译:在 LCID 和 RFC 1766 语言代码之间转换

Converting between LCIDs and RFC 1766 language codes
在 LCID 和 RFC 1766 语言代码之间转换

Occasionally, I see someone ask for a function that converts between LCIDs (such as 0x0409 for English-US) and RFC 1766 language identifiers (such as “en-us”). The rule of thumb is, if it’s something a web browser would need, and it has to do with locales and languages, you should look in the MLang library. In this case, the IMultiLanguage::GetRfc1766FromLcid method does the trick.
有时,我会遇到有人在寻求可以在 LCID(例如美国英语为 0x0409)和 RFC 1766 语言标识符(例如“en-us”)之间进行转换的函数。就经验而言,如果某些东西是 Web 浏览器会用到的,而且又和地域和语言相关,那就应该去 MLang 库(http://msdn.microsoft.com/workshop/misc/mlang/mlang.asp)里去看一下。对于本例,IMultiLanguage::GetRfc1766FromLcid 方法(http://msdn.microsoft.com/workshop/misc/mlang/reference/ifaces/imultilanguage/getrfc1766fromlcid.asp)正是诀窍所在。

For illustration, here’s a program that takes US-English and converts it to RFC 1766 format. For fun, we also convert “sv-fi” (Finland-Swedish) to an LCID.
为了演示,下面的程序会把美国英语(US-English)转换为 RFC 1766 格式。为了活跃气氛,我们还把“sv-fi”(芬兰-瑞典语)转换成了对应的 LCID。

When you run this program, you should get
在你运行此程序时,你会得到如下结果:

en-us
81d

“en-us” is the RFC 1766 way of saying “US-English”, and 0x081d is MAKELCID(MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH_FINLAND), SORT_DEFAULT).
“en-us”是 RFC 1766 方式的对美国英语的称呼,而 0x081d 就是 MAKELCID(MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH_FINLAND), SORT_DEFAULT)。

If you browse around, you’ll find lots of other interesting functions in the MLang library. You may recall that earlier we saw how to use MLang to display strings without those ugly boxes.
如果你浏览相邻的内容,你还可以在 MLang 库中找到很多其他感兴趣的功能。你还可能会回忆起早些时候我们如何使用 MLang 来显示字符串而避免出现那些难看的方框。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注