From fe978d5213fb5b2c2019652713488818086301ea Mon Sep 17 00:00:00 2001 From: Binrui Dong Date: Sun, 21 Mar 2021 17:22:38 -0400 Subject: [PATCH 1/2] Get system UI language on Windows --- src/main.cpp | 2 +- src/path_info.cpp | 2 +- src/translations.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 95f01ac6a9486..61143863183f9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -675,7 +675,7 @@ int main( int argc, const char *argv[] ) #if defined(LOCALIZE) std::string lang; #if defined(_WIN32) - lang = getLangFromLCID( GetUserDefaultLCID() ); + lang = getLangFromLCID( GetUserDefaultUILanguage() ); #else const char *v = setlocale( LC_ALL, nullptr ); if( v != nullptr ) { diff --git a/src/path_info.cpp b/src/path_info.cpp index c8713d3068c43..55637b1124e9b 100644 --- a/src/path_info.cpp +++ b/src/path_info.cpp @@ -128,7 +128,7 @@ std::string find_translated_file( const std::string &base_path, const std::strin std::string loc_name; if( get_option( "USE_LANG" ).empty() ) { #if defined(_WIN32) - loc_name = getLangFromLCID( GetUserDefaultLCID() ); + loc_name = getLangFromLCID( GetUserDefaultUILanguage() ); if( !loc_name.empty() ) { const std::string local_path = base_path + loc_name + extension; if( file_exist( local_path ) ) { diff --git a/src/translations.cpp b/src/translations.cpp index f28acc3ac0113..a5c288c116b9c 100644 --- a/src/translations.cpp +++ b/src/translations.cpp @@ -213,7 +213,7 @@ void set_language() { std::string system_lang; #if defined(_WIN32) - system_lang = getLangFromLCID( GetUserDefaultLCID() ); + system_lang = getLangFromLCID( GetUserDefaultUILanguage() ); #elif defined(__APPLE__) system_lang = getAppleSystemLang(); // macOS and iOS #elif defined(__ANDROID__) From 0bb9f7cced3458e9121a56dc576cb55695ad0492 Mon Sep 17 00:00:00 2001 From: Binrui Dong Date: Sun, 21 Mar 2021 17:22:44 -0400 Subject: [PATCH 2/2] Set LANG environment variable on Windows --- src/translations.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/translations.cpp b/src/translations.cpp index a5c288c116b9c..411f7a18cf66f 100644 --- a/src/translations.cpp +++ b/src/translations.cpp @@ -226,26 +226,26 @@ void set_language() if( !lang_opt.empty() ) { // Not 'System Language' // Overwrite all system locale settings. Use CDDA settings. User wants this. -#if defined(_WIN32) - std::string lang_env = "LANGUAGE=" + lang_opt; - if( _putenv( lang_env.c_str() ) != 0 ) { - DebugLog( D_WARNING, D_MAIN ) << "Can't set 'LANGUAGE' environment variable"; - } -#else // LANGUAGE is ignored if LANG is set to C or unset // in this case we need to set LANG to something other than C to activate localization // Reference: https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html#The-LANGUAGE-variable const char *env_lang = getenv( "LANG" ); if( env_lang == nullptr || strcmp( env_lang, "C" ) == 0 ) { +#if defined(_WIN32) + if( _putenv( ( std::string( "LANG=" ) + lang_opt ).c_str() ) != 0 ) { +#else if( setenv( "LANG", lang_opt.c_str(), true ) != 0 ) { +#endif DebugLog( D_WARNING, D_MAIN ) << "Can't set 'LANG' environment variable"; } } +#if defined(_WIN32) + if( _putenv( ( std::string( "LANGUAGE=" ) + lang_opt ).c_str() ) != 0 ) { +#else if( setenv( "LANGUAGE", lang_opt.c_str(), true ) != 0 ) { - DebugLog( D_WARNING, D_MAIN ) << "Can't set 'LANGUAGE' environment variable"; - } #endif - else { + DebugLog( D_WARNING, D_MAIN ) << "Can't set 'LANGUAGE' environment variable"; + } else { const char *env = getenv( "LANGUAGE" ); if( env != nullptr ) { DebugLog( D_INFO, D_MAIN ) << "Language is set to: '" << env << '\'';