What Does an Application Have to Do?

┌──────────────────────────────────────────────────────────────────────┐
│Call the setlocale() function in the beginning of your program.       │
└──────────────────────────────────────────────────────────────────────┘

So, what do we have to do to get locale working? It's quite simple - call the setlocale() function at the beginning of the program.
Setting the program locale (XPRMMAIN.C)

 ...
#include <locale.h>              /* header file to use setlocale() */

void main()
{
   if( setlocale( LC_ALL,"" ) == NULL )
   {
       /* show warning message saying the locale is not valid */
       setlocale( LC_ALL, "C" );              /* use C locale */
   }
    ...
}

setlocale() sets a category specified by the first argument to the locale specified by the second argument. It returns a string that specifies the locale for the category. Specifying a null string ("") for locale makes the call to set the category to the default user locale which is specified by the environment variable.

If no user locale is set, the function uses "C", which is the default locale for a C compiler. If the category is not valid, or specified locale is not valid (i.e. the corresponding locale database is not found), the function returns NULL and does not alter the process locale (it means "C" locale is applied).

To hard-code any locale name in the argument means to force a specific locale to end users. Such a rigid programming should be avoided unless the application has a specific language or cultural dependency.


[Back: Locale Implementation of IBM Visual Age C++ for OS/2]
[Next: The Exception - LC_MONETARY]