Last active
August 25, 2021 03:03
Localization Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"surprised": [ | |
"no", | |
"way", | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"surprised": [ | |
"no", | |
"puede", | |
"ser" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"message_1": [ | |
"The first part of the conversation", | |
"The second part of the conversation", | |
"The third part of the conversation | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class_name LManager | |
extends Node | |
signal language_changed(new_language) | |
const BASE_DIALOGUE_PATH := "res://resources/dialogues/" | |
var language := "en" | |
func get_dialogue_json(dialogue_name: String) -> String: | |
var _localized_dialogue := BASE_DIALOGUE_PATH + language + "/" + dialogue_name | |
var _file := File.new() | |
if _file.file_exists(_localized_dialogue): | |
return _localized_dialogue | |
return BASE_DIALOGUE_PATH + dialogue_name | |
func update_language(new_language: String) -> void: | |
language = new_language | |
TranslationServer.set_locale(language) | |
emit_signal("language_changed", language) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class_name LManager | |
extends Node | |
var language := "en" | |
func update_language(new_language: String) -> void: | |
language = new_language | |
TranslationServer.set_locale(language) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class_name LManager | |
extends Node | |
signal language_changed(new_language) | |
var language := "en" | |
func update_language(new_language: String) -> void: | |
language = new_language | |
TranslationServer.set_locale(language) | |
emit_signal("language_changed", language) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Control | |
func _on_SpanishButton_pressed() -> void: | |
LocalizationManager.update_language("es") | |
func _on_EnglishButton_pressed() -> void: | |
LocalizationManager.update_language("en") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Control | |
onready var label_two := get_node("LabelTwo") as Label | |
func _ready() -> void: | |
label_two.text = tr("UI_STRING_TWO") | |
func _on_SpanishButton_pressed() -> void: | |
LocalizationManager.update_language("es") | |
func _on_EnglishButton_pressed() -> void: | |
LocalizationManager.update_language("en") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Control | |
onready var label_two := get_node("LabelTwo") as Label | |
func _ready() -> void: | |
LocalizationManager.connect("language_changed", self, "_on_language_changed") | |
label_two.text = tr("UI_STRING_TWO") | |
func _on_SpanishButton_pressed() -> void: | |
LocalizationManager.update_language("es") | |
func _on_EnglishButton_pressed() -> void: | |
LocalizationManager.update_language("en") | |
func _on_language_changed(new_language: String) -> void: | |
label_two.text = tr("UI_STRING_TWO") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment