Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jowan-Spooner committed Apr 26, 2024
1 parent fca746f commit b184b8b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
13 changes: 5 additions & 8 deletions addons/dialogic/Editor/Settings/settings_translation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ func _handle_glossary_translation(
translation_mode: TranslationModes,
translation_folder_path: String,
orig_locale: String) -> void:
var glossary_csv_path := ""

var glossary_csv: DialogicCsvFile = null
var glossary_paths: Array = ProjectSettings.get_setting('dialogic/glossary/glossary_files', [])
Expand All @@ -207,6 +206,7 @@ func _handle_glossary_translation(
var file_name := path_parts[-1]
csv_name = "dialogic_" + file_name + '_translation.csv'

var glossary_csv_path := ""
# Get glossary CSV file path.
match save_location_mode:
SaveLocationModes.INSIDE_TRANSLATION_FOLDER:
Expand All @@ -228,13 +228,10 @@ func _handle_glossary_translation(
glossary_csv.add_translation_keys_to_glossary(glossary)
ResourceSaver.save(glossary)

match translation_mode:
TranslationModes.PER_PROJECT:
pass

TranslationModes.PER_TIMELINE:
glossary_csv.update_csv_file_on_disk()
glossary_csv = null
#If per-file mode is used, save this csv and begin a new one
if translation_mode == TranslationModes.PER_TIMELINE:
glossary_csv.update_csv_file_on_disk()
glossary_csv = null

# If a Per-Project glossary is still open, we need to save it.
if glossary_csv != null:
Expand Down
23 changes: 7 additions & 16 deletions addons/dialogic/Modules/Glossary/glossary_resource.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ const PRIVATE_PROPERTY_PREFIX := "_"
@export var _translation_keys: Dictionary = {}


func __get_property_list() -> Array:
return []


## Removes an entry and all its aliases (alternative property) from
## the glossary.
Expand Down Expand Up @@ -225,6 +222,8 @@ func get_set_regex_option(entry_key: String) -> String:
return regex_option


#region ADD AND CLEAR TRANSLATION KEYS

## This is automatically called, no need to use this.
func add_translation_id() -> String:
_translation_id = DialogicUtil.get_next_translation_id()
Expand Down Expand Up @@ -259,6 +258,10 @@ func clear_translation_keys() -> void:

_translation_keys.clear()

#endregion


#region GET AND SET TRANSLATION IDS AND KEYS

## Returns a key used to reference this glossary in the translation CSV file.
##
Expand All @@ -282,19 +285,6 @@ func get_property_translation_key(entry_key: String, property: String) -> String
return glossary_csv_key


## Returns the matching translation key for the given [param word].
## This key can be used via [method tr] to get the translation.
##
## Time complexity: O(1)
## Uses an internal dictionary to find the translation key.
## This dictionary is generated when the glossary is translated.
## See [member _translation_keys].
func get_word_translation_key(word: String) -> String:
if _translation_keys.has(word):
return _translation_keys[word]

return ""


## Returns the translation key prefix for this glossary.
## The resulting format will look like this: Glossary/a2/
Expand Down Expand Up @@ -347,3 +337,4 @@ func get_set_glossary_translation_id() -> String:

return _translation_id

#endregion
14 changes: 6 additions & 8 deletions addons/dialogic/Modules/Glossary/subsystem_glossary.gd
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ func add_glossary(path:String) -> void:
## Iterates over all glossaries and returns the first one that matches the
## [param entry_key].
##
## Returns null if none of the glossaries has an entry with that key.
## If translation is enabled, uses the [param entry_key] as well to check
## [member _translation_keys].
##
## Runtime complexity:
## O(n), where n is the number of glossaries.
func find_glossary(entry_key: String) -> DialogicGlossary:
Expand Down Expand Up @@ -150,9 +146,9 @@ func get_entry(entry_key: String) -> Dictionary:

var tr_base := translation_key.substr(0, last_slash)

result.title = _try_translate(tr_base, "title", entry)
result.text = _try_translate(tr_base, "text", entry)
result.extra = _try_translate(tr_base, "extra", entry)
result.title = translate(tr_base, "title", entry)
result.text = translate(tr_base, "text", entry)
result.extra = translate(tr_base, "extra", entry)
else:
result.title = entry.get("title", "")
result.text = entry.get("text", "")
Expand All @@ -166,7 +162,9 @@ func get_entry(entry_key: String) -> Dictionary:
return result


func _try_translate(tr_base: String, property: StringName, fallback_entry: Dictionary) -> String:

## Tries to translate the property with the given
func translate(tr_base: String, property: StringName, fallback_entry: Dictionary) -> String:
var tr_key := tr_base.path_join(property)
var tr_value := tr(tr_key)

Expand Down

0 comments on commit b184b8b

Please sign in to comment.