{"id":32753,"date":"2006-01-05T10:00:00","date_gmt":"2006-01-05T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2006\/01\/05\/converting-between-lcids-and-rfc-1766-language-codes\/"},"modified":"2006-01-05T10:00:00","modified_gmt":"2006-01-05T10:00:00","slug":"converting-between-lcids-and-rfc-1766-language-codes","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20060105-00\/?p=32753","title":{"rendered":"Converting between LCIDs and RFC 1766 language codes"},"content":{"rendered":"<p>\nOccasionally, I see someone ask for a function that\nconverts between LCIDs (such as 0x0409 for English-US)\nand RFC&nbsp;1766 language identifiers (such as &#8220;en-us&#8221;).\nThe rule of thumb is, if it&#8217;s something a web browser would need,\nand it has to do with locales and languages,\nyou should look in\n<a HREF=\"http:\/\/msdn.microsoft.com\/workshop\/misc\/mlang\/mlang.asp\">\nthe MLang library<\/a>.\nIn this case, the\n<a HREF=\"http:\/\/msdn.microsoft.com\/workshop\/misc\/mlang\/reference\/ifaces\/imultilanguage\/getrfc1766fromlcid.asp\">\nIMultiLanguage::GetRfc1766FromLcid<\/a> method does the trick.\n<\/p>\n<p>\nFor illustration, here&#8217;s a program that takes US-English\nand converts it to RFC&nbsp;1766 format.\nFor fun, we also convert &#8220;sv-fi&#8221; (Finland-Swedish) to an LCID.\n<\/p>\n<pre>\n#include &lt;stdio.h&gt;\n#include &lt;ole2.h&gt;\n#include &lt;oleauto.h&gt;\n#include &lt;mlang.h&gt;\nint __cdecl main(int argc, char **argv)\n{\n HRESULT hr = CoInitialize(NULL);\n if (SUCCEEDED(hr)) {\n  IMultiLanguage * pml;\n  hr = CoCreateInstance(CLSID_CMultiLanguage, NULL,\n                        CLSCTX_ALL,\n                        IID_IMultiLanguage, (void**)&amp;pml);\n  if (SUCCEEDED(hr)) {\n   \/\/ Let's convert US-English to an RFC 1766 string\n   BSTR bs;\n   LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,\n                        SUBLANG_ENGLISH_US), SORT_DEFAULT);\n   hr = pml-&gt;GetRfc1766FromLcid(lcid, &amp;bs);\n   if (SUCCEEDED(hr)) {\n    printf(\"%ws\\n\", bs);\n    SysFreeString(bs);\n   }\n   \/\/ And a sample reverse conversion just for good measure\n   bs = SysAllocString(L\"sv-fi\");\n   if (bs &amp;&amp; SUCCEEDED(pml-&gt;GetLcidFromRfc1766(&amp;lcid, bs))) {\n    printf(\"%x\\n\", lcid);\n   }\n   SysFreeString(bs);\n   pml-&gt;Release();\n  }\n  CoUninitialize();\n }\n return 0;\n}\n<\/pre>\n<p>\nWhen you run this program, you should get\n<\/p>\n<pre>\nen-us\n81d\n<\/pre>\n<p>\n&#8220;en-us&#8221; is the RFC 1766 way of saying &#8220;US-English&#8221;,\nand 0x081d is <code>MAKELCID(MAKELANGID(LANG_SWEDISH,\nSUBLANG_SWEDISH_FINLAND), SORT_DEFAULT)<\/code>.\n<\/p>\n<p>\nIf you browse around, you&#8217;ll find lots of other interesting\nfunctions in the MLang library.\nYou may recall that earlier\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2004\/07\/16\/185261.aspx\">\nwe saw how to use MLang to display strings without those ugly boxes<\/a>.\n<\/p>\n<p>\n<b>Update<\/b> (January 2008):\nThe globalization folks have told me that they&#8217;d prefer that\npeople didn&#8217;t use MLang.\nThey recommend instead the functions\n<a HREF=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms776386.aspx\">\n<code>LCIDToLocaleName<\/code><\/a>\nand\n<a HREF=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms776388.aspx\">\n<code>LocaleNameToLCID<\/code><\/a>.\nThe functions are built into Windows Vista\nand are also\n<a HREF=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms776343.aspx\">\navailable downlevel via a redistributable<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Occasionally, I see someone ask for a function that converts between LCIDs (such as 0x0409 for English-US) and RFC&nbsp;1766 language identifiers (such as &#8220;en-us&#8221;). The rule of thumb is, if it&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-32753","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Occasionally, I see someone ask for a function that converts between LCIDs (such as 0x0409 for English-US) and RFC&nbsp;1766 language identifiers (such as &#8220;en-us&#8221;). The rule of thumb is, if it&#8217;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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/32753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=32753"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/32753\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=32753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=32753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=32753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}