Skip to content

Commit

Permalink
Use Collect Translation to gather unique locales.
Browse files Browse the repository at this point in the history
  • Loading branch information
CakeVR committed Feb 22, 2024
1 parent 91ed3b6 commit fd58010
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
14 changes: 0 additions & 14 deletions addons/dialogic/Editor/Settings/csv_file.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
22 changes: 10 additions & 12 deletions addons/dialogic/Editor/Settings/settings_translation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
_unique_locales.append(locale)

0 comments on commit fd58010

Please sign in to comment.