
The following demonstration shows how the program (stored in print.c) is compiled
with the gcc compiler and executed, then executed again after setting the locale (to
French). Recompilation is not needed, since the locale selection takes place at runtime:
% gcc print.c
% ./a.out
42.01
% setenv LC_ALL fr
% ./a.out
42,01
%
Although this may look nice, localization has been rather problematic. The repertoire
of available locales is usually rather limited, there can be errors in their values, and
locale settings via environment variables might be used when they shouldn’t. In testing
the simple program, I made the mistake of having LC_ALL set to the value en (English)
when trying to compile the program, and I got the error message “couldn’t set locale
correctly” from the compiler. Apparently, the compiler checked the locale settings,
theoretically to adapt its own behavior to them, but did not recognize the locale name.
You can view the list of available locales with the locale -a command. The list may
contain a mixture of primary language codes like “fr,” language codes with country
specifier like “fr_FR,” and locale names that additionally contain the name of an en-
coding, such as “fr_FR.ISO8859-1.” For some languages, there might be no simple,
general locale like “fr” or “en.”
The repertoire of available locales in a system varies greatly. It may cause
surprises. Even “en” for English might be missing. ...