diff options
Diffstat (limited to 'editor/editor_translation_parser.cpp')
-rw-r--r-- | editor/editor_translation_parser.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/editor/editor_translation_parser.cpp b/editor/editor_translation_parser.cpp index da191fbc92..7a90d20000 100644 --- a/editor/editor_translation_parser.cpp +++ b/editor/editor_translation_parser.cpp @@ -37,15 +37,30 @@ EditorTranslationParser *EditorTranslationParser::singleton = nullptr; -Error EditorTranslationParserPlugin::parse_file(const String &p_path, Vector<String> *r_extracted_strings) { +Error EditorTranslationParserPlugin::parse_file(const String &p_path, Vector<String> *r_ids, Vector<Vector<String>> *r_ids_ctx_plural) { if (!get_script_instance()) return ERR_UNAVAILABLE; if (get_script_instance()->has_method("parse_file")) { - Array extracted_strings; - get_script_instance()->call("parse_file", p_path, extracted_strings); - for (int i = 0; i < extracted_strings.size(); i++) { - r_extracted_strings->append(extracted_strings[i]); + Array ids; + Array ids_ctx_plural; + get_script_instance()->call("parse_file", p_path, ids, ids_ctx_plural); + + // Add user's extracted translatable messages. + for (int i = 0; i < ids.size(); i++) { + r_ids->append(ids[i]); + } + + // Add user's collected translatable messages with context or plurals. + for (int i = 0; i < ids_ctx_plural.size(); i++) { + Array arr = ids_ctx_plural[i]; + ERR_FAIL_COND_V_MSG(arr.size() != 3, ERR_INVALID_DATA, "Array entries written into `msgids_context_plural` in `parse_file()` method should have the form [\"message\", \"context\", \"plural message\"]"); + + Vector<String> id_ctx_plural; + id_ctx_plural.push_back(arr[0]); + id_ctx_plural.push_back(arr[1]); + id_ctx_plural.push_back(arr[2]); + r_ids_ctx_plural->append(id_ctx_plural); } return OK; } else { @@ -69,7 +84,7 @@ void EditorTranslationParserPlugin::get_recognized_extensions(List<String> *r_ex } void EditorTranslationParserPlugin::_bind_methods() { - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::NIL, "parse_file", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::ARRAY, "extracted_strings"))); + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::NIL, "parse_file", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::ARRAY, "msgids"), PropertyInfo(Variant::ARRAY, "msgids_context_plural"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::ARRAY, "get_recognized_extensions")); } |