Locales mini-HOWTO: What is a « locale » anyhow?

prev-9162209 next-8102003 toc-5471344

Locales encapsulate some of the language/culture specific things that you shouldn’t hard code in your programs.

If you have various locales installed on your computer then you can select via the following list of environment variables how a locale sensitive program will behave. The default locale is the C, or POSIX locale which is hard coded in libc.

LANG

This sets the locale, but can be overridden with any other LC_xxxx environment variables

LC_COLLATE

Sort order.

LC_CTYPE

Character definitions, uppercase, lowercase, … These are used by the functions like toupper, tolower, islower, isdigit, …

LC_MONETARY

Contains the information necessary to format money in the fashion expected. It has the definitions of things like the thousands separator, decimal separator, and what the monetary symbol is and how to position it.

LC_NUMERIC

Thousands, and decimal separators, and the numeric grouping expected.

LC_TIME

How to specify the time, and date. This has the things like the days of the week, and months of the year in abbreviated, and non abbreviated form.

LC_MESSAGES

Yes, and No expressions.

LC_ALL

This sets the locale, and overrides any other LC_xxxx environment variables.

Here are some other locales, and there are lots more.

en_CA

English Canadian.

en_US

US English.

de_DE

Germany’s German.

fr_FR

France’s French.

If you are writing a program, and want to to be usable internationally you should utilize locales. The most glaring reason for this is that not everybody is going to use the same character set/code page as you.

Make sure in your programs that you don’t do things like:


/* check for alphabetic characters */
if ( (( c >= 'a') && ( c = 'A') && ( c