Localization/Guide

From Gentoo Wiki
Localization(Redirected from Localization/HOWTO)
Jump to: navigation, search
This page contains changes which are not marked for translation.

Other languages:
čeština • ‎Deutsch • ‎English • ‎español • ‎français • ‎日本語 • ‎한국어

Time zone

In order to keep the system time properly according to the present location, the timezone needs to be set. Instructions how to do this for OpenRC based systems and systemd based systems can be found in the system time article.

Locale system

What are locales?

A locale is a set of information that most programs use for determining country and language specific settings. The locales and their data are part of the system library and can be found at /usr/share/i18n/locales/ on most systems. A locale name is generally named ab_CD where ab is your two (or three) letter language code (as specified in ISO-639) and CD is your two letter country code (as specified in ISO-3166). Variants are often appended to locale names, e.g. en_GB.UTF-8 or de_DE@euro. Please explore Wikipedia to read more about locales and related articles.

Environment variables for locales

The variables controlling different aspects of locale settings are given in the table below. All of them take one name of a locale in ab_CD format given above.

Variable name Explanation
LANG Defines all locale settings at once, while allowing further individual customization via the LC_* settings below.
LC_COLLATE Define alphabetical ordering of strings. This affects e.g. output of sorted directory listing.
LC_CTYPE Define the character handling properties for the system. This determines which characters are seen as part of alphabet, numeric and so on. This also determines the character set used, if applicable.
LC_MESSAGES Programs' localizations stored in /usr/share/locale/ for applications that use message based localization scheme (majority of Gnu programs, see next chapters for closer information which do, and how to get the programs, that don't, to work).
LC_MONETARY Defines currency units and formatting of currency type numeric values.
LC_NUMERIC Defines formatting of numeric values which aren't monetary. Affects things such as thousand separator and decimal separator.
LC_TIME Defines formatting of dates and times.
LC_PAPER Defines default paper size.
LC_ALL A special variable for overriding all other settings.
Note
Some programs are written in such a way that they expect traditional English ordering of the alphabet, while some locales, most notably the Estonian one, use a different ordering. Therefore it's recommended to explicitly set LC_COLLATE to C when dealing with system-wide settings.
Warning
Using LC_ALL is strongly discouraged as it automatically overrides all other LC_* variables (LANG is not affected). This means that changes made by other means will be hidden until LC_ALL is set to a null string. It is probably best not to set it in a startup file.

Most typically users only set the LANG variable on the global basis.

Generating specific locales

You will probably only use one or maybe two locales on your system. You can specify locales you will need in /etc/locale.gen.

CODE Adding locales to /etc/locale.gen
en_GB ISO-8859-1
en_GB.UTF-8 UTF-8
de_DE ISO-8859-1
de_DE@euro ISO-8859-15

The next step is to run locale-gen. It will generate all the locales specified in the /etc/locale.gen file and write them to the locale-archive (/usr/lib/locale/locale-archive).

root #locale-gen
 * Generating 4 locales (this might take a while) with 1 jobs
 *  (1/4) Generating en_GB.ISO-8859-1 ...                       [ ok ]
 *  (2/4) Generating en_GB.UTF-8 ...                            [ ok ]
 *  (3/4) Generating de_DE.ISO-8859-1 ...                       [ ok ]
 *  (4/4) Generating de_DE.ISO-8859-15@euro ...                 [ ok ]
 * Generation complete
Note
locale-gen is available in glibc-2.3.6-r4 and newer. If you have an older version of glibc, you should update it now.

You can verify that your selected locales are available by running locale -a.

user $locale -a
C
POSIX
de_DE
de_DE.iso88591
de_DE.iso885915@euro
de_DE@euro
deutsch
en_GB
en_GB.iso88591
en_GB.utf8
german

The /usr/lib/locale/locale-archive file can be displayed using the strings command.

user $strings /usr/lib/locale/locale-archive | less

Setting a locale

OpenRC

When using OpenRC locale settings are stored in environment variables. These are typically set in the /etc/env.d/02locale (for system-wide settings) and ~/.bashrc (for user-specific settings) file. More details can be found in the UTF-8 article. The system wide settings (/etc/env.d/02locale) can be managed through eselect locale. For instance, to set the LANG variable to the C value:

root #eselect locale list
Available targets for the LANG variable:
  [1]   C 
  [2]   POSIX
  [3]   en_US
  [4]   en_US.iso885915
  [5]   en_US.utf8
  [ ]   (free form)
root #eselect locale set 1

Of course, you can edit the file manually as well and diversify the locale variables.

FILE /etc/env.d/02localeSetting the default system locale in /etc/env.d/02locale
LANG="de_DE.UTF-8"
LC_COLLATE="C"
Note
Use de_DE@euro as your LANG if you want to use the Euro currency symbol (€) on non UTF-8 based locales.

It's also possible, and pretty common especially in a more traditional UNIX environment, to leave the global settings unchanged, i.e. in the "C" locale. Users can still specify their preferred locale in their own shell RC file:

FILE ~/.bashrcSetting the user locale
export LANG="de_DE.UTF-8"
export LC_COLLATE="C"

Another way of configuring system is to leave it in the default C locale, but enable UTF-8 character representation at the same time. This option is achieved using the following settings in /etc/env.d/02locale:

CODE Using traditional C locale while specifying UTF-8
LC_CTYPE=de_DE.UTF-8

Using the above snippet, users will be able to see localized file names properly, while not being forced to your preferred language.

Once you have set the right locale, be sure to update your environment variables to make your system aware of the change.

For a system-wide default locale:

root #env-update && source /etc/profile

For a user-specific locale:

user $source ~/.bashrc

After this, kill the X server by pressing Ctrl+Alt+Backspace, log out, then log in as a user.

Now, verify that the changes have taken effect:

user $locale

systemd

If you use systemd set locale with the localectl command. Check the list of available locales with:

root #localectl list-locales

Then set the desired locale:

root #localectl set-locale LANG=de_DE.utf8

Finally check if the result is good:

root #localectl | grep "System Locale"
   System Locale: LANG=de_DE.utf8

Keyboard layout for the console

OpenRC

The keyboard layout used by the console is set in /etc/conf.d/keymaps by the keymap variable. Valid values can be found in /usr/share/keymaps/YOUR_ARCH/. i386 has further subdivisions into layout (qwerty/, azerty/, etc.). Some languages have multiple options, so you may wish to experiment to decide which one fits your needs best.

FILE /etc/conf.d/keymapsSetting the console keymap
keymap="de"
#keymap="de-latin1"
#keymap="de-latin1-nodeadkeys"

systemd

With systemd the keymap layout used for your console can be set using the localectl command. First check the available keymap layouts:

root #localectl list-keymaps

Then set the console keymap layout you want:

root #localectl set-keymap it

Finally check if the console keymap layout was set correctly:

root #localectl | grep "VC Keymap"
       VC Keymap: it

Keyboard layout for the X server

OpenRC

The keyboard layout to be used by the X server is specified in /etc/X11/xorg.conf.d/30-keyboard.conf by the XkbLayout option. For details visit the Xorg guide.

systemd

With systemd the keymap layout for the X11 server can be set using the localectl command. First check the available X11 keymap layouts:

root #localectl list-x11-keymap-layouts

Then set the X11 keymap layout you want:

root #localectl set-x11-keymap it

Finally check if the X11 keymap layout was set correctly:

root #localectl | grep "X11 Layout"
      X11 Layout: it

The Euro symbol for the console

OpenRC

In order to get your console to display the Euro symbol, you will need to set the consolefont variable in /etc/conf.d/consolefont to a file found in /usr/share/consolefonts/ (without the .psfu.gz). lat9w-16 has the Euro symbol.

FILE /etc/conf.d/consolefontSetting the console font
consolefont="lat9w-16"

You should verify that the consolefont service is in the boot runlevel:

root #rc-update -v show | grep consolefont

If no runlevel is displayed for consolefont, then add it to the proper level:

root #rc-update add consolefont boot

The Euro symbol in X

Most applications

Getting the Euro symbol to work properly in X is a little bit tougher. The first thing you should do is change the fixed and variable definitions in /usr/share/fonts/misc/fonts.alias to end in iso8859-15 instead of iso8859-1.

CODE Setting default X fonts
fixed        -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-15
variable     -*-helvetica-bold-r-normal-*-*-120-*-*-*-*-iso8859-15

Some applications use their own font, and you will have to tell them separately to use a font with the Euro symbol. You can do this at a user-specific level in .Xdefaults (you can copy this file to /etc/skel/ for use by new users), or at a global level for any application with a resource file in /usr/share/X11/app-defaults/ (like xterm). In these files you generally have to change an existing line, rather than adding a new one. To change our xterm font, for instance:

user $echo 'XTerm*font: fixed' >> ~/.Xresources
user $xrdb -merge ~/.Xresources

The Euro symbol in (X)Emacs

To use the Euro symbol in (X)Emacs, add the following to .Xdefaults :

FILE ~/.XdefaultsSetting the font for emacs
Emacs.default.attributeFont: -*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-15

For XEmacs (not plain Emacs), you have to do a little more. In /home/user/.xemacs/init.el , add:

FILE ~/.xemacs/init.elSetting the font for xemacs
(define-key global-map '(EuroSign) '[€])

NLS

For message based localization to work in programs that support it and have the nls (Native language support) USE flag, you will probably need to have the programs compiled with this flag set. Message strings are installed in /usr/share/locale/<locale>/LC_MESSAGES/<package>.mo files. Most of the programs using nls also need the gettext library to extract and use localized messages. Of course, Portage will automatically install it when needed.

After enabling the nls USE flag you may need to re-emerge some packages:

root #emerge --ask --newuse --deep --with-bdeps=y @world

LINGUAS

There is also an additional localization variable called LINGUAS, which affects the localization files that get installed in gettext-based programs, and decides which GUI language packs should be downloaded and installed for some specific software packages, such as Firefox, Thunderbird, kde-base/kde-l10n or app-office/libreoffice-l10n. The variable takes in space-separated list of language codes, and a suggested place to set it is /etc/portage/make.conf:

root #nano -w /etc/portage/make.conf
## (Add in the LINGUAS variable. For instance, for German, Finnish and English:)
LINGUAS="de fi en"

With LINGUAS="", most ebuilds would install only the packages' default language but none of the LC_MESSAGES files. They would also not download and install any of the further language packs. For instance, the currently stable app-office/libreoffice receives further language support through app-office/libreoffice-l10n which supports download and installation of the language packs defined in LINGUAS. Since the origin language of libreoffice is en_US, it does not have en_US flag in app-office/libreoffice-l10n. So with LINGUAS="", libreoffice still supports en_US.

To see the status of GUI translation, hyphenation, spell checking and other localisations on your language, please refer to the LibreOffice translation web site.

For finer grained control it can be set per package in /etc/portage/package.use:

FILE /etc/portage/package.use
www-client/firefox linguas_de linguas_pt_BR linguas_en_GB

A list of installed programs making use of the LINGUAS variable and their supported languages can be shown as follows:

user $eix -I -U linguas

A list of LINGUAS values that can be used is provided as /usr/portage/profiles/desc/linguas.desc:

user $grep -i french /usr/portage/profiles/desc/linguas.desc
fr - French locale
fr_CA - French locale for Canada
fr_FR - French locale for France

After setting the linguas USE flag it may be necessary to re-emerge some packages:

root #emerge --ask --newuse --deep --with-bdeps=y @world

See also

External resources

  • Locales and Internationalization (gnu.org)
    This article is based on a document formerly found on our main website gentoo.org.
    The following people have contributed to the original document: Alexander Holler, Steven Lucy, Benny Chuang, Lars Weiler, Tobias Scherbaum, Flammie Pirinen, nightmorph, klondike
    They are listed here as the Wiki history does not provide for any attribution. If you edit the Wiki article, please do not add yourself here, your contributions are recorded on the history page.