7

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?

  • I think it's possible to do what you want. But before you put a lot of effort in it, have you studied the en_DK.UTF-8 locale, which is shipped by default on every Ubuntu installation? – Gunnar Hjalmarsson Jul 26 '15 at 18:55
  • @GunnarHjalmarsson Yeah I know I could use a predefined locale which would have pretty much the same the same effect as what I want to achieve, but I would like to know how to create a locale regardless. – TriforceOfKirby Jul 26 '15 at 23:53
7

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/share/i18n/locales/,
    • running the folowing 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/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:

  • 1
    I used this to create an en_SE locale in order to have the same values for KDE5 and the rest of the system. Newer KDEs don't do en_DK. – kaleissin Nov 30 '18 at 18:08
1

compile your locale using :

sudo localedef -i custom -f UTF-8 custom.UTF-8 -c -v 

where custom is name of your locale file and copy locale file under /usr/share/i18n/locales/ than sudo locale-gen and modify /etc/environment or ~/.profile . done !!!

What would I name the file for this locale? 

you can give any name of your local

Would I be able to put the locale in here and have it be recognized when choosing a locale?

you need to mention custom locale in /etc/environment or ~/.profile

Where could I find information on file format and valid values for the various settings?

you can refer this link for more info :How can I customize a system locale? and http://lh.2xlibre.net/locales/

  • Thanks! So for the file name, I found this page on Wikipedia for country codes. It seems the XA-XZ codes are for user use; so for example would using en_XZ be safe to use? Assuming Ubuntu won't use these codes in the future and potentially overwrite my file? – TriforceOfKirby Jul 27 '15 at 0:02
  • yes , country codes AA, QM-QZ, XA-XZ and ZZ are for users to use . you can use it . ubuntu will never overwrite . – pl_rock Jul 27 '15 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.