From 30dfb6aa58f64aee07a1a4c3703549e3ba7574cf Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Tue, 23 Jul 2024 19:34:49 +0300 Subject: [PATCH] Try to fix issue when certain languages are set to the OS system locale and some GUI elements are not being translated during startup Only confirmed with Brazilian Portuguese at the moment --- addons/README.md | 2 +- addons/keychain/Keychain.gd | 5 +++++ src/Autoload/Global.gd | 15 ++++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/addons/README.md b/addons/README.md index 994d23949..561030c1a 100644 --- a/addons/README.md +++ b/addons/README.md @@ -9,7 +9,7 @@ ## Keychain - Upstream: https://github.com/Orama-Interactive/Keychain -- Version: [34bd83ab13f32c932479db8be4bb8c8b7e594fa2](https://github.com/Orama-Interactive/Keychain/commit/34bd83ab13f32c932479db8be4bb8c8b7e594fa2) +- Version: [0e675303915543eb04e9c91116974e73337640fc](https://github.com/Orama-Interactive/Keychain/commit/0e675303915543eb04e9c91116974e73337640fc) - License: [MIT](https://github.com/Orama-Interactive/Keychain/blob/main/LICENSE) ## gdgifexporter diff --git a/addons/keychain/Keychain.gd b/addons/keychain/Keychain.gd index b523a75b1..c75e37dc6 100644 --- a/addons/keychain/Keychain.gd +++ b/addons/keychain/Keychain.gd @@ -48,6 +48,11 @@ class InputGroup: folded = _folded +func _init() -> void: + for locale in TranslationServer.get_loaded_locales(): + load_translation(locale) + + func _ready() -> void: if !config_file: config_file = ConfigFile.new() diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 415d4a48c..f29a267c2 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -654,6 +654,11 @@ func _init() -> void: # Load settings from the config file config_cache.load(CONFIG_PATH) loaded_locales.sort() # Make sure locales are always sorted + var saved_locale := OS.get_locale() + # Load language + if config_cache.has_section_key("preferences", "locale"): + saved_locale = config_cache.get_value("preferences", "locale") + set_locale(saved_locale, false) # If no language is saved, OS' locale is used if OS.has_feature("template"): root_directory = OS.get_executable_path().get_base_dir() if OS.get_name() == "macOS": @@ -682,11 +687,6 @@ func _init() -> void: func _ready() -> void: _initialize_keychain() - var saved_locale := OS.get_locale() - # Load language - if config_cache.has_section_key("preferences", "locale"): - saved_locale = config_cache.get_value("preferences", "locale") - set_locale(saved_locale) # If no language is saved, OS' locale is used default_width = config_cache.get_value("preferences", "default_width", default_width) default_height = config_cache.get_value("preferences", "default_height", default_height) default_fill_color = config_cache.get_value( @@ -999,7 +999,7 @@ func path_join_array(basepaths: PackedStringArray, subpath: String) -> PackedStr return res -func set_locale(locale: String) -> void: +func set_locale(locale: String, load_keychain := true) -> void: locale = find_nearest_locale(locale) if not locale in TranslationServer.get_loaded_locales(): var translation := load("res://Translations/%s.po" % locale) @@ -1008,7 +1008,8 @@ func set_locale(locale: String) -> void: else: printerr("Translation %s for locale %s failed to load." % [translation, locale]) return - Keychain.load_translation(locale) + if load_keychain: + Keychain.load_translation(locale) TranslationServer.set_locale(locale)