diff options
author | SkyJJ <jjchai01@hotmail.com> | 2020-07-23 00:07:35 +0200 |
---|---|---|
committer | SkyJJ <jjchai01@hotmail.com> | 2020-08-19 03:01:52 +0200 |
commit | 396f2eee827293d9b096e6fc954a57c92bf21f95 (patch) | |
tree | 97651ad76e4a19293700039ced3e145304a775a7 /editor/editor_translation_parser.cpp | |
parent | c0d837a2ea9ca888f673485c4b9d8d9ae1936375 (diff) | |
download | redot-engine-396f2eee827293d9b096e6fc954a57c92bf21f95.tar.gz |
Update POT generation to handle context and plurals
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..e664292796 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_ctx_plural of EditorTranslationParserPlugin 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")); } |