mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Change the locale by finding the nearest loaded locale instead of looking for a hard match
Should fix issues where the OS was returning, for example, "fr" for the system locale, and it was not mapped to "fr_FR".
This commit is contained in:
parent
fecb9b5803
commit
1c3780c94c
|
@ -1020,14 +1020,31 @@ func path_join_array(basepaths: PackedStringArray, subpath: String) -> PackedStr
|
||||||
func set_locale(locale: String) -> void:
|
func set_locale(locale: String) -> void:
|
||||||
if TranslationServer.get_locale() == locale:
|
if TranslationServer.get_locale() == locale:
|
||||||
return
|
return
|
||||||
|
locale = find_nearest_locale(locale)
|
||||||
if not locale in TranslationServer.get_loaded_locales():
|
if not locale in TranslationServer.get_loaded_locales():
|
||||||
var translation := load("res://Translations/%s.po" % locale)
|
var translation := load("res://Translations/%s.po" % locale)
|
||||||
if is_instance_valid(translation) and translation is Translation:
|
if is_instance_valid(translation) and translation is Translation:
|
||||||
TranslationServer.add_translation(translation)
|
TranslationServer.add_translation(translation)
|
||||||
|
else:
|
||||||
|
printerr("Translation %s for locale %s failed to load." % [translation, locale])
|
||||||
|
return
|
||||||
Keychain.load_translation(locale)
|
Keychain.load_translation(locale)
|
||||||
TranslationServer.set_locale(locale)
|
TranslationServer.set_locale(locale)
|
||||||
|
|
||||||
|
|
||||||
|
func find_nearest_locale(locale: String) -> String:
|
||||||
|
if locale in loaded_locales:
|
||||||
|
return locale
|
||||||
|
var max_similarity_score := 0
|
||||||
|
var closest_locale := "en_US"
|
||||||
|
for loaded_locale in loaded_locales:
|
||||||
|
var compared := TranslationServer.compare_locales(locale, loaded_locale)
|
||||||
|
if compared > max_similarity_score:
|
||||||
|
max_similarity_score = compared
|
||||||
|
closest_locale = loaded_locale
|
||||||
|
return closest_locale
|
||||||
|
|
||||||
|
|
||||||
## Used by undo/redo operations to store compressed images in memory.
|
## Used by undo/redo operations to store compressed images in memory.
|
||||||
## [param redo_data] and [param undo_data] are Dictionaries,
|
## [param redo_data] and [param undo_data] are Dictionaries,
|
||||||
## with keys of type [Image] and [Dictionary] values, coming from [member Image.data].
|
## with keys of type [Image] and [Dictionary] values, coming from [member Image.data].
|
||||||
|
|
Loading…
Reference in a new issue