mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Clear some code in HandleLanguages.gd
Got rid of the second for loop, so maybe this is a minor speedup as well.
This commit is contained in:
parent
5c664b1880
commit
92e0e7e11c
|
@ -27,21 +27,21 @@ const LANGUAGES_DICT := {
|
||||||
"uk_UA": ["Українська", "Ukrainian"],
|
"uk_UA": ["Українська", "Ukrainian"],
|
||||||
}
|
}
|
||||||
|
|
||||||
var loaded_locales: Array
|
var loaded_locales := LANGUAGES_DICT.keys()
|
||||||
onready var system_language: CheckBox = $"System Language"
|
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
loaded_locales = TranslationServer.get_loaded_locales()
|
loaded_locales.sort() # Make sure locales are always sorted
|
||||||
|
var locale_index := -1
|
||||||
|
var saved_locale := OS.get_locale()
|
||||||
|
# Load language
|
||||||
|
if Global.config_cache.has_section_key("preferences", "locale"):
|
||||||
|
saved_locale = Global.config_cache.get_value("preferences", "locale")
|
||||||
|
locale_index = loaded_locales.find(saved_locale)
|
||||||
|
TranslationServer.set_locale(saved_locale) # If no language is saved, OS' locale is used
|
||||||
|
|
||||||
# Make sure locales are always sorted, in the same order
|
var button_group: ButtonGroup = $"System Language".group
|
||||||
loaded_locales.sort()
|
for locale in loaded_locales: # Create radiobuttons for each language
|
||||||
var button_group: ButtonGroup = system_language.group
|
|
||||||
|
|
||||||
# Create radiobuttons for each language
|
|
||||||
for locale in loaded_locales:
|
|
||||||
if !locale in LANGUAGES_DICT:
|
|
||||||
continue
|
|
||||||
var button := CheckBox.new()
|
var button := CheckBox.new()
|
||||||
button.text = LANGUAGES_DICT[locale][0] + " [%s]" % [locale]
|
button.text = LANGUAGES_DICT[locale][0] + " [%s]" % [locale]
|
||||||
button.name = LANGUAGES_DICT[locale][1]
|
button.name = LANGUAGES_DICT[locale][1]
|
||||||
|
@ -49,36 +49,19 @@ func _ready() -> void:
|
||||||
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||||
button.group = button_group
|
button.group = button_group
|
||||||
add_child(button)
|
add_child(button)
|
||||||
|
button.connect("pressed", self, "_on_Language_pressed", [button.get_index()])
|
||||||
# Load language
|
get_child(locale_index + 2).pressed = true # Select the appropriate button
|
||||||
if Global.config_cache.has_section_key("preferences", "locale"):
|
|
||||||
var saved_locale: String = Global.config_cache.get_value("preferences", "locale")
|
|
||||||
TranslationServer.set_locale(saved_locale)
|
|
||||||
|
|
||||||
# Set the language option menu's default selected option to the loaded locale
|
|
||||||
var locale_index: int = loaded_locales.find(saved_locale)
|
|
||||||
system_language.pressed = false # Unset System Language option in preferences
|
|
||||||
get_child(locale_index + 2).pressed = true
|
|
||||||
else: # If the user doesn't have a language preference, set it to their OS' locale
|
|
||||||
TranslationServer.set_locale(OS.get_locale())
|
|
||||||
|
|
||||||
for child in get_children():
|
|
||||||
if child is Button:
|
|
||||||
child.connect("pressed", self, "_on_Language_pressed", [child.get_index()])
|
|
||||||
child.hint_tooltip = child.name
|
|
||||||
|
|
||||||
|
|
||||||
func _on_Language_pressed(index: int) -> void:
|
func _on_Language_pressed(index: int) -> void:
|
||||||
get_child(index).pressed = true
|
|
||||||
if index == 1:
|
if index == 1:
|
||||||
TranslationServer.set_locale(OS.get_locale())
|
TranslationServer.set_locale(OS.get_locale())
|
||||||
else:
|
else:
|
||||||
TranslationServer.set_locale(loaded_locales[index - 2])
|
TranslationServer.set_locale(loaded_locales[index - 2])
|
||||||
|
|
||||||
Global.config_cache.set_value("preferences", "locale", TranslationServer.get_locale())
|
Global.config_cache.set_value("preferences", "locale", TranslationServer.get_locale())
|
||||||
Global.config_cache.save("user://cache.ini")
|
Global.config_cache.save("user://cache.ini")
|
||||||
|
|
||||||
# Update Translations
|
# Update some UI elements with the new translations
|
||||||
Global.update_hint_tooltips()
|
Global.update_hint_tooltips()
|
||||||
Global.preferences_dialog.list.clear()
|
Global.preferences_dialog.list.clear()
|
||||||
Global.preferences_dialog.add_tabs(true)
|
Global.preferences_dialog.add_tabs(true)
|
||||||
|
|
|
@ -158,6 +158,7 @@ size_flags_horizontal = 3
|
||||||
[node name="System Language" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Language"]
|
[node name="System Language" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Language"]
|
||||||
margin_right = 506.0
|
margin_right = 506.0
|
||||||
margin_bottom = 24.0
|
margin_bottom = 24.0
|
||||||
|
hint_tooltip = "System Language"
|
||||||
mouse_default_cursor_shape = 2
|
mouse_default_cursor_shape = 2
|
||||||
pressed = true
|
pressed = true
|
||||||
group = SubResource( 1 )
|
group = SubResource( 1 )
|
||||||
|
@ -1528,6 +1529,7 @@ show_hidden_files = true
|
||||||
[connection signal="about_to_show" from="." to="." method="_on_PreferencesDialog_about_to_show"]
|
[connection signal="about_to_show" from="." to="." method="_on_PreferencesDialog_about_to_show"]
|
||||||
[connection signal="popup_hide" from="." to="." method="_on_PreferencesDialog_popup_hide"]
|
[connection signal="popup_hide" from="." to="." method="_on_PreferencesDialog_popup_hide"]
|
||||||
[connection signal="item_selected" from="HSplitContainer/List" to="." method="_on_List_item_selected"]
|
[connection signal="item_selected" from="HSplitContainer/List" to="." method="_on_List_item_selected"]
|
||||||
|
[connection signal="pressed" from="HSplitContainer/ScrollContainer/VBoxContainer/Language/System Language" to="HSplitContainer/ScrollContainer/VBoxContainer/Language" method="_on_Language_pressed" binds= [ 1 ]]
|
||||||
[connection signal="value_changed" from="HSplitContainer/ScrollContainer/VBoxContainer/Interface/ShrinkContainer/ShrinkHSlider" to="." method="_on_ShrinkHSlider_value_changed"]
|
[connection signal="value_changed" from="HSplitContainer/ScrollContainer/VBoxContainer/Interface/ShrinkContainer/ShrinkHSlider" to="." method="_on_ShrinkHSlider_value_changed"]
|
||||||
[connection signal="pressed" from="HSplitContainer/ScrollContainer/VBoxContainer/Interface/ShrinkContainer/ShrinkApplyButton" to="." method="_on_ShrinkApplyButton_pressed"]
|
[connection signal="pressed" from="HSplitContainer/ScrollContainer/VBoxContainer/Interface/ShrinkContainer/ShrinkApplyButton" to="." method="_on_ShrinkApplyButton_pressed"]
|
||||||
[connection signal="item_selected" from="HSplitContainer/ScrollContainer/VBoxContainer/Extensions/InstalledExtensions" to="HSplitContainer/ScrollContainer/VBoxContainer/Extensions" method="_on_InstalledExtensions_item_selected"]
|
[connection signal="item_selected" from="HSplitContainer/ScrollContainer/VBoxContainer/Extensions/InstalledExtensions" to="HSplitContainer/ScrollContainer/VBoxContainer/Extensions" method="_on_InstalledExtensions_item_selected"]
|
||||||
|
|
Loading…
Reference in a new issue