Ubuntu – How to create a new system locale

locale

So I want to create a sort of international US English locale with Metric/SI measurement, A4 paper size, ISO date format, etc.

From what I understand, locales are defined in /usr/share/i18n/locales. Would I be able to put the locale in here and have it be recognized when choosing a locale? What would I name the file for this locale? Where could I find information on file format and valid values for the various settings?

Best Answer

We've got documentation on the wiki pages that describe how to add a new language to Ubuntu. In a nutshell:

  1. Choose the name of the locale. The format is language_REGION@modifier, where language is an ISO 639-2 two-letter code (or the three-letter one if the former is not available), REGION is an ISO 3166 code representing the region where this language is spoken, and modifier has no set syntax and can be used to specify advanced uses for the locale (e.g. a different script). Most locales will not need a modifier.

    • Examples: bn_ID is the locale for Bengali in India, it_CH is the locale for Italian in Switzerland.
  2. Create a file with that name. Once the name has been chosen, you'll have to create a file with that name, which will contain the definition of your locale. Note that if your language is spoken in different regions, you might have to create different files, one for each region.

    • Example: ca_AD, ca_ES, ca_FR, ca_IT are locale definitions for the Catalan language as spoken in the regions of Andorra, Spain, France and Italy.
  3. Define the locale. At this point you'll have to populate the file with the definition of your language. Locale definition files have got a specific syntax. Consult the additional resources below to learn about this syntax and how to define the new locale. Looking through the available locale files in the glibc sources can be helpful to get an idea of the format. Also remember to reuse: use the copy statement to include sections from locales with identical content.

  4. Test the locale definition. Once your locale file or files are ready, you should test them locally to ensure they are correct. The basic steps are:

    • copying the file to /usr/local/share/i18n/locales/,

    • running the following command to generate a binary file to be used by applications, and doing the actual test.

        localedef -i inputfile -c -f <charset> <locale>
      

    Example (testing the Asturian locale with the date command):

     cp ast_ES /usr/local/share/i18n/locales/ast_ES
     localedef -i ast_ES -c -f ISO-8859-15 ast_ES
     LANG=ast_ES date
    

Additional resources on creating a glibc locale:

Related Question