Software Internationalization Guide

POSIX and XPG Internationalization Model
Software Internationalization Guide526225-002
3-6
Setting the Program Environment
$date
15 marzo 1994, 09:45
$export LC_ALL=fr_FR.ISO8859-1
$date
15 mars 1994, 09h45
Setting the Program Environment
An application program can inherit the user’s current locale or take on an independent
locale, depending on the setting of setlocale(). Internationalized programs cannot
function as they were designed to function until setlocale() is successfully called,
establishing the locale.
When called in the first line of code in the main program, the setlocale() function
initializes locale categories. setlocale() uses the locale specified in the locale
parameter. If the locale parameter is the null string, setlocale() uses the
environment variables. At run time, the application program can switch to any locale
the system supports.
A truly internationalized application calls setlocale() with the null string locale (""),
allowing the software to adapt to the user’s current locale. This example of a
setlocale() call uses the null string for a locale name:
/*Program that accepts the user’s current locale setting*/
main()
{
setlocale(LC_ALL,"");
...
}
This example enables the application for the LC_ALL variable:
/*Program that is set to the French locale*/
main()
{
setlocale(LC_ALL,"fr_FR.ISO8859-1");
...
}
The C locale, also known as the POSIX locale, specifies the behavior of
American-based systems without internationalization. If setlocale() is not called,
the C/POSIX locale is used as the default.
Locale-Independent Code
Internationalized functions are POSIX/XPG-compliant, locale-sensitive calls that
access language and cultural data. Internationalized functions eliminate hard-coding
locale-sensitive data and enable software to support new locales easily.
Internationalized functions are part of the C run-time library. These functions make it
possible to change locales and produce valid results according to the locale setting.