From fd58010a0fff71488ea8cfb4079f200d798c2dd4 Mon Sep 17 00:00:00 2001 From: Cake Date: Thu, 22 Feb 2024 10:15:04 +0100 Subject: [PATCH] Use `Collect Translation` to gather unique locales. --- addons/dialogic/Editor/Settings/csv_file.gd | 14 ------------ .../Editor/Settings/settings_translation.gd | 22 +++++++++---------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/addons/dialogic/Editor/Settings/csv_file.gd b/addons/dialogic/Editor/Settings/csv_file.gd index 5cb635e4b..28db80e5b 100644 --- a/addons/dialogic/Editor/Settings/csv_file.gd +++ b/addons/dialogic/Editor/Settings/csv_file.gd @@ -32,9 +32,6 @@ var new_rows: int = 0 ## a per-project file. var add_separator: bool = false -## All locales found after the [method update_csv_file_on_disk] method is called. -var locales: Array = [] - enum PropertyType { String = 0, Array = 1, @@ -326,22 +323,15 @@ func update_csv_file_on_disk() -> void: # Clear the current CSV file. file = FileAccess.open(used_file_path, FileAccess.WRITE) - var is_first_line := true - for line in lines: var row_key := line[0] - # In case there might be translations for this line already, # add them at the end again (orig locale text is replaced). if row_key in old_lines: var old_line: PackedStringArray = old_lines[row_key] var updated_line: PackedStringArray = line + old_line.slice(2) - if is_first_line: - locales = updated_line.slice(1) - is_first_line = false - var line_columns: int = updated_line.size() var line_columns_to_add := column_count - line_columns @@ -360,10 +350,6 @@ func update_csv_file_on_disk() -> void: for _i in range(line_columns_to_add): line.append("") - if is_first_line: - locales = line.slice(1) - is_first_line = false - file.store_csv_line(line) new_rows += 1 diff --git a/addons/dialogic/Editor/Settings/settings_translation.gd b/addons/dialogic/Editor/Settings/settings_translation.gd index e30374b57..5e40a6585 100644 --- a/addons/dialogic/Editor/Settings/settings_translation.gd +++ b/addons/dialogic/Editor/Settings/settings_translation.gd @@ -234,13 +234,11 @@ func _handle_glossary_translation( TranslationModes.PER_TIMELINE: glossary_csv.update_csv_file_on_disk() - _collect_locales(glossary_csv.locales) glossary_csv = null # If a Per-Project glossary is still open, we need to save it. if glossary_csv != null: glossary_csv.update_csv_file_on_disk() - _collect_locales(glossary_csv.locales) glossary_csv = null @@ -334,7 +332,6 @@ func update_csv_files() -> void: if translation_mode == TranslationModes.PER_TIMELINE: csv_file.update_csv_file_on_disk() - _collect_locales(csv_file.locales) csv_data.new_events += csv_file.new_rows csv_data.updated_events += csv_file.updated_rows @@ -356,7 +353,6 @@ func update_csv_files() -> void: if translation_mode == TranslationModes.PER_PROJECT: csv_per_project.update_csv_file_on_disk() - _collect_locales(csv_per_project.locales) _silently_open_timeline(current_timeline) @@ -418,7 +414,6 @@ func _handle_character_names( character_name_csv.collect_lines_from_characters(all_characters) character_name_csv.update_csv_file_on_disk() - _collect_locales(character_name_csv.locales) func collect_translations() -> void: @@ -465,6 +460,11 @@ func collect_translations() -> void: if not file_path in all_translation_files: all_translation_files.append(file_path) + var path_without_suffix := file_path.trim_suffix('.translation') + var path_parts := path_without_suffix.split(".") + var locale_part := path_parts[-1] + _collect_locale(locale_part) + var valid_translation_files := PackedStringArray(all_translation_files) ProjectSettings.set_setting('internationalization/locale/translations', valid_translation_files) @@ -655,12 +655,10 @@ func _silently_open_timeline(timeline_to_open: Resource) -> void: settings_editor.editors_manager.edit_resource(timeline_to_open, true, true) -## Checks [param locales] for unique locales that have not been added +## Checks [param locale] for unique locales that have not been added ## to the [_unique_locales] array yet. -func _collect_locales(locales: Array) -> void: - - for locale: String in locales: - if _unique_locales.has(locale): - continue +func _collect_locale(locale: String) -> void: + if _unique_locales.has(locale): + return - _unique_locales.append(locale) \ No newline at end of file + _unique_locales.append(locale) \ No newline at end of file