mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Update GDScriptTranslationParserPlugin to use GDSriptParser instead of RegEx.
This commit is contained in:
@@ -31,23 +31,37 @@
|
||||
#ifndef GDSCRIPT_TRANSLATION_PARSER_PLUGIN_H
|
||||
#define GDSCRIPT_TRANSLATION_PARSER_PLUGIN_H
|
||||
|
||||
#include "core/set.h"
|
||||
#include "editor/editor_translation_parser.h"
|
||||
#include "modules/gdscript/gdscript_parser.h"
|
||||
#include "modules/regex/regex.h"
|
||||
|
||||
class GDScriptEditorTranslationParserPlugin : public EditorTranslationParserPlugin {
|
||||
GDCLASS(GDScriptEditorTranslationParserPlugin, EditorTranslationParserPlugin);
|
||||
|
||||
// Regex and search patterns that are used to match translation strings.
|
||||
const String text = "((?:[^\"\\\\]|\\\\[\\s\\S])*(?:\"[\\s\\\\]*\\+[\\s\\\\]*\"(?:[^\"\\\\]|\\\\[\\s\\S])*)*)";
|
||||
const String tr_pattern = "tr[\\s\\\\]*\\([\\s\\\\]*\"" + text + "\"(?:[\\s\\\\]*,[\\s\\\\]*\"" + text + "\")?[\\s\\\\]*\\)";
|
||||
const String trn_pattern = "tr_n[\\s\\\\]*\\([\\s\\\\]*\"" + text + "\"[\\s\\\\]*,[\\s\\\\]*\"" + text + "\".*?(?:\"" + text + "\"[\\s\\\\]*)?\\)";
|
||||
RegEx regex;
|
||||
Vector<String> patterns;
|
||||
Vector<String> file_dialog_patterns;
|
||||
Vector<String> *ids;
|
||||
Vector<Vector<String>> *ids_ctx_plural;
|
||||
|
||||
void _parse_file_dialog(const String &p_source_code, Vector<String> *r_output);
|
||||
void _get_captured_strings(const Array &p_results, Vector<String> *r_output);
|
||||
void _handle_tr_pattern(const String &p_source_code, const String &p_pattern, Vector<Vector<String>> *r_ids_ctx_plural);
|
||||
// List of patterns used for extracting translation strings.
|
||||
StringName tr_func = "tr";
|
||||
StringName trn_func = "tr_n";
|
||||
Set<StringName> assignment_patterns;
|
||||
Set<StringName> first_arg_patterns;
|
||||
Set<StringName> second_arg_patterns;
|
||||
// FileDialog patterns.
|
||||
StringName fd_add_filter = "add_filter";
|
||||
StringName fd_set_filter = "set_filters";
|
||||
StringName fd_filters = "filters";
|
||||
|
||||
void _traverse_class(const GDScriptParser::ClassNode *p_class);
|
||||
void _traverse_function(const GDScriptParser::FunctionNode *p_func);
|
||||
void _traverse_block(const GDScriptParser::SuiteNode *p_suite);
|
||||
|
||||
void _read_variable(const GDScriptParser::VariableNode *p_var);
|
||||
void _assess_expression(GDScriptParser::ExpressionNode *p_expression);
|
||||
void _assess_assignment(GDScriptParser::AssignmentNode *p_assignment);
|
||||
void _extract_from_call(GDScriptParser::CallNode *p_call);
|
||||
void _extract_fd_literals(GDScriptParser::ExpressionNode *p_expression);
|
||||
|
||||
public:
|
||||
virtual Error parse_file(const String &p_path, Vector<String> *r_ids, Vector<Vector<String>> *r_ids_ctx_plural) override;
|
||||
|
||||
Reference in New Issue
Block a user