zeus
zeus

Reputation: 12955

is GetLocaleInfo with LOCALE_SABBREVLANGNAME deprecated?

When I do GetLocaleInfo($0C51, LOCALE_SABBREVLANGNAME, Language, LOCALE_NAME_MAX_LENGTH); it's return ZZZ. ZZZ seam to be an invalid code for Dzonghka language (bhutan). Does it's mean that GetLocaleInfo / LOCALE_SABBREVLANGNAME is deprecated ?

Upvotes: 1

Views: 877

Answers (1)

Drake Wu
Drake Wu

Reputation: 7190

First, I can reproduce this issue. GetLocaleInfo return 4 and Language is L"ZZZ".

Then, As Document GetLocaleInfo said,

For interoperability reasons, the application should prefer the GetLocaleInfoEx function to GetLocaleInfo because Microsoft is migrating toward the use of locale names instead of locale identifiers for new locales. Any application that runs only on Windows Vista and later should use GetLocaleInfoEx.

As @Eryk pointed out, and which is also metioned in the WinNls.h:

#define LOCALE_SABBREVLANGNAME        0x00000003   // DEPRECATED arbitrary abbreviated language name, LOCALE_SISO639LANGNAME instead.

In addition, ISO 639-1 and ISO 639-2:

#define LOCALE_SISO639LANGNAME        0x00000059   // ISO abbreviated language name, eg "en"
...
#define LOCALE_SISO639LANGNAME2       0x00000067   // 3 character ISO abbreviated language name, eg "eng"

If you want to get a "3 character ISO abbreviated language name", sample:

#include <windows.h>
#include <iostream>
using namespace std;
int main() {
    int ret = 0;
    //wchar_t name[LOCALE_NAME_MAX_LENGTH] = { 0 };
    //LCID LocaleID = 0x0c51;
    //ret = LCIDToLocaleName(LocaleID, name, LOCALE_NAME_MAX_LENGTH, LOCALE_ALLOW_NEUTRAL_NAMES);
    //wprintf(L"%s\n", name);//dz-BT

    wchar_t name[] = L"dz-BT";
    wchar_t Language[LOCALE_NAME_MAX_LENGTH] = { 0 };

    ret = GetLocaleInfoEx(name, LOCALE_SISO639LANGNAME2, Language, LOCALE_NAME_MAX_LENGTH);
    wprintf(L"%s\n", Language);//dzo
    return 0;
}

Upvotes: 1

Related Questions