Skip to content

Commit

Permalink
Show used Locales in Test Locale Dropdown (#2108)
Browse files Browse the repository at this point in the history
* Limit Test Locale selection to used locales.

* Fix typo in constant name.

* Skip invalid locales.

* Use `Collect Translation` to gather unique locales.

* Add info on dropdown list to editor tooltip.
  • Loading branch information
CakeVR authored Feb 22, 2024
1 parent 8e42e69 commit 9bbdecd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 18 deletions.
37 changes: 35 additions & 2 deletions addons/dialogic/Editor/Settings/settings_translation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ const DEFAULT_TIMELINE_CSV_NAME := "dialogic_timeline_translations.csv"

const DEFAULT_GLOSSARY_CSV_NAME := "dialogic_glossary_translations.csv"

const _USED_LOCALES_SETTING := "dialogic/translation/locales"

## Contains translation changes that were made during the last update.

## Unique locales that will be set after updating the CSV files.
var _unique_locales := []

func _get_icon() -> Texture2D:
return get_theme_icon("Translation", "EditorIcons")
Expand Down Expand Up @@ -135,8 +139,18 @@ func get_locales(_filter: String) -> Dictionary:
var suggestions := {}
suggestions['Default'] = {'value':'', 'tooltip':"Will use the fallback locale set in the project settings."}
suggestions[TranslationServer.get_tool_locale()] = {'value':TranslationServer.get_tool_locale()}
for locale in TranslationServer.get_all_languages():
suggestions[locale] = {'value':locale, 'tooltip':TranslationServer.get_language_name(locale)}

var used_locales: Array = ProjectSettings.get_setting(_USED_LOCALES_SETTING, TranslationServer.get_all_languages())

for locale: String in used_locales:
var language_name := TranslationServer.get_language_name(locale)

# Invalid locales return an empty String.
if language_name.is_empty():
continue

suggestions[locale] = { 'value': locale, 'tooltip': language_name }

return suggestions


Expand Down Expand Up @@ -249,6 +263,7 @@ class CsvUpdateData:


func update_csv_files() -> void:
_unique_locales = []
var orig_locale: String = ProjectSettings.get_setting('dialogic/translation/original_locale', '').strip_edges()
var save_location_mode: SaveLocationModes = ProjectSettings.get_setting('dialogic/translation/save_mode', SaveLocationModes.NEXT_TO_TIMELINE)
var translation_mode: TranslationModes = ProjectSettings.get_setting('dialogic/translation/file_mode', TranslationModes.PER_PROJECT)
Expand Down Expand Up @@ -364,6 +379,8 @@ func update_csv_files() -> void:
}

%StatusMessage.text = status_message.format(status_message_args)
ProjectSettings.set_setting(_USED_LOCALES_SETTING, _unique_locales)
get_locales("")

## Iterates over all character resource files and creates or updates CSV files
## that contain the translations for character properties.
Expand Down Expand Up @@ -443,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 @@ -494,6 +516,8 @@ func delete_translations_files(translation_files: Array, csv_name: String) -> in
func erase_translations() -> void:
var files: PackedStringArray = ProjectSettings.get_setting('internationalization/locale/translations', [])
var translation_files := Array(files)
ProjectSettings.set_setting(_USED_LOCALES_SETTING, [])
get_locales("")

var deleted_csv_files := 0
var deleted_translation_files := 0
Expand Down Expand Up @@ -629,3 +653,12 @@ func _close_active_timeline() -> Resource:
func _silently_open_timeline(timeline_to_open: Resource) -> void:
if timeline_to_open != null:
settings_editor.editors_manager.edit_resource(timeline_to_open, true, true)


## Checks [param locale] for unique locales that have not been added
## to the [_unique_locales] array yet.
func _collect_locale(locale: String) -> void:
if _unique_locales.has(locale):
return

_unique_locales.append(locale)
34 changes: 18 additions & 16 deletions addons/dialogic/Editor/Settings/settings_translation.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[ext_resource type="PackedScene" uid="uid://dpwhshre1n4t6" path="res://addons/dialogic/Editor/Events/Fields/field_options_dynamic.tscn" id="3_dq4j2"]
[ext_resource type="PackedScene" uid="uid://7mvxuaulctcq" path="res://addons/dialogic/Editor/Events/Fields/field_file.tscn" id="4_kvsma"]

[sub_resource type="Image" id="Image_6uwds"]
[sub_resource type="Image" id="Image_g2hic"]
data = {
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
"format": "RGBA8",
Expand All @@ -14,8 +14,8 @@ data = {
"width": 16
}

[sub_resource type="ImageTexture" id="ImageTexture_5qvwl"]
image = SubResource("Image_6uwds")
[sub_resource type="ImageTexture" id="ImageTexture_xbph7"]
image = SubResource("Image_g2hic")

[node name="Translations" type="VBoxContainer"]
anchors_preset = 15
Expand Down Expand Up @@ -73,9 +73,11 @@ text = "Testing locale"
layout_mode = 2
tooltip_text = "Change this locale to test your game in a different language (only in-editor).
Equivalent of the testing local project setting. "
texture = SubResource("ImageTexture_5qvwl")
texture = SubResource("ImageTexture_xbph7")
hint_text = "Change this locale to test your game in a different language (only in-editor).
Equivalent of the testing local project setting. "
Equivalent of the testing local project setting.
Update dropdown list via \"Collect Translation\"."

[node name="TestingLocale" parent="HBox/Testing/VBox3" instance=ExtResource("3_dq4j2")]
unique_name_in_owner = true
Expand Down Expand Up @@ -111,7 +113,7 @@ text = "Default locale"
[node name="HintTooltip" parent="TranslationSettings/VBoxContainer/Grid/VBox" instance=ExtResource("2_k2lou")]
layout_mode = 2
tooltip_text = "The locale of the language your timelines are written in."
texture = SubResource("ImageTexture_5qvwl")
texture = SubResource("ImageTexture_xbph7")
hint_text = "The locale of the language your timelines are written in."

[node name="OrigLocale" parent="TranslationSettings/VBoxContainer/Grid" instance=ExtResource("3_dq4j2")]
Expand All @@ -129,7 +131,7 @@ text = "Translation folder"
layout_mode = 2
tooltip_text = "Choose a folder to let Dialogic save CSV files in.
Also used when saving \"Inside Translation Folder\""
texture = SubResource("ImageTexture_5qvwl")
texture = SubResource("ImageTexture_xbph7")
hint_text = "Choose a folder to let Dialogic save CSV files in.
Also used when saving \"Inside Translation Folder\""

Expand Down Expand Up @@ -157,7 +159,7 @@ For example, 10 timelines will be combined into 1 CSV file.
For example, 10 timelines will result in 10 CSV files.
The \"Per File\" option utilises \"Output location\", in contrast, the \"Per Type\" will always use the Translation folder."
texture = SubResource("ImageTexture_5qvwl")
texture = SubResource("ImageTexture_xbph7")
hint_text = "Decides how many CSV files will be created.
\"Per Type\": Uses one CSV file for each type of resource: Timelines, characters, and glossaries.
Expand Down Expand Up @@ -195,7 +197,7 @@ tooltip_text = "Decides where to save the generated CSV files.
This button requires the \"Per File\" Output mode.
A resource type can be: Timelines, characters, and glossaries."
texture = SubResource("ImageTexture_5qvwl")
texture = SubResource("ImageTexture_xbph7")
hint_text = "Decides where to save the generated CSV files.
\"Inside Translation Folder\": Uses the \"Translation folder\".
Expand Down Expand Up @@ -232,7 +234,7 @@ layout_mode = 2
tooltip_text = "Adds an empty line into per-project CSVs to differentiate between sections.
For example, when a new glossary item or timeline starts, an empty line will be added."
texture = SubResource("ImageTexture_5qvwl")
texture = SubResource("ImageTexture_xbph7")
hint_text = "Adds an empty line into per-project CSVs to differentiate between sections.
For example, when a new glossary item or timeline starts, an empty line will be added."
Expand Down Expand Up @@ -265,7 +267,7 @@ unique_name_in_owner = true
layout_mode = 2
disabled = true
text = "Update CSV files"
icon = SubResource("ImageTexture_5qvwl")
icon = SubResource("ImageTexture_xbph7")

[node name="HintTooltip5" parent="TranslationSettings/VBoxContainer2/Actions" instance=ExtResource("2_k2lou")]
layout_mode = 2
Expand All @@ -274,7 +276,7 @@ tooltip_text = "This button will scan all timelines and generate or update their
A Dialogic CSV file will be prefixed with \"dialogic_\".
This action will be disabled if the \"Translation folder\" is missing or has an invalid path."
texture = SubResource("ImageTexture_5qvwl")
texture = SubResource("ImageTexture_xbph7")
hint_text = "This button will scan all timelines and generate or update their CSV files.
A Dialogic CSV file will be prefixed with \"dialogic_\".
Expand All @@ -285,14 +287,14 @@ This action will be disabled if the \"Translation folder\" is missing or has an
unique_name_in_owner = true
layout_mode = 2
text = "Collect translations"
icon = SubResource("ImageTexture_5qvwl")
icon = SubResource("ImageTexture_xbph7")

[node name="HintTooltip6" parent="TranslationSettings/VBoxContainer2/Actions" instance=ExtResource("2_k2lou")]
layout_mode = 2
tooltip_text = "Godot imports CSV files as \".translation\" files.
This buttons adds them to \"Project Settings -> Localization\".
"
texture = SubResource("ImageTexture_5qvwl")
texture = SubResource("ImageTexture_xbph7")
hint_text = "Godot imports CSV files as \".translation\" files.
This buttons adds them to \"Project Settings -> Localization\".
"
Expand All @@ -309,7 +311,7 @@ layout_mode = 2
unique_name_in_owner = true
layout_mode = 2
text = "Remove translations"
icon = SubResource("ImageTexture_5qvwl")
icon = SubResource("ImageTexture_xbph7")

[node name="HintTooltip7" parent="TranslationSettings/VBoxContainer2/Actions" instance=ExtResource("2_k2lou")]
layout_mode = 2
Expand All @@ -319,7 +321,7 @@ It will try to delete any \".csv\" and \".translation\" files that are related t
CSV and translation files prefixed with \"dialogic_\" are treated as Dialogic-related.
Removes translation IDs (eg. #id:33) from timelines and characters."
texture = SubResource("ImageTexture_5qvwl")
texture = SubResource("ImageTexture_xbph7")
hint_text = "Be very careful with this button!
It will try to delete any \".csv\" and \".translation\" files that are related to Dialogic.
Expand Down

0 comments on commit 9bbdecd

Please sign in to comment.