Skip to content

Commit

Permalink
Added additional information on automatic translation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tetragramat committed May 5, 2024
1 parent cfd1df2 commit 16882f7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
5 changes: 5 additions & 0 deletions build/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion project/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions project/scenes/screens/Translation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ 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
_start_button.disabled = true
_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())

Expand All @@ -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)
6 changes: 5 additions & 1 deletion project/scenes/screens/Translation.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"

Expand Down Expand Up @@ -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"]
13 changes: 9 additions & 4 deletions project/scenes/translator/Google.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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 = {}
Expand Down

0 comments on commit 16882f7

Please sign in to comment.