Skip to content

Commit

Permalink
Merge pull request #89286 from Kiisu-Master/fix-pot-generation
Browse files Browse the repository at this point in the history
Fix packed scene translation parser missing strings.
  • Loading branch information
akien-mga committed Mar 8, 2024
2 parents 877cd12 + 8446084 commit 47941d4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
47 changes: 33 additions & 14 deletions editor/plugins/packed_scene_translation_parser_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -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");

Expand Down
1 change: 1 addition & 0 deletions editor/plugins/packed_scene_translation_parser_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 47941d4

Please sign in to comment.