diff options
author | SkyJJ <jjchai01@hotmail.com> | 2020-07-03 20:24:54 +0200 |
---|---|---|
committer | SkyJJ <jjchai01@hotmail.com> | 2020-07-05 12:14:56 +0200 |
commit | cae6f0bda282c8e831cbae5d45cfaa4e841ff3bf (patch) | |
tree | 3d3db4190712ddf25b8e7f606aeae23a28e3a5a9 /modules | |
parent | 0287508dcdf51c7349b41aabb7679061a5147fdf (diff) |
Change translation parser plugin API to parse_file()
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/editor/gdscript_translation_parser_plugin.cpp | 37 | ||||
-rw-r--r-- | modules/gdscript/editor/gdscript_translation_parser_plugin.h | 1 |
2 files changed, 7 insertions, 31 deletions
diff --git a/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp b/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp index a1b18978fc..6d454e43f2 100644 --- a/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp +++ b/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp @@ -38,25 +38,8 @@ void GDScriptEditorTranslationParserPlugin::get_recognized_extensions(List<Strin } Error GDScriptEditorTranslationParserPlugin::parse_file(const String &p_path, Vector<String> *r_extracted_strings) { - List<String> extensions; - get_recognized_extensions(&extensions); - bool extension_valid = false; - for (auto E = extensions.front(); E; E = E->next()) { - if (p_path.get_extension() == E->get()) { - extension_valid = true; - break; - } - } - - if (!extension_valid) { - Vector<String> temp; - for (auto E = extensions.front(); E; E = E->next()) { - temp.push_back(E->get()); - } - String valid_extensions = String(", ").join(temp); - ERR_PRINT("Argument p_path \"" + p_path + "\" has wrong extension. List of valid extensions: " + valid_extensions); - return ERR_INVALID_PARAMETER; - } + // Parse and match all GDScript function API that involves translation string. + // E.g get_node("Label").text = "something", var test = tr("something"), "something" will be matched and collected. Error err; RES loaded_res = ResourceLoader::load(p_path, "", false, &err); @@ -66,26 +49,18 @@ Error GDScriptEditorTranslationParserPlugin::parse_file(const String &p_path, Ve } Ref<GDScript> gdscript = loaded_res; - parse_text(gdscript->get_source_code(), r_extracted_strings); - - return OK; -} - -void GDScriptEditorTranslationParserPlugin::parse_text(const String &p_text, Vector<String> *r_extracted_strings) { - // Parse and match all GDScript function API that involves translation string. - // E.g get_node("Label").text = "something", var test = tr("something"), "something" will be matched and collected. - + String source_code = gdscript->get_source_code(); Vector<String> parsed_strings; // Search translation strings with RegEx. regex.clear(); regex.compile(String("|").join(patterns)); - Array results = regex.search_all(p_text); + Array results = regex.search_all(source_code); _get_captured_strings(results, &parsed_strings); // Special handling for FileDialog. Vector<String> temp; - _parse_file_dialog(p_text, &temp); + _parse_file_dialog(source_code, &temp); parsed_strings.append_array(temp); // Filter out / and + @@ -97,6 +72,8 @@ void GDScriptEditorTranslationParserPlugin::parse_text(const String &p_text, Vec } r_extracted_strings->append_array(parsed_strings); + + return OK; } void GDScriptEditorTranslationParserPlugin::_parse_file_dialog(const String &p_source_code, Vector<String> *r_output) { diff --git a/modules/gdscript/editor/gdscript_translation_parser_plugin.h b/modules/gdscript/editor/gdscript_translation_parser_plugin.h index ef967845b9..efef8f8249 100644 --- a/modules/gdscript/editor/gdscript_translation_parser_plugin.h +++ b/modules/gdscript/editor/gdscript_translation_parser_plugin.h @@ -48,7 +48,6 @@ class GDScriptEditorTranslationParserPlugin : public EditorTranslationParserPlug 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; GDScriptEditorTranslationParserPlugin(); |