C++ Win32 API equivalent of CultureInfo.TwoLetterISOLanguageName

雨燕双飞 提交于 2019-12-09 03:23:05

问题


The .NET framework makes it easy to get information about various locales; the Win32 C++ APIs are a bit harder to figure out.

Is there an equivalent function in Win32 to get the two-letter ISO language name given an integer locale ID?

In C# I'd do:

System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(1034);
string iso = ci.TwoLetterISOLanguageName;
// iso == "es" now.

The code needs to run on XP and newer.


回答1:


Thanks to Trevor for directing me toward this answer in an earlier reply.

Call GetLocaleInfo with the LOCALE_SISO639LANGNAME parameter.




回答2:


See the GetLocaleInfo function. There are 2 LCType values you may be interested in: LOCALE_SABBREVCTRYNAME, and LOCALE_SABBREVLANGNAME. I did a quick test on Windows 7, and both returned 3 character strings, even though ISO 3166 uses 2 characters. The LOCALE_SABBREVLANGNAME documentation states it starts out with the 2 character ISO 3166 code and adds a third character for the sublanguage.




回答3:


This is one area where Win API has evolved a lot since XP. I don't think you're going to find a function to do it that's available all the way back to XP. I believe the .NET framework stuff has its own built-in tables (at least for pre-Vista versions). GetUserDefaultLocaleName isn't even available on XP, and that doesn't do exactly what you want, and even if it did, it probably wouldn't be as complete on XP as it is on newer versions.

You might need to include your own table.



来源:https://stackoverflow.com/questions/2649676/c-win32-api-equivalent-of-cultureinfo-twoletterisolanguagename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!