From 653e33638311c8b70122aa56242dbd3782bb9b6b Mon Sep 17 00:00:00 2001 From: Duncan Brown Date: Thu, 23 Jun 2022 05:27:04 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20handles=20translation=20keys=20that=20ha?= =?UTF-8?q?ve=20only=20one=20word=20(i.e.=20no=20spaces=E2=80=A6=20(#596)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: handles translation keys that have only one word (i.e. no spaces) in the actual dialogue * fix: fixes dialogue that starts with a space * fix: issues warning if translation key cannot be found (same for a voice file that can't be found) and uses the untranslated text in this case --- .../core-scripts/esc/types/esc_command.gd | 4 ++- .../game/scenes/dialogs/esc_dialog_player.gd | 31 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_command.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_command.gd index 5c95fe38..4c479542 100644 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_command.gd +++ b/addons/escoria-core/game/core-scripts/esc/types/esc_command.gd @@ -46,7 +46,9 @@ func _init(command_string): parameters.append( parameter ) - elif ":" in parameter and '"' in parameter: + elif ':"' in parameter and (parameter.ends_with(':"') or not parameter.ends_with('"')): + # The second clause in this helps to handle dialogue that starts with a space + # and also allowing single-word dialogue to be handled in a separate elif. quote_open = true parameter_values.append(parameter) elif not quote_open and parameter.begins_with('"'): diff --git a/addons/escoria-core/game/scenes/dialogs/esc_dialog_player.gd b/addons/escoria-core/game/scenes/dialogs/esc_dialog_player.gd index 3340c81d..ce496bee 100644 --- a/addons/escoria-core/game/scenes/dialogs/esc_dialog_player.gd +++ b/addons/escoria-core/game/scenes/dialogs/esc_dialog_player.gd @@ -30,9 +30,13 @@ var _dialog_manager: ESCDialogManager = null var _keytext_regex: RegEx = RegEx.new() +# Constructor +func _init() -> void: + _keytext_regex.compile(KEYTEXT_REGEX) + + # Register the dialog player and load the dialog resources func _ready(): - _keytext_regex.compile(KEYTEXT_REGEX) if !Engine.is_editor_hint(): escoria.dialog_player = self @@ -131,12 +135,33 @@ func say(character: String, type: String, text: String) -> void: var _speech_resource = _get_voice_file( matches.get_string("key") ) - if _speech_resource != "": + if _speech_resource == "": + escoria.logger.report_warnings( + "esc_dialog_player.gd:say", + [ + "Unable to find voice file with key '%s'." % matches.get_string("key") + ] + ) + else: ( escoria.object_manager.get_object(escoria.object_manager.SPEECH).node\ as ESCSpeechPlayer ).set_state(_speech_resource) - text = tr(matches.get_string("key")) + + var translated_text: String = tr(matches.get_string("key")) + + # Only update the text if the translated text was found; otherwise, raise + # a warning and use the original, untranslated text. + if translated_text == matches.get_string("key"): + escoria.logger.report_warnings( + "esc_dialog_player.gd:say", + [ + "Unable to find translation key '%s'. Using untranslated text." % matches.get_string("key") + ] + ) + text = matches.get_string("text") + else: + text = translated_text else: text = matches.get_string("text")