aboutsummaryrefslogtreecommitdiff
path: root/game/src/LocaleButton.gd
diff options
context:
space:
mode:
author George L. Albany <Megacake1234@gmail.com>2023-02-12 16:09:17 +0100
committer GitHub <noreply@github.com>2023-02-12 16:09:17 +0100
commitc0d8a4ac3723021c95da9674c3bc0eea511ee3a0 (patch)
tree4ca4a0835cb833fbba1983f0e8de5fa66227b86e /game/src/LocaleButton.gd
parent537938683b748dbf5fcd78276aa823f168f715f1 (diff)
parent3798205c740e7e2faf2594866cb497260012508c (diff)
Merge pull request #7 from Spartan322/feature/usable-ui
Diffstat (limited to 'game/src/LocaleButton.gd')
-rw-r--r--game/src/LocaleButton.gd26
1 files changed, 26 insertions, 0 deletions
diff --git a/game/src/LocaleButton.gd b/game/src/LocaleButton.gd
new file mode 100644
index 0000000..eed815e
--- /dev/null
+++ b/game/src/LocaleButton.gd
@@ -0,0 +1,26 @@
+extends OptionButton
+
+var _locales_country_rename : Dictionary
+var _locales_list : Array[String]
+
+func _ready():
+ print("Loading locale button")
+
+ _locales_country_rename = ProjectSettings.get_setting("internationalization/locale/country_short_name", {})
+
+ _locales_list = [TranslationServer.get_locale()]
+ _locales_list.append_array(TranslationServer.get_loaded_locales())
+
+ for locale in _locales_list:
+ var locale_name := TranslationServer.get_locale_name(locale)
+ var locale_first_part := locale_name.get_slice(", ", 0)
+ var locale_second_part := locale_name.substr(locale_first_part.length() + 2)
+ if locale_second_part in _locales_country_rename:
+ locale_second_part = _locales_country_rename[locale_second_part]
+
+ add_item("%s, %s" % [locale_first_part, locale_second_part])
+
+
+func _on_item_selected(index):
+ print("Selected locale " + _locales_list[index])
+ TranslationServer.set_locale(_locales_list[index])