Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows: Get LCID from locale string?

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.

like image 248
Nick Heiner Avatar asked Dec 06 '25 07:12

Nick Heiner


1 Answers

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

like image 106
Hans Passant Avatar answered Dec 07 '25 21:12

Hans Passant