diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 800b3ebdc..1c04c1630 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -26,7 +26,6 @@ var current_project_index := 0 setget project_changed # that direction has been pressed. var key_move_press_time := [0.0, 0.0, 0.0, 0.0] -var loaded_locales : Array # Canvas related stuff var layers_changed_skip := false diff --git a/src/Preferences/HandleLanguages.gd b/src/Preferences/HandleLanguages.gd index 1c2559cd2..4154ebac0 100644 --- a/src/Preferences/HandleLanguages.gd +++ b/src/Preferences/HandleLanguages.gd @@ -1,10 +1,48 @@ extends Node + +const languages_dict := { + "en_US" : ["English", "English"], + "cs_CZ" : ["Czech", "Czech"], + "de_DE" : ["Deutsch", "German"], + "el_GR" : ["Ελληνικά", "Greek"], + "eo" : ["Esperanto", "Esperanto"], + "es_ES" : ["Español", "Spanish"], + "fr_FR" : ["Français", "French"], + "id_ID" : ["Indonesian", "Indonesian"], + "it_IT" : ["Italiano", "Italian"], + "lv_LV" : ["Latvian", "Latvian"], + "pl_PL" : ["Polski", "Polish"], + "pt_BR" : ["Português Brasileiro", "Brazilian Portuguese"], + "ru_RU" : ["Русский", "Russian"], + "zh_CN" : ["简体中文", "Chinese Simplified"], + "zh_TW" : ["繁體中文", "Chinese Traditional"], +} + +var loaded_locales : Array +onready var cjk_font = preload("res://assets/fonts/CJK/NotoSansCJKtc-Regular.tres") + + func _ready() -> void: - Global.loaded_locales = TranslationServer.get_loaded_locales() + loaded_locales = TranslationServer.get_loaded_locales() # Make sure locales are always sorted, in the same order - Global.loaded_locales.sort() + loaded_locales.sort() + var button_group = get_child(0).group + + # Create radiobuttons for each language + for locale in loaded_locales: + if !locale in languages_dict: + continue + var button = CheckBox.new() + button.text = languages_dict[locale][0] + " [%s]" % [locale] + button.name = languages_dict[locale][1] + button.hint_tooltip = languages_dict[locale][1] + button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND + button.group = button_group + if "zh" in locale: + button.add_font_override("font", cjk_font) + add_child(button) # Load language if Global.config_cache.has_section_key("preferences", "locale"): @@ -12,7 +50,7 @@ func _ready() -> void: TranslationServer.set_locale(saved_locale) # Set the language option menu's default selected option to the loaded locale - var locale_index: int = Global.loaded_locales.find(saved_locale) + var locale_index: int = loaded_locales.find(saved_locale) get_child(0).pressed = false # Unset System Language option in preferences get_child(locale_index + 1).pressed = true else: # If the user doesn't have a language preference, set it to their OS' locale @@ -34,7 +72,7 @@ func _on_Language_pressed(index : int) -> void: if index == 0: TranslationServer.set_locale(OS.get_locale()) else: - TranslationServer.set_locale(Global.loaded_locales[index - 1]) + TranslationServer.set_locale(loaded_locales[index - 1]) if "zh" in TranslationServer.get_locale(): Global.control.theme.default_font = preload("res://assets/fonts/CJK/NotoSansCJKtc-Regular.tres") diff --git a/src/Preferences/PreferencesDialog.tscn b/src/Preferences/PreferencesDialog.tscn index 2cbf805a0..53fe4ae59 100644 --- a/src/Preferences/PreferencesDialog.tscn +++ b/src/Preferences/PreferencesDialog.tscn @@ -1,8 +1,6 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://src/Preferences/PreferencesDialog.gd" type="Script" id=1] -[ext_resource path="res://assets/fonts/Roboto-Regular.tres" type="DynamicFont" id=2] -[ext_resource path="res://assets/fonts/CJK/NotoSansCJKtc-Regular.tres" type="DynamicFont" id=3] [ext_resource path="res://src/Preferences/HandleLanguages.gd" type="Script" id=4] [ext_resource path="res://src/Preferences/HandleThemes.gd" type="Script" id=5] [ext_resource path="res://src/Preferences/HandleShortcuts.gd" type="Script" id=6] @@ -115,129 +113,6 @@ pressed = true group = SubResource( 1 ) text = "System Language" -[node name="Czech" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 28.0 -margin_right = 506.0 -margin_bottom = 52.0 -mouse_default_cursor_shape = 2 -group = SubResource( 1 ) -text = "Czech [cs]" - -[node name="German" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 56.0 -margin_right = 506.0 -margin_bottom = 80.0 -mouse_default_cursor_shape = 2 -group = SubResource( 1 ) -text = "Deutsch [de]" - -[node name="Greek" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 84.0 -margin_right = 506.0 -margin_bottom = 108.0 -mouse_default_cursor_shape = 2 -custom_fonts/font = ExtResource( 2 ) -group = SubResource( 1 ) -text = "Ελληνικά [el]" - -[node name="English" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 112.0 -margin_right = 506.0 -margin_bottom = 136.0 -mouse_default_cursor_shape = 2 -group = SubResource( 1 ) -text = "English [en]" - -[node name="Esperanto" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 140.0 -margin_right = 506.0 -margin_bottom = 164.0 -mouse_default_cursor_shape = 2 -group = SubResource( 1 ) -text = "Esperanto [eo]" - -[node name="Spanish" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 168.0 -margin_right = 506.0 -margin_bottom = 192.0 -mouse_default_cursor_shape = 2 -group = SubResource( 1 ) -text = "Español [es]" - -[node name="French" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 196.0 -margin_right = 506.0 -margin_bottom = 220.0 -mouse_default_cursor_shape = 2 -group = SubResource( 1 ) -text = "Français [fr]" - -[node name="Indonesian" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 224.0 -margin_right = 506.0 -margin_bottom = 248.0 -mouse_default_cursor_shape = 2 -group = SubResource( 1 ) -text = "Indonesian [id]" - -[node name="Italian" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 252.0 -margin_right = 506.0 -margin_bottom = 276.0 -mouse_default_cursor_shape = 2 -group = SubResource( 1 ) -text = "Italiano [it]" - -[node name="Latvian" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 280.0 -margin_right = 506.0 -margin_bottom = 304.0 -mouse_default_cursor_shape = 2 -group = SubResource( 1 ) -text = "Latvian [lv]" - -[node name="Polish" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 308.0 -margin_right = 506.0 -margin_bottom = 332.0 -mouse_default_cursor_shape = 2 -group = SubResource( 1 ) -text = "Polski [pl]" - -[node name="Brazilian Portuguese" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 336.0 -margin_right = 506.0 -margin_bottom = 360.0 -mouse_default_cursor_shape = 2 -group = SubResource( 1 ) -text = "Português Brasileiro [pt_BR]" - -[node name="Russian" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 364.0 -margin_right = 506.0 -margin_bottom = 388.0 -mouse_default_cursor_shape = 2 -group = SubResource( 1 ) -text = "Русский [ru]" - -[node name="Chinese Simplified" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 392.0 -margin_right = 506.0 -margin_bottom = 418.0 -mouse_default_cursor_shape = 2 -custom_fonts/font = ExtResource( 3 ) -group = SubResource( 1 ) -text = "简体中文 [zh_CN]" - -[node name="Chinese Traditional" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] -margin_top = 422.0 -margin_right = 506.0 -margin_bottom = 448.0 -mouse_default_cursor_shape = 2 -custom_fonts/font = ExtResource( 3 ) -group = SubResource( 1 ) -text = "繁體中文 [zh_TW]" - [node name="Themes" type="HBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"] visible = false margin_top = 28.0