Internationalization and localization tools


Windows C++ Locale Function

int GetLocaleInfo(LCID Locale, LCTYPE LCType, LPTSTR lpLCData, int cchData);

int GetLocaleInfoA(LCID Locale, LCTYPE LCType, LPSTR lpLCData, int cchData);

int GetLocaleInfoW(LCID Locale, LCTYPE LCType, LPWSTR lpLCData, int cchData);

Internationalization (I18n) Function Overview

The GetLocaleInfo function retrieves LCType information about the locale specified by the Locale argument, and stores the data in the buffer pointed to by lpLCData. If cchData is non-zero, then it specifies the size, in TCHARs, of the lpLCData buffer, and the return will be the number of TCHARs written to the buffer. If cchData is 0, then GetLocaleInfo will return the number of TCHARs required to hold the information, including the null terminator, but will not store the data.

GetLocaleInfoA is the narrow version of the function, storing a single or multibyte character string in the buffer pointed to be lpLCData, and where cchData and the return value are single-byte length values.

GetLocaleInfoW is the wide version of the function, storing a wide-character string in the buffer pointed to be lpLCData, and where cchData and the return value are wide-character (WCHAR) length values.

See the MSDN Library for details on the supported LCType options.

I18n Issues

Use the appropriate version of the function as required for internationalization support, noting the following:

Formulate the correct locale to pass into GetLocaleInfo. Although there are two predefined locale constants that may be used: LOCALE_SYSTEM_DEFAULT (the system's default locale returned by GetSystemDefaultLCID) and LOCALE_USER_DEFAULT (the current user's default locale returned by GetUserDefaultLCID), neither of these will work in an internationalized application where the locale is independent of the user's system settings.

Ensure that cchData is correct for the chosen platform; bytes for the narrow version and WCHARs for the wide version. See Locale-Sensitive Length Functions for a discussion on multibyte and wide character sizes.

Recommended Replacements*

When possible, use the Generic version of the function, rather than the narrow or wide versions, and let the Windows #define UNICODE switch determine which version of the function will be called.

*If you're already using the recommended function, see I18n Issues for other reasons why Globalyzer is detecting the function.

Windows C++ Locale Functions

 

Lingoport internationalization and localization services and software