Localization concept added
This commit is contained in:
8
localization/MainStrings.csv
Normal file
8
localization/MainStrings.csv
Normal file
@@ -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";"Назад"
|
||||
|
17
localization/MainStrings.csv.import
Normal file
17
localization/MainStrings.csv.import
Normal file
@@ -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
|
||||
BIN
localization/MainStrings.en.translation
Normal file
BIN
localization/MainStrings.en.translation
Normal file
Binary file not shown.
BIN
localization/MainStrings.ru.translation
Normal file
BIN
localization/MainStrings.ru.translation
Normal file
Binary file not shown.
@@ -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": "Русский"
|
||||
|
||||
@@ -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"
|
||||
|
||||
11
scripts/LocalizationManager.gd
Normal file
11
scripts/LocalizationManager.gd
Normal file
@@ -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")
|
||||
1
scripts/LocalizationManager.gd.uid
Normal file
1
scripts/LocalizationManager.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bedt5lbt48out
|
||||
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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`"
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user