2023-07-27 11:39:38 -07:00
|
|
|
extends EditorTranslationParserPlugin
|
|
|
|
|
|
|
|
|
2024-04-08 14:42:12 -07:00
|
|
|
const DialogueConstants = preload("./constants.gd")
|
|
|
|
const DialogueSettings = preload("./settings.gd")
|
|
|
|
const DialogueManagerParseResult = preload("./components/parse_result.gd")
|
2023-07-27 11:39:38 -07:00
|
|
|
|
|
|
|
|
|
|
|
func _parse_file(path: String, msgids: Array, msgids_context_plural: Array) -> void:
|
|
|
|
var file: FileAccess = FileAccess.open(path, FileAccess.READ)
|
|
|
|
var text: String = file.get_as_text()
|
|
|
|
|
|
|
|
var data: DialogueManagerParseResult = DialogueManagerParser.parse_string(text, path)
|
|
|
|
var known_keys: PackedStringArray = PackedStringArray([])
|
|
|
|
|
2024-04-08 14:42:12 -07:00
|
|
|
# Add all character names if settings ask for it
|
|
|
|
if DialogueSettings.get_setting("export_characters_in_translation", true):
|
|
|
|
var character_names: PackedStringArray = data.character_names
|
|
|
|
for character_name in character_names:
|
|
|
|
if character_name in known_keys: continue
|
2023-07-27 11:39:38 -07:00
|
|
|
|
2024-04-08 14:42:12 -07:00
|
|
|
known_keys.append(character_name)
|
2023-07-27 11:39:38 -07:00
|
|
|
|
2024-04-08 14:42:12 -07:00
|
|
|
msgids_context_plural.append([character_name.replace('"', '\\"'), "dialogue", ""])
|
2023-07-27 11:39:38 -07:00
|
|
|
|
|
|
|
# Add all dialogue lines and responses
|
|
|
|
var dialogue: Dictionary = data.lines
|
|
|
|
for key in dialogue.keys():
|
|
|
|
var line: Dictionary = dialogue.get(key)
|
|
|
|
|
|
|
|
if not line.type in [DialogueConstants.TYPE_DIALOGUE, DialogueConstants.TYPE_RESPONSE]: continue
|
|
|
|
if line.translation_key in known_keys: continue
|
|
|
|
|
|
|
|
known_keys.append(line.translation_key)
|
|
|
|
|
|
|
|
if line.translation_key == "" or line.translation_key == line.text:
|
2024-04-08 14:42:12 -07:00
|
|
|
msgids_context_plural.append([line.text.replace('"', '\\"'), "", ""])
|
2023-07-27 11:39:38 -07:00
|
|
|
else:
|
2024-04-08 14:42:12 -07:00
|
|
|
msgids_context_plural.append([line.text.replace('"', '\\"'), line.translation_key.replace('"', '\\"'), ""])
|
2023-07-27 11:39:38 -07:00
|
|
|
|
|
|
|
|
|
|
|
func _get_recognized_extensions() -> PackedStringArray:
|
|
|
|
return ["dialogue"]
|