You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Update POT generation to handle context and plurals
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user