Can anybody please help me with how to get the language(english,chinese etc) of Windows OS through win32 API(C/C++)??
Thanks, Sourabh
Can anybody please help me with how to get the language(english,chinese etc) of Windows OS through win32 API(C/C++)??
Thanks, Sourabh
You can get the default user locale (which I think is what you're asking) using GetUserDefaultLCID. This will give you an ID which can be used to determine the culture. See here for a table containing IDs and the cultures they represent.
For Vista or Windows 7, Microsoft recommend GetUserDefaultLocaleName.
If you're asking about "Which language the OS menus and dialogs are dispalyed in" (i.e. which MUI - Multilingual User Interface kit - is installed), use the following:
More info:
You can get the default user locale (which I think is what you're asking) using GetUserDefaultLCID. This will give you an ID which can be used to determine the culture. See here for a table containing IDs and the cultures they represent.
For Vista or Windows 7, Microsoft recommend GetUserDefaultLocaleName.
Since both of the answers are older and use the deprecated language ids, this is a new answer how to solve this problem nowadays:
First of all, the locale and the UI language aren't the same thing. They correlate often but they don't necessarily need to be the same. The locale is based on the geographic location and language of the user, while the UI language determines which should be used by user interfaces.
To get the UI language, you should probably use the GetUserPreferredUILanguages function. It returns either language ids or the language names, depending on the arguments. Since Microsoft deprecated the use of language ids, you should use the function directly to get the language name(s).
If you want to get other information instead of the language name, you can use GetLocaleInfoEx. The first parameter is the just obtained language name and you can select the LCTYPE
, which is the information you want to retrieve, which can be all kinds of stuff, e.g. the country, the currency, or the date format.
However, these functions are only available to Windows Vista and later. If you need to have compatibility to older systems, you need to use the (now discouraged) language ids. With GetUserDefaultUILanguage, you can get the current users UI language as a language id.
To convert that language id to the language name or other information, use GetLocaleInfoW. It works like GetLocaleInfoEx
, just that the first parameter is the language id instead of the language name.
Since the LOCALE_SNAME
LCTYPE
(which returns the language name) has only been introduced with the concept of language names in Windows Vista, you need to use the LCTYPE
s LOCALE_SISO639LANGNAME
and LOCALE_SISO3166CTRYNAME
(which returns something like en
and US
, respectively) and build your language name with those.
Getting the user locale is easier: You just need to use the GetLocaleInfoEx function. And instead of a language name as the first parameter, you can just use the constant LOCALE_NAME_USER_DEFAULT
, which leads to GetLocaleInfoEx
directly returning info about the current user locale. To get the language name, use LOCALE_SNAME
as the LCTYPE
.
As with the UI language, using the language names is only supported from Windows Vista on. If you need to have compatibility to the older systems, you can use the GetLocaleInfoW function. And instead of a language id as the first parameter, you can just use the constant LOCALE_USER_DEFAULT
which leads to GetLocaleInfoW
directly returning info about the current user locale.
Since the LOCALE_SNAME
LCTYPE
(which returns the language name) has only been introduced with the concept of language names in Windows Vista, you need to use the LCTYPE
s LOCALE_SISO639LANGNAME
and LOCALE_SISO3166CTRYNAME
(which returns something like en
and US
, respectively) and build your language name with those.
© 2022 - 2024 — McMap. All rights reserved.