Difference between revisions of "Locale"
(→Setting system wide locale) |
(→Enabling necessary locales) |
||
Line 21: | Line 21: | ||
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: | 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. | + | en_US.UTF-8 UTF-8 |
en_US ISO-8859-1 | en_US ISO-8859-1 | ||
Revision as of 06:56, 15 October 2009
Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end
Contents
Introduction
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:
<lang>_<territory>.<codeset>[@<modifiers>]
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.UTF-8 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:
# sudo 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:
LOCALE="en_US.UTF-8"
The system wide locale will be updated after rebooting your computer.
Collation
Collation, or sorting, is a little different. Sorting is a goofy beast and different locales do things differently. To get around potential issues, we have set LC_COLLATE="C" in /etc/profile. This forces collation to "C mode". This is usually a good idea for most users. If you want to overwrite this with sorting rules from your locale, it is best to do one of the following:
- Modify the line in /etc/profile directly
- Comment out the LC_COLLATE line in /etc/profile (allowing locale aware apps to use LC_ALL or LOCALE)
- Manually set LC_COLLATE in addition to LC_ALL or LOCALE in your user profile
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.
export LC_ALL=en_US.iso8859
Your locales will be updated as soon as you re-source your ~/.bashrc. This happens on login or alternatively you can type:
$ source ~/.bashrc
Setting language
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
export LANG=en_EN.utf8
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
# locale-gen
and restart X.
export LC_MESSAGES=C
before posting. It will set the output messages (errors, warnings) to English thus enabling more people to understand what the problem might be, resulting in a more throughout response. This is of course not the point if you are posting to a non-English forum.Troubleshooting
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:
$ locale
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:
- gnome-terminal
- gnustep-terminal
- konsole
- mlterm
- urxvt (rxvt-unicode)
- xfce-terminal
- xterm
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.
Links
- GentooWiki: Localedef (404-ish as of 2009-05-24)
- ICU's interactive collation testing