From b1e79492abcf1bef482e649ee1e8464a950514cc Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 20 Jul 2025 16:41:54 +0400 Subject: [PATCH] Localization concept added --- localization/MainStrings.csv | 8 ++++++ localization/MainStrings.csv.import | 17 +++++++++++++ localization/MainStrings.en.translation | Bin 0 -> 658 bytes localization/MainStrings.ru.translation | Bin 0 -> 777 bytes localization/languages.json | 12 --------- project.godot | 6 ++++- scripts/LocalizationManager.gd | 11 ++++++++ scripts/LocalizationManager.gd.uid | 1 + scripts/PressAnyKeyScreen.gd | 4 +++ scripts/SettingsManager.gd | 10 ++++++-- scripts/SettingsMenu.gd | 11 ++++++++ ui/PressAnyKeyScreen.tscn | 4 +-- ui/SettingsMenu.tscn | 32 +++++++++++++++++++++--- 13 files changed, 95 insertions(+), 21 deletions(-) create mode 100644 localization/MainStrings.csv create mode 100644 localization/MainStrings.csv.import create mode 100644 localization/MainStrings.en.translation create mode 100644 localization/MainStrings.ru.translation create mode 100644 scripts/LocalizationManager.gd create mode 100644 scripts/LocalizationManager.gd.uid diff --git a/localization/MainStrings.csv b/localization/MainStrings.csv new file mode 100644 index 0000000..8fc4d4a --- /dev/null +++ b/localization/MainStrings.csv @@ -0,0 +1,8 @@ +keys;en;ru +press_ok_continue;"Press Ok to continue";"Нажми Ok, чтобы продолжить" +settings_title;"Settings";"Настройки" +master_volume;"Master Volume";"Общая громкость" +music_volume;"Music Volume";"Громкость музыки" +sfx_volume;"SFX Volume";"Громкость эффектов" +language;"Language";"Язык" +back;"Back";"Назад" diff --git a/localization/MainStrings.csv.import b/localization/MainStrings.csv.import new file mode 100644 index 0000000..f1138c4 --- /dev/null +++ b/localization/MainStrings.csv.import @@ -0,0 +1,17 @@ +[remap] + +importer="csv_translation" +type="Translation" +uid="uid://c5f1ss8oh62py" + +[deps] + +files=["res://localization/MainStrings.en.translation", "res://localization/MainStrings.ru.translation"] + +source_file="res://localization/MainStrings.csv" +dest_files=["res://localization/MainStrings.en.translation", "res://localization/MainStrings.ru.translation"] + +[params] + +compress=true +delimiter=1 diff --git a/localization/MainStrings.en.translation b/localization/MainStrings.en.translation new file mode 100644 index 0000000000000000000000000000000000000000..b950f4afc55176a33ab04e46e01ae1cd70037e18 GIT binary patch literal 658 zcma)4Jxc>Y5Zy!*74fSuh>aJ8hzJJJN(4bgEDQ;W20`%HoJ(@ttDQ~eT`oV-WFbNb}%50iv;$+|B zjmq%Y$=0U9ehX=7}3h;z{>Ny9T+3L;|(U=9c;t>yE- z-BfQHD^jopT8sG8kk~a1i|7m;1Sn+6$<6Venly?GG%eCoQJw?SeuTHv^}Bg6%_JlN z(wD8&_5_%0A>6i~W;c53xc~F~;dmN4^^&P^fA-?Njgrv}x>V;m^SBBoI|)DiuOHej zYC0Q%?lA)tfS{DUVVy+LDqokza>;;Igi@i=L1F2h1=VyWX9uj{OViM*uI=L)D?5jA Xy2qWmkLP5Y+^{e%d{x@FjKA?43SO46 literal 0 HcmV?d00001 diff --git a/localization/MainStrings.ru.translation b/localization/MainStrings.ru.translation new file mode 100644 index 0000000000000000000000000000000000000000..6c5955085890f63829d924524a3180a781871e64 GIT binary patch literal 777 zcmaKrPe>a<6voHev`VoErQ)d_Z4nAWkWvq&C+l5^o?SQVV3s5s-Ps)4i+>s@R;7g= zJlT`rNov(-k_IdE*vlKd^xodvf_MGi>_(*j27Y{RzW3hj%p=K+XP$~=U4=5&z-=%# z8~H{5xtg8`-9Q)I$S(!3lDJ+o8k_ggIB|oXE`#zi$!JK{V`MdzVpK#It?U&q!$5Utc9d|(u&<5?$0X3;6$MS>HyfjO6L?6tG zq)%o6;Xe3?ikew6tG3)MBIHz^8dMYX4&}?VV_r+zvwjo)k*z|*+utooP4j{d%}U(; iXWp!tim6bQ8ul)`g5JmF@nsKj;eGpK;`e3nCpZWG9{Ujh literal 0 HcmV?d00001 diff --git a/localization/languages.json b/localization/languages.json index c214334..b0c8e73 100644 --- a/localization/languages.json +++ b/localization/languages.json @@ -4,18 +4,6 @@ "name": "English", "display_name": "English" }, - "es": { - "name": "Spanish", - "display_name": "Español" - }, - "fr": { - "name": "French", - "display_name": "Français" - }, - "de": { - "name": "German", - "display_name": "Deutsch" - }, "ru": { "name": "Russian", "display_name": "Русский" diff --git a/project.godot b/project.godot index 20fbd1c..2cf133b 100644 --- a/project.godot +++ b/project.godot @@ -17,9 +17,9 @@ config/icon="res://icon.svg" [autoload] +SettingsManager="*res://scripts/SettingsManager.gd" AudioManager="*res://scripts/AudioManager.gd" GameManager="*res://scripts/GameManager.gd" -SettingsManager="*res://scripts/SettingsManager.gd" LocalizationManager="*res://scripts/LocalizationManager.gd" [input] @@ -44,6 +44,10 @@ ui_menu_toggle={ ] } +[internationalization] + +locale/translations=PackedStringArray("res://localization/MainStrings.en.translation", "res://localization/MainStrings.ru.translation") + [rendering] renderer/rendering_method="mobile" diff --git a/scripts/LocalizationManager.gd b/scripts/LocalizationManager.gd new file mode 100644 index 0000000..3563e83 --- /dev/null +++ b/scripts/LocalizationManager.gd @@ -0,0 +1,11 @@ +extends Node + +func _ready(): + # Set default locale if not already set + if TranslationServer.get_locale() == "": + TranslationServer.set_locale("en") + +func change_language(locale: String): + TranslationServer.set_locale(locale) + # Signal to update UI elements + get_tree().call_group("localizable", "update_text") diff --git a/scripts/LocalizationManager.gd.uid b/scripts/LocalizationManager.gd.uid new file mode 100644 index 0000000..0779427 --- /dev/null +++ b/scripts/LocalizationManager.gd.uid @@ -0,0 +1 @@ +uid://bedt5lbt48out diff --git a/scripts/PressAnyKeyScreen.gd b/scripts/PressAnyKeyScreen.gd index bcb7cfe..eedbbda 100644 --- a/scripts/PressAnyKeyScreen.gd +++ b/scripts/PressAnyKeyScreen.gd @@ -4,9 +4,13 @@ signal any_key_pressed func _ready(): print("PressAnyKeyScreen ready") + update_text() func _input(event): if event.is_action_pressed("any_key") or event is InputEventScreenTouch: print("Any key pressed: ", event) any_key_pressed.emit() get_viewport().set_input_as_handled() + +func update_text(): + $PressKeyContainer/PressKeyLabel.text = tr("press_ok_continue") diff --git a/scripts/SettingsManager.gd b/scripts/SettingsManager.gd index 7301ea3..64369d8 100644 --- a/scripts/SettingsManager.gd +++ b/scripts/SettingsManager.gd @@ -5,6 +5,9 @@ const SETTINGS_FILE = "user://settings.cfg" # prod `user://`=`%APPDATA%\Skelly\` var settings = { +} + +var default_settings = { "master_volume": 0.50, "music_volume": 0.40, "sfx_volume": 0.50, @@ -21,11 +24,14 @@ func _ready(): func load_settings(): var config = ConfigFile.new() if config.load(SETTINGS_FILE) == OK: - for key in settings.keys(): - settings[key] = config.get_value("settings", key, settings[key]) + for key in default_settings.keys(): + settings[key] = config.get_value("settings", key, default_settings[key]) print("Settings loaded: ", settings) else: print("No settings file found, using defaults") + print("Language is set to: ", settings["language"]) + TranslationServer.set_locale(settings["language"]) + # TODO: Apply values for volume control func save_settings(): var config = ConfigFile.new() diff --git a/scripts/SettingsMenu.gd b/scripts/SettingsMenu.gd index db104f6..c78cf8f 100644 --- a/scripts/SettingsMenu.gd +++ b/scripts/SettingsMenu.gd @@ -23,6 +23,7 @@ func _ready(): # Setup language selector from JSON data setup_language_selector() + update_text() func _on_master_volume_changed(value: float): @@ -70,3 +71,13 @@ func _on_language_selector_item_selected(index: int): var selected_lang = language_codes[index] SettingsManager.set_setting("language", selected_lang) print("Language changed to: ", selected_lang) + LocalizationManager.change_language(selected_lang) + +func update_text(): + # Update all the label texts when language changes + $SettingsContainer/SettingsTitle.text = tr("settings_title") + $SettingsContainer/MasterVolumeContainer/MasterVolume.text = tr("master_volume") + $SettingsContainer/MusicVolumeContainer/MusicVolume.text = tr("music_volume") + $SettingsContainer/SFXVolumeContainer/SFXVolume.text = tr("sfx_volume") + $SettingsContainer/LanguageContainer/LanguageLabel.text = tr("language") + $BackButtonContainer/BackButton.text = tr("back") diff --git a/ui/PressAnyKeyScreen.tscn b/ui/PressAnyKeyScreen.tscn index 64d1c43..335cd83 100644 --- a/ui/PressAnyKeyScreen.tscn +++ b/ui/PressAnyKeyScreen.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" uid="uid://buak21ajgvevl" path="res://scripts/PressAnyKeyScreen.gd" id="1_0a4p2"] -[node name="PressAnyKeyScreen" type="Control"] +[node name="PressAnyKeyScreen" type="Control" groups=["localizable"]] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -42,4 +42,4 @@ horizontal_alignment = 1 [node name="PressKeyLabel" type="Label" parent="PressKeyContainer"] layout_mode = 2 -text = "Press Ok to continue" +text = "`press_ok_continue`" diff --git a/ui/SettingsMenu.tscn b/ui/SettingsMenu.tscn index b89cb1a..0bc13df 100644 --- a/ui/SettingsMenu.tscn +++ b/ui/SettingsMenu.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" uid="uid://c8mlvlerv4y03" path="res://scripts/SettingsMenu.gd" id="1_oqkcn"] -[node name="SettingsMenu" type="Control"] +[node name="SettingsMenu" type="Control" groups=["localizable"]] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -107,7 +107,7 @@ popup/item_2/id = 2 popup/item_3/text = "Deutsch" popup/item_3/id = 3 popup/item_4/text = "Русский" -popup/item_4/id = 4 +popup/item_4/id = 2 [node name="BackButtonContainer" type="Control" parent="."] layout_mode = 1 @@ -115,14 +115,38 @@ anchors_preset = 0 offset_right = 40.0 offset_bottom = 40.0 -[node name="Button" type="Button" parent="BackButtonContainer"] +[node name="BackButton" type="Button" parent="BackButtonContainer"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 text = "back" +[node name="ResetSettingsContainer" type="Control" parent="."] +layout_mode = 1 +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = -20.0 +offset_top = -40.0 +offset_right = 20.0 +grow_horizontal = 2 +grow_vertical = 0 + +[node name="ResetSettingButton" type="Button" parent="ResetSettingsContainer"] +layout_mode = 1 +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -98.0 +offset_right = 98.0 +offset_bottom = 31.0 +grow_horizontal = 2 +text = "Reset settings to default" + [connection signal="value_changed" from="SettingsContainer/MasterVolumeContainer/MasterVolumeSlider" to="." method="_on_master_volume_changed"] [connection signal="value_changed" from="SettingsContainer/MusicVolumeContainer/MusicVolumeSlider" to="." method="_on_music_volume_changed"] [connection signal="value_changed" from="SettingsContainer/SFXVolumeContainer/SFXVolumeSlider" to="." method="_on_sfx_volume_changed"] [connection signal="item_selected" from="SettingsContainer/LanguageContainer/LanguageSelector" to="." method="_on_language_selector_item_selected"] -[connection signal="pressed" from="BackButtonContainer/Button" to="." method="_on_back_button_pressed"] +[connection signal="pressed" from="BackButtonContainer/BackButton" to="." method="_on_back_button_pressed"]