Skip to content

Commit

Permalink
Add TranslationUtils (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
MewPurPur committed Apr 14, 2024
1 parent 3cf4f32 commit 0fb9d6a
Show file tree
Hide file tree
Showing 16 changed files with 325 additions and 41 deletions.
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ timers/tooltip_delay_sec=0.4

[input]

optimize_svg={
optimize={
"deadzone": 0.5,
"events": []
}
Expand Down
2 changes: 1 addition & 1 deletion src/GlobalSettings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 41 additions & 0 deletions src/TranslationUtils.gd
Original file line number Diff line number Diff line change
@@ -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
7 changes: 0 additions & 7 deletions src/Utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ui_elements/path_command_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/ui_elements/path_command_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/ui_parts/code_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")))
Expand Down
26 changes: 6 additions & 20 deletions src/ui_parts/settings_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion src/ui_parts/settings_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 43 additions & 1 deletion translations/GodSVG.pot
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ msgstr ""
msgid "Rasterized SVG"
msgstr ""

msgid "Show rasterized SVG"
msgstr ""

msgid "Enable Snapping"
msgstr ""

Expand All @@ -100,7 +103,7 @@ msgstr ""
msgid "Reset to default"
msgstr ""

msgid "Copy All Text"
msgid "Copy all text"
msgstr ""

msgid "Clear SVG"
Expand Down Expand Up @@ -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 ""
44 changes: 43 additions & 1 deletion translations/bg.po
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ msgstr "Покажи дръжките"
msgid "Rasterized SVG"
msgstr "Растеризирай SVG"

msgid "Show rasterized SVG"
msgstr "Покажи растеризиран SVG"

msgid "Enable Snapping"
msgstr "Включи захващането"

Expand All @@ -103,7 +106,7 @@ msgstr "Размер на захващането"
msgid "Reset to default"
msgstr "Възстанови началната стойност"

msgid "Copy All Text"
msgid "Copy all text"
msgstr "Копирай всичкия текст"

msgid "Clear SVG"
Expand Down Expand Up @@ -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 "Кратка кубична крива на Безие до"
48 changes: 47 additions & 1 deletion translations/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
Expand Down Expand Up @@ -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"
Loading

0 comments on commit 0fb9d6a

Please sign in to comment.