diff options
| author | Kiisu_Master <142301391+Kiisu-Master@users.noreply.github.com> | 2024-03-08 17:40:35 +0200 |
|---|---|---|
| committer | Kiisu_Master <142301391+Kiisu-Master@users.noreply.github.com> | 2024-03-08 20:43:19 +0200 |
| commit | 8446084a20da03ac18d8fae19c12a700af1b3135 (patch) | |
| tree | 2ab8609027b19e751e0def0cd307fe27512a1271 | |
| parent | aef11a14274f6f9e74ad91ead1d7c07ea1dd7f5f (diff) | |
| download | redot-engine-8446084a20da03ac18d8fae19c12a700af1b3135.tar.gz | |
Fix packed scene translation parser missing strings.
| -rw-r--r-- | editor/plugins/packed_scene_translation_parser_plugin.cpp | 47 | ||||
| -rw-r--r-- | editor/plugins/packed_scene_translation_parser_plugin.h | 1 |
2 files changed, 34 insertions, 14 deletions
diff --git a/editor/plugins/packed_scene_translation_parser_plugin.cpp b/editor/plugins/packed_scene_translation_parser_plugin.cpp index 04d4c6d779..86df57c469 100644 --- a/editor/plugins/packed_scene_translation_parser_plugin.cpp +++ b/editor/plugins/packed_scene_translation_parser_plugin.cpp @@ -58,6 +58,15 @@ Error PackedSceneEditorTranslationParserPlugin::parse_file(const String &p_path, String node_type = state->get_node_type(i); String parent_path = state->get_node_path(i, true); + // Handle instanced scenes. + if (node_type.is_empty()) { + Ref<PackedScene> instance = state->get_node_instance(i); + if (instance.is_valid()) { + Ref<SceneState> _state = instance->get_state(); + node_type = _state->get_node_type(0); + } + } + // Find the `auto_translate_mode` property. bool auto_translating = true; bool auto_translate_mode_found = false; @@ -118,7 +127,8 @@ Error PackedSceneEditorTranslationParserPlugin::parse_file(const String &p_path, for (int j = 0; j < state->get_node_property_count(i); j++) { String property_name = state->get_node_property_name(i, j); - if (!lookup_properties.has(property_name) || (exception_list.has(node_type) && exception_list[node_type].has(property_name))) { + + if (!match_property(property_name, node_type)) { continue; } @@ -134,15 +144,6 @@ Error PackedSceneEditorTranslationParserPlugin::parse_file(const String &p_path, parsed_strings.append_array(temp); r_ids_ctx_plural->append_array(ids_context_plural); } - } else if ((node_type == "MenuButton" || node_type == "OptionButton") && property_name == "items") { - Vector<String> str_values = property_value; - int incr_value = node_type == "MenuButton" ? PopupMenu::ITEM_PROPERTY_SIZE : OptionButton::ITEM_PROPERTY_SIZE; - for (int k = 0; k < str_values.size(); k += incr_value) { - String desc = str_values[k].get_slice(";", 1).strip_edges(); - if (!desc.is_empty()) { - parsed_strings.push_back(desc); - } - } } else if (node_type == "FileDialog" && property_name == "filters") { // Extract FileDialog's filters property with values in format "*.png ; PNG Images","*.gd ; GDScript Files". Vector<String> str_values = property_value; @@ -167,14 +168,32 @@ Error PackedSceneEditorTranslationParserPlugin::parse_file(const String &p_path, return OK; } +bool PackedSceneEditorTranslationParserPlugin::match_property(const String &p_property_name, const String &p_node_type) { + for (const KeyValue<String, Vector<String>> &exception : exception_list) { + const String &exception_node_type = exception.key; + if (ClassDB::is_parent_class(p_node_type, exception_node_type)) { + const Vector<String> &exception_properties = exception.value; + for (const String &exception_property : exception_properties) { + if (p_property_name.match(exception_property)) { + return false; + } + } + } + } + for (const String &lookup_property : lookup_properties) { + if (p_property_name.match(lookup_property)) { + return true; + } + } + return false; +} + PackedSceneEditorTranslationParserPlugin::PackedSceneEditorTranslationParserPlugin() { // Scene Node's properties containing strings that will be fetched for translation. lookup_properties.insert("text"); - lookup_properties.insert("tooltip_text"); - lookup_properties.insert("placeholder_text"); - lookup_properties.insert("items"); + lookup_properties.insert("*_text"); + lookup_properties.insert("popup/*/text"); lookup_properties.insert("title"); - lookup_properties.insert("dialog_text"); lookup_properties.insert("filters"); lookup_properties.insert("script"); diff --git a/editor/plugins/packed_scene_translation_parser_plugin.h b/editor/plugins/packed_scene_translation_parser_plugin.h index d1a92ded32..0a5cc1c2a6 100644 --- a/editor/plugins/packed_scene_translation_parser_plugin.h +++ b/editor/plugins/packed_scene_translation_parser_plugin.h @@ -43,6 +43,7 @@ class PackedSceneEditorTranslationParserPlugin : public EditorTranslationParserP public: virtual Error parse_file(const String &p_path, Vector<String> *r_ids, Vector<Vector<String>> *r_ids_ctx_plural) override; + bool match_property(const String &p_property_name, const String &p_node_type); virtual void get_recognized_extensions(List<String> *r_extensions) const override; PackedSceneEditorTranslationParserPlugin(); |
