Get language name from windows locale code

458 Views Asked by At

I have an integer language code looking like this '1031' that needs to be translated to a string like 'German'.

On iOS it's implemented like so

locale = localeIdentifier(fromWindowsLocaleCode:)

language = locale.displayName(forKey: NSLocale.Key.languageCode, value: locale.languageCode)

Is there anything built in for this?

Backup plan is to parse this [MS-LCID]: Windows Language Code Identifier (LCID) Reference

2

There are 2 best solutions below

1
Gabriel Andrei On
0
confucius_007 On

On Windows official document, it discourages the use of LCID, It is better to use the locale name instead. Still, in your case, you can try GetLocaleInfoA,

wchar_t buffer[LOCALE_NAME_MAX_LENGTH];    
GetLocaleInfo(1031, LOCALE_SENGLISHLANGUAGENAME,
            (LPWSTR)&buffer, LOCALE_NAME_MAX_LENGTH)

from

#include <Windows.h>

It will give "German" as output in buffer array.