I have string data representing locales, like "fr" or "en". I need to convert it to the appropriate LCID values, like 0x80c
or 0x409
. Is there a function or macro to do so?
I'm using C++ on Windows 7.
I have string data representing locales, like "fr" or "en". I need to convert it to the appropriate LCID values, like 0x80c
or 0x409
. Is there a function or macro to do so?
I'm using C++ on Windows 7.
Apparently not in the Windows API. Indeed, I cannot find any suitable function here nor here.
I guess the best thing to do is to add a resource text file with all abbreviations and their LCIDs, and then write a LocaleStringToLCID function yourself. But I wonder where you would find the two-letter abbreviations. The MSDN page http://msdn.microsoft.com/en-us/library/aa912040.aspx only employs full-length and TLA locale strings. Maybe here: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
I now see that the link that the OP posted, http://msdn.microsoft.com/en-us/library/aa912040.aspx, applies to Windows Mobile, not the desktop OS! Hence I also looked at the wrong documentation!
Those are LCID values, not sure what LID means. You can get them out of GetLocaleInfoEx(), available in Vista and up. You need to pass a locale name like "en-US", necessary to nail down the language locale. For example:
#include "stdafx.h"
#include <windows.h>
#include <assert.h>
int _tmain(int argc, _TCHAR* argv[])
{
LCID lcid = 0;
BOOL ok = GetLocaleInfoEx(L"en-US", LOCALE_RETURN_NUMBER | LOCALE_ILANGUAGE, (LPWSTR)&lcid, sizeof(lcid));
assert(ok);
wprintf(L"LCID = %04x\n", lcid);
return 0;
}
Output: LCID = 0409