I've written a web application for which the user interface is in Dutch. I use the system's date and time routines to format date strings in the application. However, the date strings that the system formats are in English but I want them in Dutch, so I need to set the system's locale. How do I do that on Debian? I tried setting LC_ALL=nl_NL
but it doesn't seem to have any effect:
$ date
Sat Aug 15 14:31:31 UTC 2009
$ LC_ALL=nl_NL date
Sat Aug 15 14:31:36 UTC 2009
I remember that setting LC_ALL on my Ubuntu desktop system works fine. Do I need to install extra packages to make this work, or am I doing it entirely wrong?
Edit
/etc/default/locale
and set the contents to:You can check which locales you currently have generated using:
You can generate more by editing
/etc/locale.gen
and uncommenting the lines for the locales that you want to enable. Then you can generate them by running the command:You can find a list of supported locales in
/usr/share/i18n/SUPPORTED
There is more information available on the Debian wiki.
You may need to install the
locales
package. This will ask you which locales to generate. If it's already installed, thendpkg-reconfigure locales
will let you generate more locales.Answers here are incomplete as with most elsewhere. After piecing together information from a few places, what worked for me was to (1) make sure the locale I wanted was available (generate it if it wasn't) then (2) set locale related environment variables to desired locale.
In my case I needed
en_US.UTF-8
programmatically (i.e. non-interactively) installed in a docker container. The ff accomplished what I need but it should work just fine in an interactive shell.On the same shell, you will need to do
source ~/.bashrc
for the env vars to take effect immediately. You can check that locale has been configured correctly by invokinglocale
.There were a lot of Q&A entries regarding this subject but only a few were actually helpful. Credit where credit is due:
None of these answers worked for me, on an LXC container installed with:
I always got the following output from
locale-gen
, i.e. not generating any locales (none listed):Running
dpkg-reconfigure locales
and selecting some locales did not update/etc/locale.gen
as I expected it to.However, when I modified that file manually and uncommented the locales that I wanted, then
locale-gen
started working properly:I was also able to generate locales manually like this:
But this was not a permanent solution: I found that running
locale-gen
without the--keep-existing
option will delete all such manually-generated locales, i.e. every locale not listed (and uncommented) in/etc/locale.gen
.For a web application, it might be better to use setlocale() inside the program, rather than requiring that the system default locale be set appropriately outside. Less loose ends that way.
For those who, like me, on Ubuntu 14.04 LTS, have, somehow, no
/etc/locale.gen
file, you can add a new locale in/var/lib/locales/supported.d/local
and then run :sudo dpkg-reconfigure locales
You can also add the french (for example) locale this way (instead of editing
/var/lib/locales/supported.d/local
) :sudo locale-gen fr_FR fr_FR.UTF-8
to add and generate the
ISO-8859-1
andUTF-8
codesets of thefr_FR
locale and finally type :sudo dpkg-reconfigure locales
to finish the job
Note: Some of the commands below require root privileges, consider the use of
sudo
.Basic info
According to
man locale-gen
, locales are set in several files.Comprehensive details on locales at the Arch Wiki.
Checking locales and the locale
To check the (already) generated locales, run any of the following commands (with minor output differences).
To check the currently used locale, run any of the following commands (with minor output differences).
Setting and generating (new) locales
Locales are typically set by uncommenting lines in
/etc/locale.gen
, after which runninglocale-gen
is required.This will generate locales files for each uncommented line in
/etc/locale.gen
(and under/var/lib/locales/supported.d/
), whether they were previously generated or not.Alternatively, the command
will uncomment the corresponding line in
locale-gen
while generating the desired locale and only this one.Removing locales
To remove locales in
/etc/locale.gen
, simply comment the desired lines and regenerate the locales usinglocale-gen
. The commandlocale-gen --purge <locale>
doesn't do what the modifier suggests.To remove locales under
/var/lib/locales/supported.d/
is trickier. Since any file/var/lib/locales/supported.d/<code>
depends on the packagelanguage-pack-<code>-base
, any change on the former will be restored when the latter is updated.Workaround. To prevent changes under
/var/lib/locales/supported.d/
, set files in it with the "immutable (i)" attribute. So instead of removing files, empty them. For instance:Setting the locale
Setting and generating locales does not set the system locale. Any of the following commands achieves this.
But first you need to have needed language pack installed. On my German based VPS there was no english language pack pre-installed. So first you check that you have it installed: