Browsed by
Tag: ubuntu

Locales in Debian and Ubuntu

Locales in Debian and Ubuntu

Locales customize your system to languages and country specific settings.
On a single user system, you set up your locale at installation time and that’s it.
But if you need to support several different languages (e.g. an international ecommerce shop) you have to tweak your setup.

Command line tools, packages and configuration files

The locale command displays information about the current locale. The man page reveals more information:

When invoked without arguments, locale displays the current locale settings for each locale category (see locale(5)), based on the settings of the environment variables that control the locale (see locale(7)).

A locale is composed of several locale categories. When a program looks up locale dependent values, it does this according to the following environment variables:

$ locale
LANG=de_DE.UTF-8
LANGUAGE=
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
LC_ALL=

You can find more information about the variables and locales in general at https://www.gnu.org/software/gettext/manual/gettext.html#Locale-Environment-Variables and https://help.ubuntu.com/community/Locale

Display a list of all available locales:

$ locale -a
C
C.UTF-8
de_DE.utf8
POSIX

Locales availabe for generation are configured in /etc/locales.gen
Just uncomment the locales you want to be available, then run the locale-gen command.

# This file lists locales that you wish to have built. You can find a list
# of valid supported locales at /usr/share/i18n/SUPPORTED, and you can add
# user defined locales to /usr/local/share/i18n/SUPPORTED. If you change
# this file, you need to rerun locale-gen.


# C.UTF-8 UTF-8
# aa_DJ ISO-8859-1
# aa_DJ.UTF-8 UTF-8
# aa_ER UTF-8

...

# de_CH.UTF-8 UTF-8
# de_DE ISO-8859-1
de_DE.UTF-8 UTF-8
# de_DE@euro ISO-8859-15
# de_IT ISO-8859-1
# de_IT.UTF-8 UTF-8
# de_LI.UTF-8 UTF-8

...

As an alternative, you could achieve the same result with:

$ sudo locale-gen fr_FR.UTF-8
Generating locales...
  fr_FR.UTF-8... done
Generation complete.

This will update the config file und generate the specified locale (fr_FR.UTF-8) in one step.

If you have a bunch of locales to generate the following shell snippet will help:

$ L="de_DE
de_DE.UTF-8
de_DE@euro
en_GB
en_GB.ISO-8859-15
en_GB.UTF-8
en_US.UTF-8
es_ES
es_ES.UTF-8
es_ES@euro
fr_FR
fr_FR.UTF-8
fr_FR@euro
it_IT
it_IT.UTF-8
it_IT@euro
nl_NL
nl_NL.UTF-8
nl_NL@euro"

$ for i in $L[*]; do
$  sudo sed -i s"/^# ${i}/${i}/g" locale.gen
$ done
 
$ sudo locale-gen
Generating locales (this might take a while)...
  de_DE.ISO-8859-1... done
  de_DE.UTF-8... done
  de_DE.ISO-8859-15@euro... done
  en_GB.ISO-8859-1... done
  en_GB.ISO-8859-15... done
  en_GB.UTF-8... done
  en_US.UTF-8... done
  es_ES.ISO-8859-1... done
  es_ES.UTF-8...^A done
  es_ES.ISO-8859-15@euro... done
  fr_FR.ISO-8859-1... done
  fr_FR.UTF-8... done
  fr_FR.ISO-8859-15@euro... done
  it_IT.ISO-8859-1... done
  it_IT.UTF-8... done
  it_IT.ISO-8859-15@euro... done
  nl_NL.ISO-8859-1... done
  nl_NL.UTF-8... done
  nl_NL.ISO-8859-15@euro... done
Generation complete.

The default locale is defined in /etc/default/locale

LANG=de_DE.UTF-8

To change the default, you can edit the file or use update-locale like so

$ sudo update-locale LANG=de_DE.UTF-8

The advantage of using update-locale ist that some basic checks are performed to ensure that requested settings are valid.

Conclusion so far: with the tools described above you can cherry pick how locales are setup.

Language packs

Important: language-packs only apply to Ubuntu and not Debian

On Ubuntu you can also install language-packs.
There are a lot of them, seperated into base and updates packages, for example:

language-pack-en: translation updates for language English
Translation data updates for all supported packages for: English
language-pack-en-base provides the bulk of translation data and is updated
only seldom. This package provides frequent translation updates.

$ sudo aptitude search "^language-pack-*"
p   language-pack-af               - translation updates for language Afrikaans
p   language-pack-af-base          - translations for language Afrikaans
p   language-pack-am               - translation updates for language Amharic
p   language-pack-am-base          - translations for language Amharic
p   language-pack-an               - translation updates for language Aragonese
p   language-pack-an-base          - translations for language Aragonese
p   language-pack-ar               - translation updates for language Arabic
p   language-pack-ar-base          - translations for language Arabic
p   language-pack-as               - translation updates for language Assamese
p   language-pack-as-base          - translations for language Assamese
p   language-pack-ast              - translation updates for language Asturian
p   language-pack-ast-base         - translations for language Asturian
p   language-pack-az               - translation updates for language Azerbaijan
p   language-pack-az-base          - translations for language Azerbaijani
p   language-pack-be               - translation updates for language Belarusian
p   language-pack-be-base          - translations for language Belarusian
p   language-pack-bg               - translation updates for language Bulgarian
p   language-pack-bg-base          - translations for language Bulgarian
p   language-pack-bn               - translation updates for language Bengali
p   language-pack-bn-base          - translations for language Bengali
p   language-pack-br               - translation updates for language Breton
p   language-pack-br-base          - translations for language Breton

...

If you install a language-pack, additional configuration is installed in /var/lib/locales/supported.d
For English this will look like this:

/var/lib/locales/supported.d/en

en_HK.UTF-8 UTF-8
en_DK.UTF-8 UTF-8
en_IN UTF-8
en_IL UTF-8
en_ZM UTF-8
en_ZW.UTF-8 UTF-8
en_NZ.UTF-8 UTF-8
en_PH.UTF-8 UTF-8
en_NG UTF-8
en_US.UTF-8 UTF-8
en_GB.UTF-8 UTF-8
en_AU.UTF-8 UTF-8
en_SG.UTF-8 UTF-8
en_BW.UTF-8 UTF-8
en_AG UTF-8
en_ZA.UTF-8 UTF-8
en_CA.UTF-8 UTF-8
en_IE.UTF-8 UTF-8

Independently from the settings in /etc/locale.gen all the locales in /var/lib/locales/supported.d/en are beeing generated.