From 0209a131ed3ab10b87982138d9faa8c81d4a92fe Mon Sep 17 00:00:00 2001 From: Mew Pur Pur <85438892+MewPurPur@users.noreply.github.com> Date: Sun, 14 Apr 2024 03:44:40 +0300 Subject: [PATCH] Add TranslationUtils (#654) --- project.godot | 2 +- src/GlobalSettings.gd | 2 +- src/TranslationUtils.gd | 41 ++++++++++++++++++++++ src/Utils.gd | 7 ---- src/{ => ui_elements}/OverlayRect.gd | 0 src/ui_elements/path_command_button.gd | 2 +- src/ui_elements/path_command_editor.gd | 4 +-- src/ui_parts/code_editor.gd | 4 +-- src/ui_parts/settings_menu.gd | 26 ++++---------- src/ui_parts/settings_menu.tscn | 2 +- translations/GodSVG.pot | 44 ++++++++++++++++++++++- translations/bg.po | 44 ++++++++++++++++++++++- translations/de.po | 48 +++++++++++++++++++++++++- translations/en.po | 44 ++++++++++++++++++++++- translations/ru.po | 48 +++++++++++++++++++++++++- translations/uk.po | 48 +++++++++++++++++++++++++- 16 files changed, 325 insertions(+), 41 deletions(-) create mode 100644 src/TranslationUtils.gd rename src/{ => ui_elements}/OverlayRect.gd (100%) diff --git a/project.godot b/project.godot index 5bead86b..93e77514 100644 --- a/project.godot +++ b/project.godot @@ -55,7 +55,7 @@ timers/tooltip_delay_sec=0.4 [input] -optimize_svg={ +optimize={ "deadzone": 0.5, "events": [] } diff --git a/src/GlobalSettings.gd b/src/GlobalSettings.gd index 7b90b8ed..9e93f4a4 100644 --- a/src/GlobalSettings.gd +++ b/src/GlobalSettings.gd @@ -64,7 +64,7 @@ const default_config = { var default_input_events := {} # Dictionary{String: Array[InputEvent]} const configurable_keybinds = { - "file": ["import", "export", "save", "optimize_svg", "copy_svg_text", "clear_svg", + "file": ["import", "export", "save", "optimize", "copy_svg_text", "clear_svg", "clear_file_path", "reset_svg"], "edit": ["undo", "redo", "select_all", "duplicate", "move_up", "move_down", "delete"], "view": ["zoom_in", "zoom_out", "zoom_reset", "view_show_grid", "view_show_handles", diff --git a/src/TranslationUtils.gd b/src/TranslationUtils.gd new file mode 100644 index 00000000..602e1da9 --- /dev/null +++ b/src/TranslationUtils.gd @@ -0,0 +1,41 @@ +class_name TranslationUtils extends RefCounted + +func get_shortcut_description(action_name: String) -> String: + match action_name: + "export": return tr("Export") + "import": return tr("Import") + "save": return tr("Save SVG") + "optimize": return tr("Optimize") + "copy_svg_text": return tr("Copy all text") + "reset_svg": return tr("Reset SVG") + "clear_svg": return tr("Clear SVG") + "clear_file_path": return tr("Clear saving path") + "undo": return tr("Undo") + "redo": return tr("Redo") + "select_all": return tr("Select all tags") + "duplicate": return tr("Duplicate the selected tags") + "delete": return tr("Delete the selection") + "move_up": return tr("Move the selected tags up") + "move_down": return tr("Move the selected tags down") + "zoom_in": return tr("Zoom in") + "zoom_out": return tr("Zoom out") + "zoom_reset": return tr("Zoom reset") + "view_show_grid": return tr("Show grid") + "view_show_handles": return tr("Show handles") + "view_rasterize_svg": return tr("Show rasterized SVG") + _: return action_name + + +func get_command_char_description(command_char: String) -> String: + match command_char: + "M", "m": return tr("Move to") + "L", "l": return tr("Line to") + "H", "h": return tr("Horizontal Line to") + "V", "v": return tr("Vertical Line to") + "Z", "z": return tr("Close Path") + "A", "a": return tr("Elliptical Arc to") + "Q", "q": return tr("Quadratic Bezier to") + "T", "t": return tr("Shorthand Quadratic Bezier to") + "C", "c": return tr("Cubic Bezier to") + "S", "s": return tr("Shorthand Cubic Bezier to") + _: return command_char diff --git a/src/Utils.gd b/src/Utils.gd index 2b64972e..3d3f762c 100644 --- a/src/Utils.gd +++ b/src/Utils.gd @@ -10,13 +10,6 @@ enum CustomNotification { HANDLE_COLORS_CHANGED = 305, } -const path_command_char_dict = { - "M": "Move to", "L": "Line to", "H": "Horizontal Line to", "V": "Vertical Line to", - "Z": "Close Path", "A": "Elliptical Arc to", "Q": "Quadratic Bezier to", - "T": "Shorthand Quadratic Bezier to", "C": "Cubic Bezier to", - "S": "Shorthand Cubic Bezier to" -} - # Enum with values to be used for set_value() of attribute editors. # REGULAR means that the attribute will update if the new value is different. # INTERMEDIATE and FINAL cause the attribute update to have the corresponding sync mode. diff --git a/src/OverlayRect.gd b/src/ui_elements/OverlayRect.gd similarity index 100% rename from src/OverlayRect.gd rename to src/ui_elements/OverlayRect.gd diff --git a/src/ui_elements/path_command_button.gd b/src/ui_elements/path_command_button.gd index bc1a3360..10f558d2 100644 --- a/src/ui_elements/path_command_button.gd +++ b/src/ui_elements/path_command_button.gd @@ -23,7 +23,7 @@ func update_text() -> void: rtl.add_text(":") rtl.pop() rtl.add_text(" ") - rtl.add_text(Utils.path_command_char_dict[command_char.to_upper()]) + rtl.add_text(TranslationUtils.new().get_command_char_description(command_char)) func set_invalid(new_state := true) -> void: if new_state: diff --git a/src/ui_elements/path_command_editor.gd b/src/ui_elements/path_command_editor.gd index a3f33359..c8ff18a8 100644 --- a/src/ui_elements/path_command_editor.gd +++ b/src/ui_elements/path_command_editor.gd @@ -248,13 +248,13 @@ func activate() -> void: relative_button.add_theme_color_override("font_color", Color(1, 1, 1)) if Utils.is_string_upper(cmd_char): relative_button.tooltip_text = "%s (%s)" %\ - [Utils.path_command_char_dict[cmd_char.to_upper()], tr("Absolute")] + [TranslationUtils.new().get_command_char_description(cmd_char), tr("Absolute")] relative_button.add_theme_stylebox_override("normal", absolute_button_normal) relative_button.add_theme_stylebox_override("hover", absolute_button_hovered) relative_button.add_theme_stylebox_override("pressed", absolute_button_pressed) else: relative_button.tooltip_text = "%s (%s)" %\ - [Utils.path_command_char_dict[cmd_char.to_upper()], tr("Relative")] + [TranslationUtils.new().get_command_char_description(cmd_char), tr("Relative")] relative_button.add_theme_stylebox_override("normal", relative_button_normal) relative_button.add_theme_stylebox_override("hover", relative_button_hovered) relative_button.add_theme_stylebox_override("pressed", relative_button_pressed) diff --git a/src/ui_parts/code_editor.gd b/src/ui_parts/code_editor.gd index ef4dfe29..5b481259 100644 --- a/src/ui_parts/code_editor.gd +++ b/src/ui_parts/code_editor.gd @@ -47,7 +47,7 @@ func _unhandled_input(input_event: InputEvent) -> void: _on_copy_button_pressed() elif input_event.is_action_pressed("clear_svg"): clear_svg() - elif input_event.is_action_pressed("optimize_svg"): + elif input_event.is_action_pressed("optimize"): _on_optimize_button_pressed() elif input_event.is_action_pressed("clear_file_path"): clear_file_path() @@ -194,7 +194,7 @@ func _on_file_button_pressed() -> void: func _on_options_button_pressed() -> void: var btn_array: Array[Button] = [] - btn_array.append(Utils.create_btn(tr("Copy All Text"), _on_copy_button_pressed, + btn_array.append(Utils.create_btn(tr("Copy all text"), _on_copy_button_pressed, false, load("res://visual/icons/Copy.svg"))) btn_array.append(Utils.create_btn(tr("Clear SVG"), clear_svg, SVG.text == SVG.DEFAULT, load("res://visual/icons/Clear.svg"))) diff --git a/src/ui_parts/settings_menu.gd b/src/ui_parts/settings_menu.gd index 165338a7..a52d22a9 100644 --- a/src/ui_parts/settings_menu.gd +++ b/src/ui_parts/settings_menu.gd @@ -22,22 +22,6 @@ const SettingColor = preload("res://src/ui_elements/setting_color.gd") var focused_content := 0 -var shortcut_descriptions := { # Dictionary{String: String} - "export": tr("Export"), - "import": tr("Import"), - "save": tr("Save"), - "undo": tr("Undo"), - "redo": tr("Redo"), - "select_all": tr("Select all tags"), - "duplicate": tr("Duplicate the selected tags"), - "delete": tr("Delete the selection"), - "move_up": tr("Move the selected tags up"), - "move_down": tr("Move the selected tags down"), - "zoom_in": tr("Zoom in"), - "zoom_out": tr("Zoom out"), - "zoom_reset": tr("Zoom reset"), -} - func _ready() -> void: update_language_button() setup_setting_labels() @@ -232,21 +216,23 @@ func setup_shortcuts_tab() -> void: func show_keybinds(category: String): for child in shortcut_container.get_children(): child.queue_free() + + var translation_utils := TranslationUtils.new() for action in GlobalSettings.configurable_keybinds[category]: var keybind_config := ShortcutConfigWidget.instantiate() shortcut_container.add_child(keybind_config) - keybind_config.label.text = shortcut_descriptions[action] if\ - action in shortcut_descriptions else action + keybind_config.label.text = translation_utils.get_shortcut_description(action) keybind_config.setup(action) func show_tool_keybinds() -> void: for child in shortcut_container.get_children(): child.queue_free() + + var translation_utils := TranslationUtils.new() for action in GlobalSettings.unconfigurable_keybinds: var keybind_config := ShortcutShowcaseWidget.instantiate() shortcut_container.add_child(keybind_config) - keybind_config.label.text = shortcut_descriptions[action] if\ - action in shortcut_descriptions else action + keybind_config.label.text = translation_utils.get_shortcut_description(action) keybind_config.setup(action) diff --git a/src/ui_parts/settings_menu.tscn b/src/ui_parts/settings_menu.tscn index 10ff779d..342fcee6 100644 --- a/src/ui_parts/settings_menu.tscn +++ b/src/ui_parts/settings_menu.tscn @@ -9,7 +9,7 @@ [sub_resource type="ButtonGroup" id="ButtonGroup_f7wyd"] [node name="SettingsMenu" type="PanelContainer"] -custom_minimum_size = Vector2(568, 360) +custom_minimum_size = Vector2(580, 360) anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 diff --git a/translations/GodSVG.pot b/translations/GodSVG.pot index ca853bc0..959d527f 100644 --- a/translations/GodSVG.pot +++ b/translations/GodSVG.pot @@ -91,6 +91,9 @@ msgstr "" msgid "Rasterized SVG" msgstr "" +msgid "Show rasterized SVG" +msgstr "" + msgid "Enable Snapping" msgstr "" @@ -100,7 +103,7 @@ msgstr "" msgid "Reset to default" msgstr "" -msgid "Copy All Text" +msgid "Copy all text" msgstr "" msgid "Clear SVG" @@ -497,3 +500,42 @@ msgstr "" msgid "Search color" msgstr "" + +msgid "File" +msgstr "" + +msgid "View" +msgstr "" + +msgid "Tool" +msgstr "" + +msgid "Move to" +msgstr "" + +msgid "Line to" +msgstr "" + +msgid "Horizontal Line to" +msgstr "" + +msgid "Vertical Line to" +msgstr "" + +msgid "Close Path" +msgstr "" + +msgid "Elliptical Arc to" +msgstr "" + +msgid "Quadratic Bezier to" +msgstr "" + +msgid "Shorthand Quadratic Bezier to" +msgstr "" + +msgid "Cubic Bezier to" +msgstr "" + +msgid "Shorthand Cubic Bezier to" +msgstr "" diff --git a/translations/bg.po b/translations/bg.po index 94cad233..6c20ab80 100644 --- a/translations/bg.po +++ b/translations/bg.po @@ -94,6 +94,9 @@ msgstr "Покажи дръжките" msgid "Rasterized SVG" msgstr "Растеризирай SVG" +msgid "Show rasterized SVG" +msgstr "Покажи растеризиран SVG" + msgid "Enable Snapping" msgstr "Включи захващането" @@ -103,7 +106,7 @@ msgstr "Размер на захващането" msgid "Reset to default" msgstr "Възстанови началната стойност" -msgid "Copy All Text" +msgid "Copy all text" msgstr "Копирай всичкия текст" msgid "Clear SVG" @@ -509,3 +512,42 @@ msgstr "Винаги активно." msgid "Search color" msgstr "Търсене на цвят" + +msgid "File" +msgstr "Файл" + +msgid "View" +msgstr "Гледка" + +msgid "Tool" +msgstr "Инструмент" + +msgid "Move to" +msgstr "Премести до" + +msgid "Line to" +msgstr "Отсечка до" + +msgid "Horizontal Line to" +msgstr "Хоризонтална отсечка до" + +msgid "Vertical Line to" +msgstr "Вертикална отсечка до" + +msgid "Close Path" +msgstr "Затвори пътеката" + +msgid "Elliptical Arc to" +msgstr "Елиптична дъга до" + +msgid "Quadratic Bezier to" +msgstr "Квадратна крива на Безие до" + +msgid "Shorthand Quadratic Bezier to" +msgstr "Кратка квадратна крива на Безие до" + +msgid "Cubic Bezier to" +msgstr "Кубична крива на Безие до" + +msgid "Shorthand Cubic Bezier to" +msgstr "Кратка кубична крива на Безие до" diff --git a/translations/de.po b/translations/de.po index bc2998e9..65c5cf17 100644 --- a/translations/de.po +++ b/translations/de.po @@ -95,6 +95,10 @@ msgstr "Griffe anzeigen" msgid "Rasterized SVG" msgstr "SVG rasterisieren" +#, fuzzy +msgid "Show rasterized SVG" +msgstr "SVG rasterisieren" + msgid "Enable Snapping" msgstr "Einrasten aktivieren" @@ -104,7 +108,8 @@ msgstr "Einrastgröße" msgid "Reset to default" msgstr "Zurücksetzen" -msgid "Copy All Text" +#, fuzzy +msgid "Copy all text" msgstr "Text kopieren" msgid "Clear SVG" @@ -524,6 +529,47 @@ msgstr "Immer aktiv." msgid "Search color" msgstr "Farbe suchen" +msgid "File" +msgstr "" + +msgid "View" +msgstr "" + +msgid "Tool" +msgstr "" + +#, fuzzy +msgid "Move to" +msgstr "Nach unten" + +msgid "Line to" +msgstr "" + +msgid "Horizontal Line to" +msgstr "" + +msgid "Vertical Line to" +msgstr "" + +#, fuzzy +msgid "Close Path" +msgstr "Schließen" + +msgid "Elliptical Arc to" +msgstr "" + +msgid "Quadratic Bezier to" +msgstr "" + +msgid "Shorthand Quadratic Bezier to" +msgstr "" + +msgid "Cubic Bezier to" +msgstr "" + +msgid "Shorthand Cubic Bezier to" +msgstr "" + #, fuzzy #~ msgid "Clear association" #~ msgstr "Dateizuordnung entfernen" diff --git a/translations/en.po b/translations/en.po index 651cb6ea..bc60aa01 100644 --- a/translations/en.po +++ b/translations/en.po @@ -92,6 +92,9 @@ msgstr "" msgid "Rasterized SVG" msgstr "" +msgid "Show rasterized SVG" +msgstr "" + msgid "Enable Snapping" msgstr "" @@ -101,7 +104,7 @@ msgstr "" msgid "Reset to default" msgstr "" -msgid "Copy All Text" +msgid "Copy all text" msgstr "" msgid "Clear SVG" @@ -500,3 +503,42 @@ msgstr "" msgid "Search color" msgstr "" + +msgid "File" +msgstr "" + +msgid "View" +msgstr "" + +msgid "Tool" +msgstr "" + +msgid "Move to" +msgstr "" + +msgid "Line to" +msgstr "" + +msgid "Horizontal Line to" +msgstr "" + +msgid "Vertical Line to" +msgstr "" + +msgid "Close Path" +msgstr "" + +msgid "Elliptical Arc to" +msgstr "" + +msgid "Quadratic Bezier to" +msgstr "" + +msgid "Shorthand Quadratic Bezier to" +msgstr "" + +msgid "Cubic Bezier to" +msgstr "" + +msgid "Shorthand Cubic Bezier to" +msgstr "" diff --git a/translations/ru.po b/translations/ru.po index 22ba4874..3373b460 100644 --- a/translations/ru.po +++ b/translations/ru.po @@ -97,6 +97,10 @@ msgstr "Показать ручки редактирования" msgid "Rasterized SVG" msgstr "Растеризовать SVG" +#, fuzzy +msgid "Show rasterized SVG" +msgstr "Растеризовать SVG" + msgid "Enable Snapping" msgstr "Включить привязку" @@ -106,7 +110,8 @@ msgstr "Размер привязки" msgid "Reset to default" msgstr "Восстановить значение по умолчанию" -msgid "Copy All Text" +#, fuzzy +msgid "Copy all text" msgstr "Скопировать весь текст" msgid "Clear SVG" @@ -520,6 +525,47 @@ msgstr "Всегда активно." msgid "Search color" msgstr "Искать цвет" +msgid "File" +msgstr "" + +msgid "View" +msgstr "" + +msgid "Tool" +msgstr "" + +#, fuzzy +msgid "Move to" +msgstr "Подвинуть вниз" + +msgid "Line to" +msgstr "" + +msgid "Horizontal Line to" +msgstr "" + +msgid "Vertical Line to" +msgstr "" + +#, fuzzy +msgid "Close Path" +msgstr "Закрыть" + +msgid "Elliptical Arc to" +msgstr "" + +msgid "Quadratic Bezier to" +msgstr "" + +msgid "Shorthand Quadratic Bezier to" +msgstr "" + +msgid "Cubic Bezier to" +msgstr "" + +msgid "Shorthand Cubic Bezier to" +msgstr "" + #, fuzzy #~ msgid "Clear association" #~ msgstr "Удалить" diff --git a/translations/uk.po b/translations/uk.po index 92493760..faf08bce 100644 --- a/translations/uk.po +++ b/translations/uk.po @@ -98,6 +98,10 @@ msgstr "Показати ручки редагування" msgid "Rasterized SVG" msgstr "Растеризувати SVG" +#, fuzzy +msgid "Show rasterized SVG" +msgstr "Растеризувати SVG" + msgid "Enable Snapping" msgstr "Активувати прилипання" @@ -107,7 +111,8 @@ msgstr "Розмір прилипання" msgid "Reset to default" msgstr "Скинути значення до замовчування" -msgid "Copy All Text" +#, fuzzy +msgid "Copy all text" msgstr "Скопіювати весь текст" msgid "Clear SVG" @@ -521,6 +526,47 @@ msgstr "Завжди активно." msgid "Search color" msgstr "Шукати колір" +msgid "File" +msgstr "" + +msgid "View" +msgstr "" + +msgid "Tool" +msgstr "" + +#, fuzzy +msgid "Move to" +msgstr "Пересунути вниз" + +msgid "Line to" +msgstr "" + +msgid "Horizontal Line to" +msgstr "" + +msgid "Vertical Line to" +msgstr "" + +#, fuzzy +msgid "Close Path" +msgstr "Закрити" + +msgid "Elliptical Arc to" +msgstr "" + +msgid "Quadratic Bezier to" +msgstr "" + +msgid "Shorthand Quadratic Bezier to" +msgstr "" + +msgid "Cubic Bezier to" +msgstr "" + +msgid "Shorthand Cubic Bezier to" +msgstr "" + #, fuzzy #~ msgid "Clear association" #~ msgstr "Видалити асоціацію"