How to create a new system 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?
We've got documentation on the wiki pages that describe how to add a new language to Ubuntu. In a nutshell:
-
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_IN is the locale for Bengali in India, it_CH is the locale for Italian in Switzerland.
-
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.
-
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. -
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:
- IBM Locale Definition document
- Available locale files in the glibc sources (click on the blob link to see the contents of the file)
- Locale Helper
- Tips on writing a glibc locale file
- Glibc Documentation on localedef
- Translate Toolkit project documentation
- Examples:
- Submission of the Pashto locale
- Submission of the Chuvash locale
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/