Internationalizing and Localizing Applications in Oracle Solaris

Exit Print View

Updated: July 2014
 
 

Locale Functions

The functions related to system locales are as follows:

setlocale()

Set the program locale

localelist()

Query installed locales

localelistfree()

Free memory associated with a localelist() call

The localelist() function is used to query the locales which are installed on a system. For information about how to install additional locales on an Oracle Solaris system, see International Language Environments Guide for Oracle Solaris 11.2 .

For more information, see the setlocale(3C), localelist(3C), localelistfree(3C), locale_alias(5), langinfo.h(3HEAD), nl_types.h(3HEAD), and environ(5) man pages.

Example 2-1  Setting the Locale of a Program

The following code fragment shows how to set the locale to en_US.UTF-8.

#include <locale.h>
      :
(void) setlocale(LC_ALL, "en_US.UTF-8");

Note -  If you want to use the locale information from the user environment, pass an empty string ("") as an argument to the setlocale() function. For information, see the setlocale(3C) and environ(5) man pages.
Example 2-2  Querying the Locale of a Program

The following code fragment shows how to query the current locale.

   
#include <locale.h>
      :
char *locale;
      :
locale = setlocale(LC_ALL, NULL);

In this example, the locale variable is set to the current locale of the program.

Example 2-3  Using the Locale Settings From the User Environment

The following code fragment shows how to set the env_locale variable to use the locale settings from the user environment.

   
#include <locale.h>
      :
char *env_locale;
env_locale = setlocale(LC_ALL, "");

For example, if the locale in the user environment is es_ES.UTF-8, the env_locale variable is set to es_ES.UTF-8.


Note -  When the environment has different values set for different locale categories (also called the composite locale setting), the call to the setlocale function with the LC_ALL category, returns a string that contains values for all the categories separated by the slash character "/". For example:
"/es_ES.UTF-8/es_ES.UTF-8/es_ES.UTF-8/es_ES.UTF-8/es_ES.UTF-8/de_DE.UTF-8"

This string includes the categories LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, and LC_MESSAGES, where LC_MESSAGES was set in the environment to de_DE.UTF-8.