Change translation parser plugin API to parse_file()
This commit is contained in:
parent
0287508dcd
commit
cae6f0bda2
6 changed files with 35 additions and 60 deletions
|
|
@ -41,33 +41,16 @@ Error EditorTranslationParserPlugin::parse_file(const String &p_path, Vector<Str
|
|||
if (!get_script_instance())
|
||||
return ERR_UNAVAILABLE;
|
||||
|
||||
if (get_script_instance()->has_method("parse_text")) {
|
||||
Error err;
|
||||
FileAccess *file = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
if (err != OK) {
|
||||
ERR_PRINT("Failed to open " + p_path);
|
||||
return err;
|
||||
}
|
||||
parse_text(file->get_as_utf8_string(), r_extracted_strings);
|
||||
return OK;
|
||||
} else {
|
||||
ERR_PRINT("Custom translation parser plugin's \"func parse_text(text, extracted_strings)\" is undefined.");
|
||||
return ERR_UNAVAILABLE;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTranslationParserPlugin::parse_text(const String &p_text, Vector<String> *r_extracted_strings) {
|
||||
if (!get_script_instance())
|
||||
return;
|
||||
|
||||
if (get_script_instance()->has_method("parse_text")) {
|
||||
if (get_script_instance()->has_method("parse_file")) {
|
||||
Array extracted_strings;
|
||||
get_script_instance()->call("parse_text", p_text, 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]);
|
||||
}
|
||||
return OK;
|
||||
} else {
|
||||
ERR_PRINT("Custom translation parser plugin's \"func parse_text(text, extracted_strings)\" is undefined.");
|
||||
ERR_PRINT("Custom translation parser plugin's \"func parse_file(path, extracted_strings)\" is undefined.");
|
||||
return ERR_UNAVAILABLE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +69,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_text", PropertyInfo(Variant::STRING, "text"), PropertyInfo(Variant::ARRAY, "extracted_strings")));
|
||||
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::ARRAY, "get_recognized_extensions"));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ protected:
|
|||
|
||||
public:
|
||||
virtual Error parse_file(const String &p_path, Vector<String> *r_extracted_strings);
|
||||
virtual void parse_text(const String &p_text, Vector<String> *r_extracted_strings);
|
||||
virtual void get_recognized_extensions(List<String> *r_extensions) const;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ Error PackedSceneEditorTranslationParserPlugin::parse_file(const String &p_path,
|
|||
String extension = s->get_language()->get_extension();
|
||||
if (EditorTranslationParser::get_singleton()->can_parse(extension)) {
|
||||
Vector<String> temp;
|
||||
EditorTranslationParser::get_singleton()->get_parser(extension)->parse_text(s->get_source_code(), &temp);
|
||||
EditorTranslationParser::get_singleton()->get_parser(extension)->parse_file(s->get_path(), &temp);
|
||||
parsed_strings.append_array(temp);
|
||||
}
|
||||
} else if (property_name == "filters") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue