aboutsummaryrefslogtreecommitdiff
path: root/game/src/LocaleButton.gd
blob: 32807d0fe8063c833864072cf279f6f447c9da25 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
extends OptionButton

var _locales_country_rename : Dictionary
var _locales_list : Array[String]

func _ready():
   _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])

   Events.Options.load_settings.connect(load_setting)
   Events.Options.save_settings.connect(save_setting)


func load_setting(file : ConfigFile):
   var locale_index := _locales_list.find(file.get_value("Localization", "Locale", "") as String)
   if locale_index != -1:
      selected = locale_index

func save_setting(file : ConfigFile):
   file.set_value("Localization", "Locale", _locales_list[selected])

func _on_item_selected(index):
   TranslationServer.set_locale(_locales_list[index])
   Events.Options.save_settings_from_file.call_deferred()