mirror of
https://github.com/godotengine/godot
synced 2024-09-05 11:48:29 +00:00
Fix packed scene translation parser missing strings.
This commit is contained in:
parent
aef11a1427
commit
8446084a20
|
@ -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");
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue