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

Rate this post

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.


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


Sort order.


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


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.


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


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.


Yes, and No expressions.


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

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


English Canadian.


US English.


Germany’s German.


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