From 16882f7fc207e2ac27dc6f65199eaf0db0d11774 Mon Sep 17 00:00:00 2001 From: Tetragramat Date: Sun, 5 May 2024 17:00:42 +0200 Subject: [PATCH] Added additional information on automatic translation --- build/README.txt | 5 +++++ project/project.godot | 2 +- project/scenes/screens/Translation.gd | 10 +++++++--- project/scenes/screens/Translation.tscn | 6 +++++- project/scenes/translator/Google.gd | 13 +++++++++---- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/build/README.txt b/build/README.txt index a04b838..0864b71 100644 --- a/build/README.txt +++ b/build/README.txt @@ -3,6 +3,11 @@ LonaRPG MTL # Changelog +Update 9 + +* Refactored Google translation to be more generic and allow more translation services than just Google translate +* Automatic translation is faster and displays additional information about translation process + Update 8 * Added version checker, on start tool will check if there is new version diff --git a/project/project.godot b/project/project.godot index 6f722f1..893a13f 100644 --- a/project/project.godot +++ b/project/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="LonaRPG MTL" -config/version="1.0.8" +config/version="1.0.9" run/main_scene="res://Root.tscn" config/features=PackedStringArray("4.2") run/low_processor_mode=true diff --git a/project/scenes/screens/Translation.gd b/project/scenes/screens/Translation.gd index 9f4bc27..838a8d3 100644 --- a/project/scenes/screens/Translation.gd +++ b/project/scenes/screens/Translation.gd @@ -25,7 +25,7 @@ func _on_begin_button_pressed(): _extracted_data = _translator.get_untranslated() if _extracted_data.is_empty(): - _label.add_text(str("\nThere is nothing to translate.\n")) + _label.append_text(str("[color=green]There is nothing to translate.[/color]\n\n")) return _translator_option_button.disabled = true @@ -33,6 +33,8 @@ func _on_begin_button_pressed(): _progress_bar.max_value = _extracted_data.size() _progress_bar.value = 0; + _label.append_text("Starting translation of %d lines from %s to %s.\n\n" % [_extracted_data.size(), "zh-CN", _data.get_language()]) + var node: Google = _translator_option_button.get_selected_metadata() node.translate(_extracted_data.keys(), "zh-CN", _data.get_language()) @@ -44,12 +46,14 @@ func _on_google_translation_progress(translations: Dictionary): _progress_bar.value = _translated_data.size() _translator.apply_translations(translations) - _label.add_text(str("Progress... Translated %d lines.\n" % translations.size())) + _label.append_text("Progress... Translated %d lines.\n\n" % translations.size()) if _translated_data.size() == _extracted_data.size(): - _label.add_text(str("\nTranslation is complete. Start LonaRPG and switch language to MTL.\n\n")) + _label.append_text(str("[color=green]Translation is complete. Start LonaRPG and switch language to MTL.[/color]\n\n")) _start_button.disabled = false _translator_option_button.disabled = false _translated_data.clear() _extracted_data.clear() +func _on_google_execution_failure(reason: String): + _label.append_text("[color=red]%s[/color]\n\n" % reason) diff --git a/project/scenes/screens/Translation.tscn b/project/scenes/screens/Translation.tscn index 426cae3..ffcefd7 100644 --- a/project/scenes/screens/Translation.tscn +++ b/project/scenes/screens/Translation.tscn @@ -39,7 +39,10 @@ theme_override_constants/separation = 20 [node name="RichTextLabel" type="RichTextLabel" parent="Panel/MarginContainer/VBoxContainer"] layout_mode = 2 size_flags_vertical = 3 -text = "Select translation service and press start to begin automatic translation. +bbcode_enabled = true +text = "Cached translations were automatically applied. + +Select translation service and press start to begin automatic translation. " @@ -77,4 +80,5 @@ text = "Start" [connection signal="item_selected" from="Panel/MarginContainer/VBoxContainer/TranslatorOptionButton" to="." method="_on_translator_option_button_item_selected"] [connection signal="pressed" from="Panel/MarginContainer/VBoxContainer/HBoxContainer/CancelButton" to="." method="_on_cancel_button_pressed"] [connection signal="pressed" from="Panel/MarginContainer/VBoxContainer/HBoxContainer/BeginButton" to="." method="_on_begin_button_pressed"] +[connection signal="execution_failure" from="Google" to="." method="_on_google_execution_failure"] [connection signal="translation_progress" from="Google" to="." method="_on_google_translation_progress"] diff --git a/project/scenes/translator/Google.gd b/project/scenes/translator/Google.gd index 27ef709..8507fca 100644 --- a/project/scenes/translator/Google.gd +++ b/project/scenes/translator/Google.gd @@ -4,6 +4,7 @@ class_name Google const CHARACTER_LIMIT = 5000 signal translation_progress(translations: Dictionary) +signal execution_failure(reason: String) @onready var _http_request: HTTPRequest = $HTTPRequest @onready var _timer: Timer = $Timer @@ -51,19 +52,22 @@ func execute() -> void: var response = _http_request.request(url, [], HTTPClient.METHOD_GET) if response != OK: + execution_failure.emit("Request failed %d" % response) printerr("Request failed %d" % response) _timer.start() func _on_http_request_request_completed(result: HTTPRequest.Result, response_code: HTTPClient.ResponseCode, headers: PackedStringArray, body: PackedByteArray) -> void: - print_debug("HTTPRequest to Google api.\nResult %d\nCode %d\nHeaders %s\nBody %s" % [result, response_code, headers, body.get_string_from_utf8()]) + print_debug("HTTP Request to Google api.\nResult %d\nCode %d\nHeaders %s\nBody %s" % [result, response_code, headers, body.get_string_from_utf8()]) if result != HTTPRequest.RESULT_SUCCESS: - printerr("HTTPRequest to Google api failed.\nResult %d\nCode %d\nHeaders %s\nBody %s" % [result, response_code, headers, body.get_string_from_utf8()]) + execution_failure.emit("HTTP Request to Google api failed.[table=2][cell]Result[/cell][cell]%d[/cell][cell]Code[/cell][cell]%d[/cell][cell]Headers[/cell][cell]%s[/cell][cell]Content[/cell][cell]%s[/cell][/table]" % [result, response_code, headers, body.get_string_from_utf8()]) + printerr("HTTP Request to Google api failed.\nResult %d\nCode %d\nHeaders %s\nBody %s" % [result, response_code, headers, body.get_string_from_utf8()]) return if response_code != HTTPClient.RESPONSE_OK: - printerr("HTTPRequest to Google api failed.\nResult %d\nCode %d\nHeaders %s\nBody %s" % [result, response_code, headers, body.get_string_from_utf8()]) + execution_failure.emit("HTTP Request to Google api failed.[table=2][cell]Result[/cell][cell]%d[/cell][cell]Code[/cell][cell]%d[/cell][cell]Headers[/cell][cell]%s[/cell][cell]Content[/cell][cell]%s[/cell][/table]" % [result, response_code, headers, body.get_string_from_utf8()]) + printerr("HTTP Request to Google api failed.\nResult %d\nCode %d\nHeaders %s\nBody %s" % [result, response_code, headers, body.get_string_from_utf8()]) return var json = JSON.new() @@ -86,7 +90,8 @@ func _on_http_request_request_completed(result: HTTPRequest.Result, response_cod original_lines.append(item) if original_lines.size() != translated_lines.size(): - printerr("Amount of original %d and translated %d lines does not match!" % [original_lines.size(), translated_lines.size()]) + execution_failure.emit("Amount of original %d and translated %d lines in the response does not match!" % [original_lines.size(), translated_lines.size()]) + printerr("Amount of original %d and translated %d lines in the response does not match!" % [original_lines.size(), translated_lines.size()]) return var translations: Dictionary = {}