diff --git a/editor/plugins/packed_scene_translation_parser_plugin.cpp b/editor/plugins/packed_scene_translation_parser_plugin.cpp index 04d4c6d779d9..86df57c4694b 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 instance = state->get_node_instance(i); + if (instance.is_valid()) { + Ref _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 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 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> &exception : exception_list) { + const String &exception_node_type = exception.key; + if (ClassDB::is_parent_class(p_node_type, exception_node_type)) { + const Vector &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 d1a92ded326f..0a5cc1c2a66b 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 *r_ids, Vector> *r_ids_ctx_plural) override; + bool match_property(const String &p_property_name, const String &p_node_type); virtual void get_recognized_extensions(List *r_extensions) const override; PackedSceneEditorTranslationParserPlugin();