Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌎 Translation Support #118

Draft
wants to merge 5 commits into
base: godot-4.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added addons/pandora/l10n/en.mo
Binary file not shown.
89 changes: 89 additions & 0 deletions addons/pandora/l10n/en.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
msgid ""
msgstr ""
"Project-Id-Version: Pandora\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.3.2\n"

msgid "ui.control_bar.create_category_button.tooltip"
msgstr "Create Category"

msgid "ui.control_bar.create_entity_button.tooltip"
msgstr "Create Entity"

msgid "ui.control_bar.regenerate_id_button.tooltip"
msgstr ""
"Generate a new ID for selected entry.\n"
"Shift-click: generate new IDs for all entries."

msgid "ui.control_bar.delete_button.tooltip"
msgstr "Delete Selected Entry"

msgid "ui.control_bar.save_button.tooltip"
msgstr "Save Current Changes"

msgid "ui.control_bar.reset_button.tooltip"
msgstr "Reset Data"

msgid "ui.control_bar.learn_link.text"
msgstr "Learn"

msgid "ui.control_bar.contribute_link.text"
msgstr "Contribute"

msgid "ui.control_bar.report_link.text"
msgstr "🐛 Report a bug!"

msgid "ui.entity_tree.entity_search.placeholder"
msgstr "Search…"

msgid "ui.property_editor.caption_label.text"
msgstr "Properties"

msgid "ui.property_editor.unselected_container_label.text"
msgstr "Create or select a category or item to see its properties here."

msgid "ui.property_editor.icon_label.text"
msgstr "Icon"

msgid "ui.property_editor.script_label.text"
msgstr "Script"

msgid "ui.property_editor.generate_id_class_label.text"
msgstr "Generate ID Class"

msgid "ui.property_editor.id_class_name_label.text"
msgstr "ID Class Name"

msgid "ui.property_editor.id_class_name_field.placeholder"
msgstr "SomeClassName"

msgid "ui.property_editor.property_default_name"
msgstr "Property"

msgid "ui.property_editor.property_settings.header_label.text"
msgstr "Properties"

msgid "ui.property_editor.property_settings.info_label.text"
msgstr "Property Settings"

msgid "ui.property_editor.property_settings.categories_only_label.text"
msgstr "Categories Only"

msgid "ui.property_editor.property_settings.category_filter_label.text"
msgstr "Category Filter"

msgid "ui.property_editor.property_settings.sort_list_label.text"
msgstr "Sort List"

msgid "ui.property_editor.property_settings.sort_list_menu.alphabetically"
msgstr "Alphabetically"

msgid "ui.property_editor.property_settings.sort_list_menu.as_is"
msgstr "As-is"
Binary file added addons/pandora/l10n/pt_BR.mo
Binary file not shown.
91 changes: 91 additions & 0 deletions addons/pandora/l10n/pt_BR.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
msgid ""
msgstr ""
"Project-Id-Version: Pandora\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: pt_BR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.3.2\n"

msgid "ui.control_bar.create_category_button.tooltip"
msgstr "Nova Categoria"

msgid "ui.control_bar.create_entity_button.tooltip"
msgstr "Nova Entidade"

msgid "ui.control_bar.regenerate_id_button.tooltip"
msgstr ""
"Gerar um novo ID para o registro selecionado.\n"
"Shift-click: Gera um novo ID para todos os registros."

msgid "ui.control_bar.delete_button.tooltip"
msgstr "Deletar Registro Selecionado"

msgid "ui.control_bar.save_button.tooltip"
msgstr "Salvar Mudanças"

msgid "ui.control_bar.reset_button.tooltip"
msgstr "Desfazer Mudanças"

msgid "ui.control_bar.learn_link.text"
msgstr "Aprenda"

msgid "ui.control_bar.contribute_link.text"
msgstr "Contribua"

msgid "ui.control_bar.report_link.text"
msgstr "🐛 Reporte um bug!"

msgid "ui.entity_tree.entity_search.placeholder"
msgstr "Buscar…"

msgid "ui.property_editor.caption_label.text"
msgstr "Propriedades"

msgid "ui.property_editor.unselected_container_label.text"
msgstr "Crie um selecione uma categoria para visualizar suas propriedades"

msgid "ui.property_editor.icon_label.text"
msgstr "Ícone"

msgid "ui.property_editor.script_label.text"
msgstr "Script"

msgid "ui.property_editor.generate_id_class_label.text"
msgstr "Gerar Classe de IDs"

msgid "ui.property_editor.id_class_name_label.text"
msgstr "Nome da Classe de IDs"

msgid "ui.property_editor.id_class_name_field.placeholder"
msgstr "NomeDaClasse"

#, fuzzy
msgid "ui.property_editor.property_default_name"
msgstr "Property"

msgid "ui.property_editor.property_settings.header_label.text"
msgstr "Propriedades"

msgid "ui.property_editor.property_settings.info_label.text"
msgstr "Configurações da Propriedade"

msgid "ui.property_editor.property_settings.categories_only_label.text"
msgstr "Somente para Categorias"

msgid "ui.property_editor.property_settings.category_filter_label.text"
msgstr "Filtrar Categoria"

msgid "ui.property_editor.property_settings.sort_list_label.text"
msgstr "Ordenar"

msgid "ui.property_editor.property_settings.sort_list_menu.alphabetically"
msgstr "Ordem Alfabética"

#, fuzzy
msgid "ui.property_editor.property_settings.sort_list_menu.as_is"
msgstr "As-is"
82 changes: 82 additions & 0 deletions addons/pandora/l10n/template.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
msgid ""
msgstr ""

"Project-Id-Version: Pandora\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8-bit\n"

msgid "ui.control_bar.create_category_button.tooltip"
msgstr ""

msgid "ui.control_bar.create_entity_button.tooltip"
msgstr ""

msgid "ui.control_bar.regenerate_id_button.tooltip"
msgstr ""

msgid "ui.control_bar.delete_button.tooltip"
msgstr ""

msgid "ui.control_bar.save_button.tooltip"
msgstr ""

msgid "ui.control_bar.reset_button.tooltip"
msgstr ""

msgid "ui.control_bar.learn_link.text"
msgstr ""

msgid "ui.control_bar.contribute_link.text"
msgstr ""

msgid "ui.control_bar.report_link.text"
msgstr ""

msgid "ui.entity_tree.entity_search.placeholder"
msgstr ""

msgid "ui.property_editor.caption_label.text"
msgstr ""

msgid "ui.property_editor.unselected_container_label.text"
msgstr ""

msgid "ui.property_editor.icon_label.text"
msgstr ""

msgid "ui.property_editor.script_label.text"
msgstr ""

msgid "ui.property_editor.generate_id_class_label.text"
msgstr ""

msgid "ui.property_editor.id_class_name_label.text"
msgstr ""

msgid "ui.property_editor.id_class_name_field.placeholder"
msgstr ""

msgid "ui.property_editor.property_default_name"
msgstr ""

msgid "ui.property_editor.property_settings.header_label.text"
msgstr ""

msgid "ui.property_editor.property_settings.info_label.text"
msgstr ""

msgid "ui.property_editor.property_settings.categories_only_label.text"
msgstr ""

msgid "ui.property_editor.property_settings.category_filter_label.text"
msgstr ""

msgid "ui.property_editor.property_settings.sort_list_label.text"
msgstr ""

msgid "ui.property_editor.property_settings.sort_list_menu.alphabetically"
msgstr ""

msgid "ui.property_editor.property_settings.sort_list_menu.as_is"
msgstr ""
8 changes: 8 additions & 0 deletions addons/pandora/l10n/translation_manager.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class_name TranslationManager extends Node

static func translate(string: String) -> String:
var language: String = TranslationServer.get_tool_locale()
var translations_path: String = "res://addons/pandora/l10n/%s.po" % language
var fallback_translations_path: String = "res://addons/pandora/l10n/en.po"
var translations: Translation = load(translations_path if FileAccess.file_exists(translations_path) else fallback_translations_path)
return translations.get_message(string)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ extends VBoxContainer
@onready var script_picker = %ScriptPicker
@onready var id_generation_enabled = %IdGenerationEnabled
@onready var class_name_edit = %ClassNameEdit
@onready var icon_label = %IconLabel
@onready var script_label = %ScriptLabel
@onready var id_generation_label = %IdGenerationLabel
@onready var id_class_name_label = %IdClassNameLabel

@onready var script_attribute = $ScriptAttribute
@onready var h_separator_2 = $HSeparator2
Expand Down Expand Up @@ -35,11 +39,18 @@ func init(entity:PandoraEntity) -> void:


func _ready() -> void:
_translate()
texture_picker.texture_changed.connect(_set_icon_path)
script_picker.script_path_changed.connect(_set_script_path)
id_generation_enabled.toggled.connect(_set_id_generation)
class_name_edit.text_changed.connect(_set_class_name)

func _translate():
icon_label.text = TranslationManager.translate("ui.property_editor.icon_label.text")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Godot 3 we could simply use the tr() function available in GDScript. Could we do that instead of this custom translation mamager? Godot 4 supports .pot files in the project settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a better look at this, I thought that was only applied to the project, not to addons.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I ran some tests here and as I suspected the TranslationServer is not available in the EditorPlugin so we can't inject POT files.

Some refs:
godotengine/godot-proposals#6885
godotengine/godot-proposals#1262

I actually took the idea of the custom tr manager from the reference you gave in #65:

https://github.com/nathanhoad/godot_dialogue_manager/blob/71c65332cc7b34eee9c517aaa36d645a79bfadb3/addons/dialogue_manager/constants.gd#L254

script_label.text = TranslationManager.translate("ui.property_editor.script_label.text")
id_generation_label.text = TranslationManager.translate("ui.property_editor.id_generation_label.text")
id_class_name_label.text = TranslationManager.translate("ui.property_editor.id_class_name_label.text")
class_name_edit.placeholder_text = TranslationManager.translate("ui.property_editor.id_class_name_field.placeholder")

func _set_icon_path(path:String) -> void:
_entity.set_icon_path(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ theme_override_constants/separation = 20
layout_mode = 2

[node name="IconLabel" type="Label" parent="IconAttribute"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text = "Icon"
Expand All @@ -33,7 +34,8 @@ layout_mode = 2
[node name="ScriptAttribute" type="HBoxContainer" parent="."]
layout_mode = 2

[node name="Label" type="Label" parent="ScriptAttribute"]
[node name="ScriptLabel" type="Label" parent="ScriptAttribute"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text = "Script"
Expand All @@ -49,7 +51,8 @@ theme_override_constants/separation = 20
[node name="IdGenerationAttribute" type="HBoxContainer" parent="."]
layout_mode = 2

[node name="Label" type="Label" parent="IdGenerationAttribute"]
[node name="IdGenerationLabel" type="Label" parent="IdGenerationAttribute"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text = "Generate ID Class"
Expand All @@ -63,6 +66,7 @@ unique_name_in_owner = true
layout_mode = 2

[node name="IdClassNameLabel" type="Label" parent="IdClassNameAttribute"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text = "ID Class Name"
Expand Down
16 changes: 16 additions & 0 deletions addons/pandora/ui/editor/pandora_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class_name PandoraEditor extends Control
@onready var entity_search: LineEdit = %EntitySearch
@onready var version = %Version
@onready var save_label = %SaveLabel
@onready var learn_link = %Learn
@onready var contribute_link = %Contribute
@onready var report_link = %ReportBug

@onready var data_content = %DataContent
@onready var error_content = %ErrorContent
Expand All @@ -24,6 +27,7 @@ var _load_error = false


func _ready() -> void:
_translate()
save_button.pressed.connect(_save)
tree.entity_selected.connect(_entity_selected)
tree.selection_cleared.connect(_selection_cleared)
Expand All @@ -50,6 +54,18 @@ func _ready() -> void:
Pandora.data_loaded.connect(self._data_load_success)
Pandora.data_loaded_failure.connect(self._data_load_failure)

func _translate() -> void:
create_category_button.tooltip_text = TranslationManager.translate("ui.control_bar.create_category_button.tooltip")
create_entity_button.tooltip_text = TranslationManager.translate("ui.control_bar.create_entity_button.tooltip")
delete_button.tooltip_text = TranslationManager.translate("ui.control_bar.delete_button.tooltip")
regenerate_id_button.tooltip_text = TranslationManager.translate("ui.control_bar.regenerate_id_button.tooltip")
save_button.tooltip_text = TranslationManager.translate("ui.control_bar.save_button.tooltip")
reset_button.tooltip_text = TranslationManager.translate("ui.control_bar.reset_button.tooltip")
learn_link.text = TranslationManager.translate("ui.control_bar.learn_link.text")
contribute_link.text = TranslationManager.translate("ui.control_bar.contribute_link.text")
report_link.text = TranslationManager.translate("ui.control_bar.report_link.text")
entity_search.placeholder_text = TranslationManager.translate("ui.entity_tree.entity_search.placeholder")


func reattempt_load_on_error() -> void:
if _load_error:
Expand Down
Loading