diff --git a/addons/localization_editor/scenes/auto_translate/google/LocalizationAutoTranslateGoogle.gd b/addons/localization_editor/scenes/auto_translate/google/LocalizationAutoTranslateGoogle.gd index 3ceb8bc..8f451ad 100644 --- a/addons/localization_editor/scenes/auto_translate/google/LocalizationAutoTranslateGoogle.gd +++ b/addons/localization_editor/scenes/auto_translate/google/LocalizationAutoTranslateGoogle.gd @@ -4,6 +4,10 @@ extends MarginContainer var _data: LocalizationData +var _data_keys: Array = [] +var _queries_count: int = 0 +var _from_code: String +var _to_code: String @onready var _from_language_ui = $Panel/VBox/HBox/FromLanguage @onready var _to_language_ui = $Panel/VBox/HBox/ToLanguage @@ -49,22 +53,32 @@ func _check_translate_ui(_item: DropdownItem) -> void: _translate_ui.set_disabled(_from_language_ui.get_selected_index() == -1 or _to_language_ui.get_selected_index() == -1) func _on_translate_pressed() -> void: - var from_language_code = _from_language_ui.get_selected_value() - var to_language_code = _to_language_ui.get_selected_value() - _translate(from_language_code, to_language_code) + _from_code = _from_language_ui.get_selected_value() + _to_code = _to_language_ui.get_selected_value() + _translate() -func _translate(from_code: String, to_code: String) -> void: +func _translate() -> void: _translate_ui.disabled = true _progress_ui.max_value = _data.keys().size() - if not _data.locales().has(to_code): - _data.add_locale(to_code, false) - for key in _data.keys(): - var from_translation = _data.translation_by_locale(key, from_code) - var to_translation = _data.translation_by_locale(key, to_code) - if from_translation != null and not from_translation.value.length() <= 0 and (to_translation.value == null or to_translation.value.length() <= 0): + if not _data.locales().has(_to_code): + _data.add_locale(_to_code, false) + + _data_keys = _data.keys().duplicate() + _create_requests() + +func _create_requests() -> void: + var space = IP.RESOLVER_MAX_QUERIES - _queries_count + for index in range(space): + if _data_keys.size() <= 0: + return + var from_translation = _data.translation_by_locale(_data_keys[0], _from_code) + var to_translation = _data.translation_by_locale(_data_keys[0], _to_code) + if from_translation != null and not from_translation.value.is_empty() and (to_translation.value == null or to_translation.value.is_empty()): _create_request(from_translation, to_translation) else: _add_progress() + _data_keys.remove_at(0) + _queries_count += 1 func _create_request(from_translation, to_translation) -> void: var url = _create_url(from_translation, to_translation) @@ -89,6 +103,8 @@ func _http_request_completed(result, response_code, headers, body, http_request, to_translation.value = json.get_data()[0][0][0] _add_progress() remove_child(http_request) + _queries_count -= 1 + _create_requests() func _add_progress() -> void: _progress_ui.value = _progress_ui.value + 1