Friday, October 5, 2012

Setting the Locale on Linux

A locale is a system setting that allows users to configure the operating system for their own language, date, currency, etc. on Linux. There are slightly different ways to set up locales on different Linux distributions. Here I write how I would normally set up locales on Linux.

To set the system-wide default locale, I would append the LANG= variable to the Linux kernel. The kernel will happily accept the LANG= variable and pass it to the operating system. With syslinux, I would have an entry in syslinux.cfg as follows.

LABEL debian
KERNEL vmlinuz-3.6.0
INITRD /boot/initramfs.lzma
APPEND LANG=en_US.UTF-8 TERM=vt100 root=/dev/sda9

On Debian, Ubuntu, Mint and MEPIS, the system-wide locale may be specified in /etc/environment or /etc/default/locale.

LANG=C.UTF-8

To set your own locale different from the system-wide locale, just add a line to your .bashrc or .xsession:

export LANG=zh_CN.UTF-8

Generating locale-archive Again

The number of locales available on the system may be incomplete in order to save disk space. To see which locales are available, run the following command:

locale -a

If you want to add or remove locales, edit /etc/locale.gen. The following is a sample locale.gen.

ar_SA.UTF-8 UTF-8
bn_IN UTF-8
de_DE.UTF-8 UTF-8
en_US ISO-8859-1
en_US.UTF-8 UTF-8
es_MX.UTF-8 UTF-8
fa_IR UTF-8
fr_FR.UTF-8 UTF-8
gu_IN UTF-8
hi_IN UTF-8
id_ID.UTF-8 UTF-8
it_IT.UTF-8 UTF-8
ja_JP.UTF-8 UTF-8
kn_IN UTF-8
ko_KR.UTF-8 UTF-8
ml_IN UTF-8
mr_IN UTF-8
or_IN UTF-8
pa_PK UTF-8
pt_BR.UTF-8 UTF-8
ru_RU.UTF-8 UTF-8
ta_IN UTF-8
te_IN UTF-8
th_TH.UTF-8 UTF-8
tr_TR.UTF-8 UTF-8
vi_VN UTF-8
zh_CN.UTF-8 UTF-8
zh_TW.UTF-8 UTF-8

After changing the file locale.gen, you need to run locale-gen to regenerate the file /usr/lib/locale/locale-archive.

locale-gen

Enabling All Possible Locales

If you have plenty disk space, then you can enable all locales supported by the current glibc implementation. The list of supported locales is at /usr/share/i18n/SUPPORTED. Just copy it to /etc/locale.gen and rebuild the locales. It will regenerate the file /usr/lib/locale/locale-archive to about 100MB.

cp /usr/share/i18n/SUPPORTED /etc/locale.gen
locale-gen

Running Applications In Different Locales

Use the env command to run an application in a different locale. For example, to run pidgin in Chinese on an English desktop, I would issue:

env LANG=zh_CN.UTF-8 pidgin

About This Blog

KBlog logo This blog seeks to provide useful information to people, based on the author's knowledge and experience. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Follow by Email

Total Pageviews