LOCALE_SABBREVLANGNAME 的 GetLocaleInfo 是否已弃用?

is GetLocaleInfo with LOCALE_SABBREVLANGNAME deprecated?

当我执行 GetLocaleInfo([=11=]C51, LOCALE_SABBREVLANGNAME, Language, LOCALE_NAME_MAX_LENGTH); 时,它是 return ZZZ。 ZZZ 接缝是宗卡语(不丹)的无效代码。这是否意味着 GetLocaleInfo / LOCALE_SABBREVLANGNAME 已弃用?

首先,我可以重现这个问题。 GetLocaleInfo return 4 并且语言是 L"ZZZ".

然后,正如文档 GetLocaleInfo 所说,

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.

正如@Eryk 指出的,WinNls.h 中也提到了这一点:

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

此外,ISO 639-1 和 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"

如果你想得到一个“3个字符的ISO缩写语言名称”,示例:

#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;
}