Skip to content

Instantly share code, notes, and snippets.

@hotwatermorning
Created February 7, 2017 06:56
Show Gist options
  • Save hotwatermorning/a94064c3bfeaf131bcb0bac32137dbd2 to your computer and use it in GitHub Desktop.
Save hotwatermorning/a94064c3bfeaf131bcb0bac32137dbd2 to your computer and use it in GitHub Desktop.
Make locale string from locale id
// https://www.codeproject.com/Articles/9600/Windows-SetThreadLocale-and-CRT-setlocale
// 0x0411 -> "japanese_Japan.932"
// 0x041E -> "Thai_Thailand.874"
// 0x0808 -> "Chinese (Simplified)_China.936"
std::string make_locale_id_string(LCID locale_id)
{
std::string ret;
std::array<char, 128> buf;
buf.fill(0);
int const buf_writable = buf.size() - 1;
int result = GetLocaleInfoA(locale_id, LOCALE_SENGLANGUAGE, buf.data(), buf_writable);
if(result == 0) {
return ret;
}
ret = buf.data();
buf.fill(0);
result = GetLocaleInfoA(locale_id, LOCALE_SENGCOUNTRY, buf.data(), buf_writable);
if(result == 0) {
return ret;
}
if(*buf.data() != NULL) {
ret += std::string("_") + buf.data();
}
result = GetLocaleInfoA(locale_id, LOCALE_IDEFAULTANSICODEPAGE, buf.data(), buf_writable);
if(result == 0) {
result = GetLocaleInfoA(locale_id, LOCALE_IDEFAULTCODEPAGE, buf.data(), buf_writable);
if(result == 0) {
return ret;
}
}
if(*buf.data() != NULL) {
ret += std::string(".") + buf.data();
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment