Fine Tuning Locale in Ubuntu GNU/Linux

Update (Feb 2, 2010): A Belorussian translation is kindly provided by Paul Bukhovko.
Version 0.1. November 18, 2008

Copyright (c) 2008 Qiming LI (Qiming.Li AT IEEE dot ORG).

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

0. Background

A few years ago, I was quite frustrated in configuring locale settings in Debian when I switched from RedHat (not that it was any easier for RedHat), so much so that I ended up writing my own mini howto on it, hoping it would be useful to folks like me.

I also tried Gentoo for a couple of years, but gave up the idea of compiling everything from the source and the long process of installation (I could have used the binary packages but that would sort of defeat the purpose, wouldn't it?). Configuring locale in Gentoo was quite straight forward, though.

Recently I lean more on Ubuntu, mainly for its effortless installation and configuration processes. Although I lost a little of control as what should and should not be installed on my system, but with cheap hard drives and CPUs today, that seemed to be a reasonable trade-off.

1. Locale configuration problems in Ubuntu

Locale configuration in Ubuntu was, as in Gentoo, quite straight forward, provided that you use the default gdm, since it allows you to specify a locale at the login window, and Gnome handles locales pretty nicely. For example, scim would be run (and working nicely) when I chose "zh_CN.UTF-8" as my locale. It should be pretty much the same for kdm and KDE but I didn't try.

However, a couple of little tricks I used to play with Debian wouldn't work in Ubuntu. For example, in Debian I could have set the locale to "C" and still have scim working on my browser and gnome-terminal, whereas in Ubuntu scim simply wouldn't work that way.

Also, when I set the locale to zh_CN, I lost control of menu displays and error messages. Although it wouldn't hurt to read error messages in Chinese, it sometimes requires a bit of guess work to decipher what they really mean, especially those errors and warnings emitted from gcc.

Ocasionally you would need to copy/paste the messages to your browser to google about a solution to your problem, and error messages in Chinese (which are not standardized in anyway) just wouldn't help.

Most importantly, when you want to view man pages, having a locale other than "C" could make it complain and refuse to work. Same goes for programs like aspell.

In Debian I could put something in /etc/X11/Xsession.d/ to fine tune the locale settings (as I explained in the mini howto) But it didn't seem to work in Ubuntu (at last for for some release versions that I tried). In some cases I could work it around using the script as in the mini howto, but it's troublesome.

2. Fine Tuning

In the end, I figured out that /etc/environment is the right place to place the locale settings. Basically I inserted the following lines into the file but leave "LANG" and "LANGUAGE" unchanged:

After that, log out of Gnome (which seems to have the side effect of restarting gdm, otherwise I may have to restart it manually), and log in back again, and menu items, error messages, man pages, etc., would be displayed in English, without affecting scim.

A minor (but surprising!) problem is that the /etc/environment file does not support usual variable substitution as in a shell script. So I cannot put something like

as I did in the mini howto. What happens to the Least Surprise priciple, I wonder.