简体   繁体   English

C ++ Win32 API等效于CultureInfo.TwoLetterISOLanguageName

[英]C++ Win32 API equivalent of CultureInfo.TwoLetterISOLanguageName

The .NET framework makes it easy to get information about various locales; .NET框架可以轻松获取有关各种语言环境的信息; the Win32 C++ APIs are a bit harder to figure out. Win32 C ++ API有点难以弄清楚。

Is there an equivalent function in Win32 to get the two-letter ISO language name given an integer locale ID? 在Win32中是否有等效函数来获取给定整数区域设置ID的双字母ISO语言名称?

In C# I'd do: 在C#我会这样做:

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. 代码需要在XP和更新版本上运行。

Thanks to Trevor for directing me toward this answer in an earlier reply. 感谢Trevor在早些时候的回复中指导我做出这个回答。

Call GetLocaleInfo with the LOCALE_SISO639LANGNAME parameter. 使用LOCALE_SISO639LANGNAME参数调用GetLocaleInfo

See the GetLocaleInfo function. 请参阅GetLocaleInfo函数。 There are 2 LCType values you may be interested in: LOCALE_SABBREVCTRYNAME, and LOCALE_SABBREVLANGNAME. 您可能感兴趣的有2个LCType值:LOCALE_SABBREVCTRYNAME和LOCALE_SABBREVLANGNAME。 I did a quick test on Windows 7, and both returned 3 character strings, even though ISO 3166 uses 2 characters. 我在Windows 7上进行了快速测试,两者都返回了3个字符串,即使ISO 3166使用2个字符。 The LOCALE_SABBREVLANGNAME documentation states it starts out with the 2 character ISO 3166 code and adds a third character for the sublanguage. LOCALE_SABBREVLANGNAME文档声明它以2个字符的ISO 3166代码开始,并为子语言添加第三个字符。

This is one area where Win API has evolved a lot since XP. 这是Win API自XP以来发展很多的一个领域。 I don't think you're going to find a function to do it that's available all the way back to XP. 我不认为你会找到一个功能,可以一直回到XP。 I believe the .NET framework stuff has its own built-in tables (at least for pre-Vista versions). 我相信.NET框架有自己的内置表(至少对于Vista之前的版本)。 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. GetUserDefaultLocaleName甚至在XP上都不可用,并且这并不能完全满足您的需求,即使它确实如此,它在XP上可能不会像在新版本上那样完整。

You might need to include your own table. 您可能需要包含自己的表格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM