Before XPG4, an application used several system APIs such as DosQueryCp() and DosQueryCtryInfo() to retrieve NLS-related information. This chapter introduces XPG4 functions to obtain the environment information.
┌──────────────────────────────────────────────────────────────────────┐ │Use the setlocale() function to query the current locale. Use the │ │nl_langinfo() function to retrieve the further information of the │ │current locale such as the code set. │ └──────────────────────────────────────────────────────────────────────┘
To find out the locale name at runtime, use the setlocale function as follows:
char* cl; cl = setlocale( category, NULL );The function returns a pointer to a string that specifies the locale for the category.
The application can determine at least the language and territory (e.g. country) from the returned string (refer to the DBCS countries locales for the locale naming convention). Since the codeset name is optional, it may not be contained in the string. In such cases, the nl_langinfo() function is used:
#include <nl_types.h> #include <langinfo.h> char *nl_langinfo(nl_item item );
The function returns a pointer to a string that contains information about the active language or territory. The active language or territory is determined by the most recent setlocale call. The constant macros used to identify queried information are defined in the langinfo.h header. To query the current code set, specify CODESET to the item.