Difference between revisions of "Locale"
|Line 90:||Line 90:|
[http://gentoo-wiki.com/HOWTO_localedef GentooWiki: ]
Revision as of 15:15, 18 September 2008
- 1 Introduction
- 2 Enabling necessary locales
- 3 Setting system wide locale
- 4 Setting per user locale
- 5 Setting language
- 6 Setting starting weekday
- 7 Troubleshooting
- 8 Links
Locales are used in Linux to define which language the user uses. As the locales define the charset which the user uses as well, setting up the correct locale is especially important if the language contains non-ASCII characters.
Locale Naming ist defined as following:
In this howto we're setting up a system that uses the en_US.UTF-8 locale, but you can follow this article easily if you want to setup another locale.
Enabling necessary locales
First you have to enable the locales you want being supported by your system. To enable or disable them, the file /etc/locale.gen is used. It contains every locale you can enable, and you have just to uncomment lines you want to do so.
As we want to setup an english UTF-8 conform system, we want to enable en_US.UTF-8. But for compatibility to programs that don't support UTF-8 yet, it's recommended to support any other locale, prefixed with en_US as well. Having this in mind, we enable this set of locales:
en_US.UTF8 UTF-8 en_US ISO-8859-1
After you've enabled the necessary locales, you have to run locale-gen as root to update them:
# locale-gen Generating locales... en_US.UTF-8... done en_US.ISO-8859-1... done Generation complete.
Note: Though it's most likely just one language you use on your computer it can be helpful or even necessary to enable other locales as well. For example if you're running a multi-user system with users that don't speak en_US, they won't be happy until their individual locale is at least supported by your system.
Setting system wide locale
To define which locale should be used by the system, you can easily add your locale to your /etc/rc.conf file. As we've just added ISO-8859 support just for (backward-)compability, we add en_US.utf-8 here:
The system wide locale will be updated after rebooting your computer.
Important: You need to type the name of the locale exactly as shown in the output of `locale -a`. E.g. LOCALE="en_US.utf8" is valid, while LOCALE="en_US.UTF-8" is not.
Setting per user locale
As we discussed earlier, some users might want to define a different locale than the system-wide locale. In this case, you can export LC_ALL in your ~/.bashrc. For example you can use the en_US.iso8859 locale, though there is no advantage of using it.
Your locales will be updated as soon as you re-source your ~/.bashrc. This happens on login or alternatively you can type:
$ source ~/.bashrc
The language in which the system interacts with the user is also determined by the locales, namely the locale LC_LANG. To set the preferred language, you have to export the LANG variable in your ~/.bashrc. Or you can put it in rc.local for system wide
After sourcing your ~/.bashrc, programs ought to use the defined language, at least they do if they're using proper internationalization.
Setting starting weekday
In a lot of countries the first day of the week is Monday. To do change or add the following lines under the LC_TIME section in /usr/share/i18n/locales/<your_locale>
week 7;19971130;5 first_weekday 2 first_workday 2
And then run
and restart X.
How can I obtain the available locale names?
You can get the correct names of all available locales with this command:
$ locale -a
How can I see which locale I am using?
Which locale is currently in use is viewable simply by typing:
My terminal doesn't support UTF-8 characters
Unfortunately some terminals don't support UTF-8. In this case, you have to use a different terminal.
List of terminals that support UTF-8:
- urxvt (rxvt-unicode)
Note: This list may be incomplete.
xterm doesn't support UTF-8 characters for me
xterm only supports UTF-8 if you run it as uxterm or xterm -u8.