47 lines
1.5 KiB
GDScript3
47 lines
1.5 KiB
GDScript3
|
extends Control
|
||
|
|
||
|
|
||
|
# Called when the node enters the scene tree for the first time.
|
||
|
func _ready():
|
||
|
$window_dialog/margin_container/v_box_container/option_button.clear()
|
||
|
var id = 0
|
||
|
var selected = -1
|
||
|
var near_selected = -1
|
||
|
var current_locale = TranslationServer.get_locale()
|
||
|
var root_language = current_locale.split('_')[0]
|
||
|
|
||
|
for key in TranslationServer.get_loaded_locales():
|
||
|
if key == TranslationServer.get_locale():
|
||
|
selected = id
|
||
|
else:
|
||
|
var tmp = key.split("_")
|
||
|
# print("tmp:" + tmp[0])
|
||
|
if tmp[0] == root_language:
|
||
|
if tmp.size() == 1:
|
||
|
near_selected = id
|
||
|
elif near_selected == -1:
|
||
|
near_selected = id
|
||
|
$window_dialog/margin_container/v_box_container/option_button.add_item(TranslationServer.get_locale_name(key) + " [" + key + "]", id)
|
||
|
id += 1
|
||
|
if selected == -1 and near_selected != -1:
|
||
|
selected = near_selected
|
||
|
if selected == -1:
|
||
|
# Your language not exist, create it just for the form
|
||
|
var key = TranslationServer.get_locale()
|
||
|
$window_dialog/margin_container/v_box_container/option_button.add_item(TranslationServer.get_locale_name(key) + " (" + key + " !)", id)
|
||
|
selected = id
|
||
|
$window_dialog/margin_container/v_box_container/option_button.select(selected)
|
||
|
|
||
|
|
||
|
func _on_option_button_item_selected(index):
|
||
|
var id = 0
|
||
|
for key in TranslationServer.get_loaded_locales():
|
||
|
if id == $window_dialog/margin_container/v_box_container/option_button.get_selected():
|
||
|
TranslationServer.set_locale(key)
|
||
|
return
|
||
|
id += 1
|
||
|
|
||
|
|
||
|
func _on_button_pressed():
|
||
|
$window_dialog.hide()
|