Skip to content

Commit

Permalink
Merge pull request #48176 from BrettDong/windows
Browse files Browse the repository at this point in the history
Fix translations not working on Windows for some Windows languages
  • Loading branch information
ZhilkinSerg authored Mar 21, 2021
2 parents 0d05f69 + 0bb9f7c commit 9c8c3f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/path_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ std::string find_translated_file( const std::string &base_path, const std::strin
std::string loc_name;
if( get_option<std::string>( "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 ) ) {
Expand Down
20 changes: 10 additions & 10 deletions src/translations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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 << '\'';
Expand Down

0 comments on commit 9c8c3f3

Please sign in to comment.