Skip to content

Commit

Permalink
Change translation to be on a script basis
Browse files Browse the repository at this point in the history
  • Loading branch information
MewPurPur committed May 5, 2024
1 parent 9c5a895 commit d0982d7
Show file tree
Hide file tree
Showing 57 changed files with 2,341 additions and 2,054 deletions.
11 changes: 6 additions & 5 deletions export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter="web-build/*, *.md, visual/editor_only/*"
exclude_filter="web-build/*, *.md, godot_only/*"
export_path=""
encryption_include_filters=""
encryption_exclude_filters=""
Expand Down Expand Up @@ -70,7 +70,7 @@ dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter="web-build/*, *.md, *.ico, visual/editor_only/*"
exclude_filter="web-build/*, *.md, *.ico, godot_only/*"
export_path=""
encryption_include_filters=""
encryption_exclude_filters=""
Expand Down Expand Up @@ -110,7 +110,7 @@ dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter="web-build/*, *.md, *.ico, visual/editor_only/*"
exclude_filter="web-build/*, *.md, *.ico, godot_only/*"
export_path="../GodSVG meta/GodSVG exports/GodSVG_macos.zip"
encryption_include_filters=""
encryption_exclude_filters=""
Expand Down Expand Up @@ -216,7 +216,7 @@ custom_features=""
export_filter="exclude"
export_files=PackedStringArray()
include_filter=""
exclude_filter="web-build/*, *.md, *.ico, visual/editor_only/*"
exclude_filter="web-build/*, *.md, *.ico, godot_only/*"
export_path=""
encryption_include_filters=""
encryption_exclude_filters=""
Expand Down Expand Up @@ -254,7 +254,7 @@ dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter="web-build/*, *.md, *.ico, visual/editor_only/*"
exclude_filter="web-build/*, *.md, *.ico, godot_only/*"
export_path=""
encryption_include_filters=""
encryption_exclude_filters=""
Expand Down Expand Up @@ -381,6 +381,7 @@ permissions/mount_format_filesystems=false
permissions/mount_unmount_filesystems=false
permissions/nfc=false
permissions/persistent_activity=false
permissions/post_notifications=false
permissions/process_outgoing_calls=false
permissions/read_calendar=false
permissions/read_call_log=false
Expand Down
5 changes: 5 additions & 0 deletions godot_only/Scripts.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class_name Scripts extends RefCounted

# Simple solution to running some scripts by just running the project.
static func update_translations() -> void:
load("res://godot_only/scripts/update_translations.gd").new()
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://cvgj1ej5gr81o"
path="res://.godot/imported/BetterLineEdit.svg-a2d2a62bdb304b4891d0634d0d2e4c63.ctex"
path="res://.godot/imported/BetterLineEdit.svg-33c8d74a467cb95950aa75271d901c24.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

[deps]

source_file="res://visual/godot_only/BetterLineEdit.svg"
dest_files=["res://.godot/imported/BetterLineEdit.svg-a2d2a62bdb304b4891d0634d0d2e4c63.ctex"]
source_file="res://godot_only/icons/BetterLineEdit.svg"
dest_files=["res://.godot/imported/BetterLineEdit.svg-33c8d74a467cb95950aa75271d901c24.ctex"]

[params]

Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://bxdad4w7o7u7n"
path="res://.godot/imported/BetterTextEdit.svg-8d29d288cfe6e11d561b58da21e3e545.ctex"
path="res://.godot/imported/BetterTextEdit.svg-f06d86b1b5bf325dabaff5aebeb88925.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

[deps]

source_file="res://visual/godot_only/BetterTextEdit.svg"
dest_files=["res://.godot/imported/BetterTextEdit.svg-8d29d288cfe6e11d561b58da21e3e545.ctex"]
source_file="res://godot_only/icons/BetterTextEdit.svg"
dest_files=["res://.godot/imported/BetterTextEdit.svg-f06d86b1b5bf325dabaff5aebeb88925.ctex"]

[params]

Expand Down
72 changes: 72 additions & 0 deletions godot_only/scripts/update_translations.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
extends RefCounted

# Don't have a better solution than handling all these different whitespace variations...
const delimiters = {
'TranslationServer.translate("': '")',
'TranslationServer.translate(\n\t\t\t"': '")',
'TranslationServer.translate(\n\t\t\t\t"': '")',
'TranslationServer.translate(\n\t\t\t\t\t"': '")',
"TranslationServer.translate('": "')",
'TranslationServer.translate("""': '""")',
'TranslationServer.translate_plural("': '")',
"TranslationServer.translate_plural('": "')",
'TranslationServer.translate_plural("""': '""")',
}

var strings: PackedStringArray = PackedStringArray(["translation-credits"])

func _init() -> void:
search_directory(ProjectSettings.globalize_path("src"))
update_translations()


func search_directory(dir: String) -> void:
for dir_name in DirAccess.get_directories_at(dir):
search_directory(dir.path_join(dir_name))

for file_name in DirAccess.get_files_at(dir):
var file_text := FileAccess.get_file_as_string(dir.path_join(file_name))
for start_delim: String in delimiters:
var end_delim: String = delimiters[start_delim]
var cursor := 0
while true:
cursor = file_text.find(start_delim, cursor)
if cursor == -1:
break

var string_start := cursor + start_delim.length()
cursor = file_text.find(end_delim, cursor)
var string := file_text.substr(string_start, cursor - string_start)
if not string in strings:
strings.append(string)

func update_translations() -> void:
var location := ProjectSettings.globalize_path("translations/GodSVG.pot")
DirAccess.make_dir_recursive_absolute(location)
var fa := FileAccess.open(location, FileAccess.WRITE)

fa.store_string("#, fuzzy\n")
fa.store_string("msgid \"\"\n")
fa.store_string("msgstr \"\"\n")
fa.store_string("\"Project-Id-Version: GodSVG\\n\"\n")
fa.store_string("\"POT-Creation-Date: \\n\"\n")
fa.store_string("\"PO-Revision-Date: \\n\"\n")
fa.store_string("\"Last-Translator: \\n\"\n")
fa.store_string("\"Language-Team: \\n\"\n")
fa.store_string("\"MIME-Version: 1.0\\n\"\n")
fa.store_string("\"Content-Type: text/plain; charset=UTF-8\\n\"\n")
fa.store_string("\"Content-Transfer-Encoding: 8bit\\n\"\n")
fa.store_string("\"X-Generator: Poedit 3.4.2\\n\"\n")

for string in strings:
fa.store_string('\nmsgid "%s"\nmsgstr ""\n' % string)
fa = null

var files := DirAccess.get_files_at(ProjectSettings.globalize_path("translations"))
for file in files:
if file.get_extension() != "po":
continue

var args := PackedStringArray(["--update", "--quiet", "--verbose", "--backup=off",
ProjectSettings.globalize_path("translations").path_join(file), location])
OS.execute("msgmerge", args)
2 changes: 1 addition & 1 deletion src/FileUtils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static func apply_svg_from_path(path: String) -> int:
if not error.is_empty():
var alert_dialog := AlertDialog.instantiate()
HandlerGUI.add_overlay(alert_dialog)
alert_dialog.setup(error, TranslationServer.translate("Alert!"), 280.0)
alert_dialog.setup(error)
return ERR_FILE_CANT_OPEN

var svg_text := svg_file.get_as_text()
Expand Down
14 changes: 6 additions & 8 deletions src/HandlerGUI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,14 @@ func web_load_svg() -> void:
warning_panel.set_svg(file_data)
HandlerGUI.add_overlay(warning_panel)
else:
var error := ""
if extension.is_empty():
error = TranslationServer.translate(
"The file extension is empty. Only \"svg\" files are supported.")
else:
error = TranslationServer.translate(
"\"{passed_extension}\" is a unsupported file extension. Only \"svg\" files are supported.").format({"passed_extension": extension})
var alert_dialog := AlertDialog.instantiate()
HandlerGUI.add_overlay(alert_dialog)
alert_dialog.setup(error, TranslationServer.translate("Alert!"), 280.0)
if extension.is_empty():
alert_dialog.setup(TranslationServer.translate(
"The file extension is empty. Only \"svg\" files are supported."))
else:
alert_dialog.setup(TranslationServer.translate(
"\"{passed_extension}\" is a unsupported file extension. Only \"svg\" files are supported.").format({"passed_extension": extension}))


const web_glue = """var fileData;
Expand Down
40 changes: 40 additions & 0 deletions src/TranslationUtils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,46 @@ static func get_shortcut_description(action_name: String) -> String:
"view_show_handles": return TranslationServer.translate("Show handles")
"view_rasterized_svg": return TranslationServer.translate("Show rasterized SVG")
"debug": return TranslationServer.translate("View debug information")
"move_relative": return "%s (%s)" %\
[get_command_char_description("M"), TranslationServer.translate("Relative")]
"move_absolute": return "%s (%s)" %\
[get_command_char_description("M"), TranslationServer.translate("Absolute")]
"line_relative": return "%s (%s)" %\
[get_command_char_description("L"), TranslationServer.translate("Relative")]
"line_absolute": return "%s (%s)" %\
[get_command_char_description("L"), TranslationServer.translate("Absolute")]
"horizontal_line_relative": return "%s (%s)" %\
[get_command_char_description("H"), TranslationServer.translate("Relative")]
"horizontal_line_absolute": return "%s (%s)" %\
[get_command_char_description("H"), TranslationServer.translate("Absolute")]
"vertical_line_relative": return "%s (%s)" %\
[get_command_char_description("V"), TranslationServer.translate("Relative")]
"vertical_line_absolute": return "%s (%s)" %\
[get_command_char_description("V"), TranslationServer.translate("Absolute")]
"close_path_relative": return "%s (%s)" %\
[get_command_char_description("Z"), TranslationServer.translate("Relative")]
"close_path_absolute": return "%s (%s)" %\
[get_command_char_description("Z"), TranslationServer.translate("Absolute")]
"elliptical_arc_relative": return "%s (%s)" %\
[get_command_char_description("A"), TranslationServer.translate("Relative")]
"elliptical_arc_absolute": return "%s (%s)" %\
[get_command_char_description("A"), TranslationServer.translate("Absolute")]
"quadratic_bezier_relative": return "%s (%s)" %\
[get_command_char_description("Q"), TranslationServer.translate("Relative")]
"quadratic_bezier_absolute": return "%s (%s)" %\
[get_command_char_description("Q"), TranslationServer.translate("Absolute")]
"shorthand_quadratic_bezier_relative": return "%s (%s)" %\
[get_command_char_description("T"), TranslationServer.translate("Relative")]
"shorthand_quadratic_bezier_absolute": return "%s (%s)" %\
[get_command_char_description("T"), TranslationServer.translate("Absolute")]
"cubic_bezier_relative": return "%s (%s)" %\
[get_command_char_description("C"), TranslationServer.translate("Relative")]
"cubic_bezier_absolute": return "%s (%s)" %\
[get_command_char_description("C"), TranslationServer.translate("Absolute")]
"shorthand_cubic_bezier_relative": return "%s (%s)" %\
[get_command_char_description("S"), TranslationServer.translate("Relative")]
"shorthand_cubic_bezier_absolute": return "%s (%s)" %\
[get_command_char_description("S"), TranslationServer.translate("Absolute")]
_: return action_name


Expand Down
6 changes: 4 additions & 2 deletions src/parsers/SVGParser.gd
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ class ParseResult extends RefCounted:

static func get_error_string(parse_error: ParseError) -> String:
match parse_error:
ParseError.ERR_NOT_SVG: return "Doesn’t describe an SVG."
ParseError.ERR_IMPROPER_NESTING: return "Improper nesting."
ParseError.ERR_NOT_SVG:
return TranslationServer.translate("Doesn’t describe an SVG.")
ParseError.ERR_IMPROPER_NESTING:
return TranslationServer.translate("Improper nesting.")
_: return ""

static func text_to_svg(text: String) -> ParseResult:
Expand Down
2 changes: 1 addition & 1 deletion src/ui_elements/BetterLineEdit.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@icon("res://visual/godot_only/BetterLineEdit.svg")
@icon("res://godot_only/icons/BetterLineEdit.svg")
class_name BetterLineEdit extends LineEdit
## A LineEdit with a few tweaks to make it nicer to use.

Expand Down
24 changes: 0 additions & 24 deletions src/ui_elements/BetterTabContainer.gd

This file was deleted.

2 changes: 1 addition & 1 deletion src/ui_elements/BetterTextEdit.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@icon("res://visual/godot_only/BetterTextEdit.svg")
@icon("res://godot_only/icons/BetterTextEdit.svg")
class_name BetterTextEdit extends TextEdit
## A TextEdit with some improvements.

Expand Down
11 changes: 11 additions & 0 deletions src/ui_elements/configure_color_popup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,22 @@ signal color_deletion_requested
var color_palette: ColorPalette
var idx: int


func _notification(what: int) -> void:
if what == Utils.CustomNotification.LANGUAGE_CHANGED:
update_translation()

func _ready() -> void:
set_label_text(color_palette.color_names[idx])
color_edit.value = color_palette.colors[idx]
update_translation()


func update_translation() -> void:
%LabelContainer/EditButton.tooltip_text =\
TranslationServer.translate("Edit color name")
$ConfigureContainer/BottomContainer/DeleteButton.tooltip_text =\
TranslationServer.translate("Delete color")
func _on_edit_button_pressed() -> void:
color_name_edit.text = color_palette.color_names[idx]
color_name_edit.show()
Expand Down
2 changes: 0 additions & 2 deletions src/ui_elements/configure_color_popup.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ horizontal_alignment = 1

[node name="EditButton" type="Button" parent="ConfigureContainer/TopContainer/LabelContainer"]
layout_mode = 2
tooltip_text = "Edit color name"
focus_mode = 0
mouse_default_cursor_shape = 2
theme_type_variation = &"FlatButton"
Expand Down Expand Up @@ -65,7 +64,6 @@ enable_palettes = false

[node name="DeleteButton" type="Button" parent="ConfigureContainer/BottomContainer"]
layout_mode = 2
tooltip_text = "Delete color"
focus_mode = 0
mouse_default_cursor_shape = 2
theme_type_variation = &"IconButton"
Expand Down
6 changes: 6 additions & 0 deletions src/ui_elements/palette_config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ var currently_edited_idx := -1
@onready var colors_container: HFlowContainer = %MainContainer/ColorsContainer
@onready var action_button: Button = $HBoxContainer/ActionButton

func _notification(what: int) -> void:
if what == Utils.CustomNotification.LANGUAGE_CHANGED:
%MainContainer/HBoxContainer/EditButton.tooltip_text = TranslationServer.translate(
"Edit palette name")


# Used to setup a palette for this element.
func assign_palette(palette: ColorPalette) -> void:
current_palette = palette
Expand Down
1 change: 0 additions & 1 deletion src/ui_elements/palette_config.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ script = ExtResource("2_coqnx")
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
tooltip_text = "Edit palette name"
focus_mode = 0
mouse_default_cursor_shape = 2
theme_type_variation = &"FlatButton"
Expand Down
8 changes: 8 additions & 0 deletions src/ui_elements/pathdata_field.gd
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func set_value(new_value: String, update_type := Utils.UpdateType.REGULAR) -> vo
attribute.set_value(new_value)


func _notification(what: int) -> void:
if what == Utils.CustomNotification.LANGUAGE_CHANGED:
update_translation()

func set_attribute(new_attribute: AttributePath) -> void:
attribute = new_attribute
set_value(attribute.get_value())
Expand All @@ -64,7 +68,11 @@ func set_attribute(new_attribute: AttributePath) -> void:
commands_container.draw.connect(commands_draw)
Indications.hover_changed.connect(_on_selections_or_hover_changed)
Indications.selection_changed.connect(_on_selections_or_hover_changed)
update_translation()


func update_translation() -> void:
line_edit.placeholder_text = TranslationServer.translate("No path data")

func _on_line_edit_focus_entered() -> void:
focused.emit()
Expand Down
Loading

0 comments on commit d0982d7

Please sign in to comment.