From 1db29d0101816825af6641bbfbbc3cef6d394dc2 Mon Sep 17 00:00:00 2001 From: SkyJJ Date: Fri, 19 Jun 2020 11:56:24 +0200 Subject: [PATCH] Added "POT generation" feature under "Localization" in the Editor --- editor/pot_generator.cpp | 346 +++++++++++++++++++++++++++++ editor/pot_generator.h | 67 ++++++ editor/project_settings_editor.cpp | 114 ++++++++++ editor/project_settings_editor.h | 10 + 4 files changed, 537 insertions(+) create mode 100644 editor/pot_generator.cpp create mode 100644 editor/pot_generator.h diff --git a/editor/pot_generator.cpp b/editor/pot_generator.cpp new file mode 100644 index 00000000000..7ec5a221a4b --- /dev/null +++ b/editor/pot_generator.cpp @@ -0,0 +1,346 @@ +/*************************************************************************/ +/* pot_generator.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "pot_generator.h" + +#include "core/class_db.h" +#include "core/error_macros.h" +#include "core/io/resource_loader.h" +#include "core/project_settings.h" +#include "core/script_language.h" +#include "core/variant.h" +#include "modules/gdscript/gdscript.h" +#include "scene/resources/packed_scene.h" + +POTGenerator *POTGenerator::singleton = nullptr; + +//#define DEBUG_POT + +#ifdef DEBUG_POT +void _print_all_translation_strings(const OrderedHashMap> &p_all_translation_strings) { + for (auto E_pair = p_all_translation_strings.front(); E_pair; E_pair = E_pair.next()) { + String msg = static_cast(E_pair.key()) + " : "; + for (Set::Element *E = E_pair.value().front(); E; E = E->next()) { + msg += E->get() + " "; + } + print_line(msg); + } +} +#endif + +void POTGenerator::generate_pot(const String &p_file) { + if (!ProjectSettings::get_singleton()->has_setting("locale/translations_pot_files")) { + WARN_PRINT("No files selected for POT generation."); + return; + } + + // Clear all_translation_strings of the previous round. + all_translation_strings.clear(); + + Vector files = ProjectSettings::get_singleton()->get("locale/translations_pot_files"); + Vector translation_strings; + List packed_scene_extensions; + ResourceLoader::get_recognized_extensions_for_type("PackedScene", &packed_scene_extensions); + + // Collect all translatable strings according to files order in "POT Generation" setting. + for (int i = 0; i < files.size(); i++) { + String file_path = files[i]; + String file_extension = file_path.get_extension(); + + Error err; + RES loaded_res = ResourceLoader::load(file_path, "", false, &err); + if (err) { + ERR_PRINT("Failed to load " + file_path); + continue; + } + + bool is_scene_file = false; + for (List::Element *E = packed_scene_extensions.front(); E; E = E->next()) { + if (file_extension == E->get()) { + is_scene_file = true; + break; + } + } + + if (is_scene_file) { + Ref ps = loaded_res; + translation_strings = _parse_scene(ps->get_state()); + } else if (file_extension == "gd") { + // Currently we only support GDScript. + Ref s = loaded_res; + translation_strings = _parse_script(s->get_source_code()); + } else { + ERR_PRINT("Unrecognized file extension in generate_pot()"); + continue; + } + + // Store translation strings parsed in this iteration along with their corresponding source file - to write into POT later on. + for (int j = 0; j < translation_strings.size(); j++) { + all_translation_strings[translation_strings[j]].insert(file_path); + } + } + +#ifdef DEBUG_POT + _print_all_translation_strings(all_translation_strings); +#endif + + _write_to_pot(p_file); +} + +Vector POTGenerator::_parse_scene(const Ref &p_state) { + // Parse specific scene Node's properties (see in constructor) that are auto-translated by the engine when set. E.g Label's text property. + // These properties are translated with the tr() function in the C++ code when being set or updated. + + Vector parsed_strings; + + String property_name; + Variant property_value; + for (int i = 0; i < p_state->get_node_count(); i++) { + if (!ClassDB::is_parent_class(p_state->get_node_type(i), "Control") && !ClassDB::is_parent_class(p_state->get_node_type(i), "Viewport")) { + continue; + } + + for (int j = 0; j < p_state->get_node_property_count(i); j++) { + property_name = p_state->get_node_property_name(i, j); + if (!lookup_properties.has(property_name)) { + continue; + } + + property_value = p_state->get_node_property_value(i, j); + + if (property_name == "script" && property_value.get_type() == Variant::OBJECT && !property_value.is_null()) { + // Parse built-in script. Currently we only support GDScript. + Ref s = Object::cast_to(property_value); + parsed_strings.append_array(_parse_script(s->get_source_code())); + } else if (property_name == "filters") { + // Extract FileDialog's filters property with values in format "*.png ; PNG Images","*.gd ; GDScript Files". + Vector str_values = property_value; + for (int k = 0; k < str_values.size(); k++) { + String desc = str_values[k].get_slice(";", 1).strip_edges(); + if (!desc.empty()) { + parsed_strings.push_back(desc); + } + } + } else if (property_value.get_type() == Variant::STRING) { + String str_value = String(property_value); + // Prevent reading text containing only spaces. + if (!str_value.strip_edges().empty()) { + parsed_strings.push_back(str_value); + } + } + } + } + + return parsed_strings; +} + +Vector POTGenerator::_parse_script(const String &p_source_code) { + // 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 + // The extra complication in the regex pattern is to ensure that the matching works when users write over multiple lines, use tabs etc. + + Vector parsed_strings; + + regex.clear(); + regex.compile(String("|").join(patterns)); + Array results = regex.search_all(p_source_code); + _get_captured_strings(results, &parsed_strings); + + // Special handling for FileDialog + Vector temp; + _parse_file_dialog(p_source_code, &temp); + parsed_strings.append_array(temp); + + // Filter out / and + + String filter = "(?:\\\\\\n|\"[\\s\\\\]*\\+\\s*\")"; + regex.clear(); + regex.compile(filter); + for (int i = 0; i < parsed_strings.size(); i++) { + parsed_strings.set(i, regex.sub(parsed_strings[i], "", true)); + } + + return parsed_strings; +} + +void POTGenerator::_parse_file_dialog(const String &p_source_code, Vector *r_output) { + // FileDialog API has the form .filters = PackedStringArray(["*.png ; PNG Images","*.gd ; GDScript Files"]). + // First filter: Get "*.png ; PNG Images", "*.gd ; GDScript Files" from PackedStringArray. + regex.clear(); + regex.compile(String("|").join(file_dialog_patterns)); + Array results = regex.search_all(p_source_code); + + Vector temp; + _get_captured_strings(results, &temp); + String captured_strings = String(",").join(temp); + + // Second filter: Get the texts after semicolon from "*.png ; PNG Images","*.gd ; GDScript Files". + String second_filter = "\"[^;]+;" + text + "\""; + regex.clear(); + regex.compile(second_filter); + results = regex.search_all(captured_strings); + _get_captured_strings(results, r_output); + for (int i = 0; i < r_output->size(); i++) { + r_output->set(i, r_output->get(i).strip_edges()); + } +} + +void POTGenerator::_get_captured_strings(const Array &p_results, Vector *r_output) { + Ref result; + for (int i = 0; i < p_results.size(); i++) { + result = p_results[i]; + for (int j = 0; j < result->get_group_count(); j++) { + String s = result->get_string(j + 1); + // Prevent reading text with only spaces. + if (!s.strip_edges().empty()) { + r_output->push_back(s); + } + } + } +} + +void POTGenerator::_write_to_pot(const String &p_file) { + Error err; + FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err); + if (err != OK) { + ERR_PRINT("Failed to open " + p_file); + return; + } + + String project_name = ProjectSettings::get_singleton()->get("application/config/name"); + Vector files = ProjectSettings::get_singleton()->get("locale/translations_pot_files"); + String extracted_files = ""; + for (int i = 0; i < files.size(); i++) { + extracted_files += "# " + files[i] + "\n"; + } + const String header = + "# LANGUAGE translation for " + project_name + " for the following files:\n" + extracted_files + + "#\n" + "#\n" + "# FIRST AUTHOR < EMAIL @ADDRESS>, YEAR.\n" + "#\n" + "#, fuzzy\n" + "msgid \"\"\n" + "msgstr \"\"\n" + "\"Project-Id-Version: " + + project_name + "\\n\"\n" + "\"Content-Type: text/plain; charset=UTF-8\\n\"\n" + "\"Content-Transfer-Encoding: 8-bit\\n\"\n\n"; + + file->store_string(header); + + for (OrderedHashMap>::Element E_pair = all_translation_strings.front(); E_pair; E_pair = E_pair.next()) { + String msg = E_pair.key(); + + // Write file locations. + for (Set::Element *E = E_pair.value().front(); E; E = E->next()) { + file->store_line("#: " + E->get().trim_prefix("res://")); + } + + // Write msgid. + Vector msg_lines = msg.split("\\n"); + file->store_string("msgid \"" + msg_lines[0]); + for (int i = 1; i < msg_lines.size(); i++) { + file->store_line("\\n\""); + file->store_string("\"" + msg_lines[i]); + } + file->store_line("\""); + + file->store_line("msgstr \"\"\n"); + } + + file->close(); +} + +POTGenerator *POTGenerator::get_singleton() { + if (!singleton) { + singleton = memnew(POTGenerator); + } + return singleton; +} + +POTGenerator::POTGenerator() { + // Scene Node's properties containing strings that will be fetched for translation. + lookup_properties.insert("text"); + lookup_properties.insert("hint_tooltip"); + lookup_properties.insert("placeholder_text"); + lookup_properties.insert("dialog_text"); + lookup_properties.insert("filters"); + lookup_properties.insert("script"); + + //Add exception list (to prevent false positives) + //line edit, text edit, richtextlabel + //Set exception_list; + //exception_list.insert("RichTextLabel"); + + // Regex search pattern templates. + const String dot = "\\.[\\s\\\\]*"; + const String str_assign_template = "[\\s\\\\]*=[\\s\\\\]*\"" + text + "\""; + const String first_arg_template = "[\\s\\\\]*\\([\\s\\\\]*\"" + text + "\"[\\s\\S]*?\\)"; + const String second_arg_template = "[\\s\\\\]*\\([\\s\\S]+?,[\\s\\\\]*\"" + text + "\"[\\s\\S]*?\\)"; + + // Common patterns. + patterns.push_back("tr" + first_arg_template); + patterns.push_back(dot + "text" + str_assign_template); + patterns.push_back(dot + "placeholder_text" + str_assign_template); + patterns.push_back(dot + "hint_tooltip" + str_assign_template); + patterns.push_back(dot + "set_text" + first_arg_template); + patterns.push_back(dot + "set_tooltip" + first_arg_template); + patterns.push_back(dot + "set_placeholder" + first_arg_template); + + // Tabs and TabContainer API. + patterns.push_back(dot + "set_tab_title" + second_arg_template); + patterns.push_back(dot + "add_tab" + first_arg_template); + + // PopupMenu API. + patterns.push_back(dot + "add_check_item" + first_arg_template); + patterns.push_back(dot + "add_icon_check_item" + second_arg_template); + patterns.push_back(dot + "add_icon_item" + second_arg_template); + patterns.push_back(dot + "add_icon_radio_check_item" + second_arg_template); + patterns.push_back(dot + "add_item" + first_arg_template); + patterns.push_back(dot + "add_multistate_item" + first_arg_template); + patterns.push_back(dot + "add_radio_check_item" + first_arg_template); + patterns.push_back(dot + "add_separator" + first_arg_template); + patterns.push_back(dot + "add_submenu_item" + first_arg_template); + patterns.push_back(dot + "set_item_text" + second_arg_template); + //patterns.push_back(dot + "set_item_tooltip" + second_arg_template); //no tr() behind this function. might be bug. + + // FileDialog API - special case. + const String fd_text = "((?:[\\s\\\\]*\"(?:[^\"\\\\]|\\\\[\\s\\S])*(?:\"[\\s\\\\]*\\+[\\s\\\\]*\"(?:[^\"\\\\]|\\\\[\\s\\S])*)*\"[\\s\\\\]*,?)*)"; + const String packed_string_array = "[\\s\\\\]*PackedStringArray[\\s\\\\]*\\([\\s\\\\]*\\[" + fd_text + "\\][\\s\\\\]*\\)"; + file_dialog_patterns.push_back(dot + "add_filter[\\s\\\\]*\\(" + fd_text + "[\\s\\\\]*\\)"); + file_dialog_patterns.push_back(dot + "filters[\\s\\\\]*=" + packed_string_array); + file_dialog_patterns.push_back(dot + "set_filters[\\s\\\\]*\\(" + packed_string_array + "[\\s\\\\]*\\)"); +} + +POTGenerator::~POTGenerator() { + memdelete(singleton); + singleton = nullptr; +} diff --git a/editor/pot_generator.h b/editor/pot_generator.h new file mode 100644 index 00000000000..5e947aca004 --- /dev/null +++ b/editor/pot_generator.h @@ -0,0 +1,67 @@ +/*************************************************************************/ +/* pot_generator.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef POT_GENERATOR_H +#define POT_GENERATOR_H + +#include "core/ordered_hash_map.h" +#include "core/set.h" +#include "modules/regex/regex.h" +#include "scene/resources/packed_scene.h" + +class POTGenerator { + static POTGenerator *singleton; + // Stores all translatable strings and the source files containing them. + OrderedHashMap> all_translation_strings; + + // Scene Node's properties that contain translation strings. + Set lookup_properties; + + // Regex and search patterns that are used to match translation strings in scripts. + const String text = "((?:[^\"\\\\]|\\\\[\\s\\S])*(?:\"[\\s\\\\]*\\+[\\s\\\\]*\"(?:[^\"\\\\]|\\\\[\\s\\S])*)*)"; + RegEx regex; + Vector patterns; + Vector file_dialog_patterns; + + Vector _parse_scene(const Ref &p_state); + Vector _parse_script(const String &p_source_code); + void _parse_file_dialog(const String &p_source_code, Vector *r_output); + void _get_captured_strings(const Array &p_results, Vector *r_output); + void _write_to_pot(const String &p_file); + +public: + static POTGenerator *get_singleton(); + void generate_pot(const String &p_file); + + POTGenerator(); + ~POTGenerator(); +}; + +#endif // POT_GENERATOR_H diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index a8029e1e2b5..f284c2b9948 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -38,6 +38,7 @@ #include "editor/editor_export.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/pot_generator.h" #include "scene/gui/margin_container.h" #include "scene/gui/tab_container.h" @@ -120,6 +121,7 @@ void ProjectSettingsEditor::_notification(int p_what) { action_add_error->add_theme_color_override("font_color", input_editor->get_theme_color("error_color", "Editor")); translation_list->connect("button_pressed", callable_mp(this, &ProjectSettingsEditor::_translation_delete)); + translation_pot_list->connect("button_pressed", callable_mp(this, &ProjectSettingsEditor::_translation_pot_delete)); _update_actions(); popup_add->add_icon_item(input_editor->get_theme_icon("Keyboard", "EditorIcons"), TTR("Key"), INPUT_KEY); popup_add->add_icon_item(input_editor->get_theme_icon("KeyboardPhysical", "EditorIcons"), TTR("Physical Key"), INPUT_KEY_PHYSICAL); @@ -140,6 +142,15 @@ void ProjectSettingsEditor::_notification(int p_what) { translation_res_option_file_open->add_filter("*." + E->get()); } + List pfn; + ResourceLoader::get_recognized_extensions_for_type("PackedScene", &pfn); + for (List::Element *E = pfn.front(); E; E = E->next()) { + translation_pot_file_open->add_filter("*." + E->get()); + } + // Currently we only support GDScript. + translation_pot_file_open->add_filter("*.gd"); + translation_pot_generate->add_filter("*.pot"); + restart_close_button->set_icon(input_editor->get_theme_icon("Close", "EditorIcons")); restart_container->add_theme_style_override("panel", input_editor->get_theme_stylebox("bg", "Tree")); restart_icon->set_texture(input_editor->get_theme_icon("StatusWarning", "EditorIcons")); @@ -1519,6 +1530,60 @@ void ProjectSettingsEditor::_translation_filter_mode_changed(int p_mode) { undo_redo->commit_action(); } +void ProjectSettingsEditor::_translation_pot_add(const String &p_path) { + PackedStringArray pot_translations = ProjectSettings::get_singleton()->get("locale/translations_pot_files"); + + for (int i = 0; i < pot_translations.size(); i++) { + if (pot_translations[i] == p_path) { + return; //exists + } + } + + pot_translations.push_back(p_path); + undo_redo->create_action(TTR("Add files for POT generation")); + undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translations_pot_files", pot_translations); + undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translations_pot_files", ProjectSettings::get_singleton()->get("locale/translations_pot_files")); + undo_redo->add_do_method(this, "_update_translations"); + undo_redo->add_undo_method(this, "_update_translations"); + undo_redo->add_do_method(this, "_settings_changed"); + undo_redo->add_undo_method(this, "_settings_changed"); + undo_redo->commit_action(); +} + +void ProjectSettingsEditor::_translation_pot_delete(Object *p_item, int p_column, int p_button) { + TreeItem *ti = Object::cast_to(p_item); + ERR_FAIL_COND(!ti); + + int idx = ti->get_metadata(0); + + PackedStringArray pot_translations = ProjectSettings::get_singleton()->get("locale/translations_pot_files"); + + ERR_FAIL_INDEX(idx, pot_translations.size()); + + pot_translations.remove(idx); + + undo_redo->create_action(TTR("Remove file from POT generation")); + undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translations_pot_files", pot_translations); + undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translations_pot_files", ProjectSettings::get_singleton()->get("locale/translations_pot_files")); + undo_redo->add_do_method(this, "_update_translations"); + undo_redo->add_undo_method(this, "_update_translations"); + undo_redo->add_do_method(this, "_settings_changed"); + undo_redo->add_undo_method(this, "_settings_changed"); + undo_redo->commit_action(); +} + +void ProjectSettingsEditor::_translation_pot_file_open() { + translation_pot_file_open->popup_centered_ratio(); +} + +void ProjectSettingsEditor::_translation_pot_generate_open() { + translation_pot_generate->popup_centered_ratio(); +} + +void ProjectSettingsEditor::_translation_pot_generate(const String &p_file) { + POTGenerator::get_singleton()->generate_pot(p_file); +} + void ProjectSettingsEditor::_update_translations() { //update translations @@ -1696,6 +1761,23 @@ void ProjectSettingsEditor::_update_translations() { } } + //update translation POT files + + translation_pot_list->clear(); + root = translation_pot_list->create_item(nullptr); + translation_pot_list->set_hide_root(true); + if (ProjectSettings::get_singleton()->has_setting("locale/translations_pot_files")) { + PackedStringArray pot_translations = ProjectSettings::get_singleton()->get("locale/translations_pot_files"); + for (int i = 0; i < pot_translations.size(); i++) { + TreeItem *t = translation_pot_list->create_item(root); + t->set_editable(0, false); + t->set_text(0, pot_translations[i].replace_first("res://", "")); + t->set_tooltip(0, pot_translations[i]); + t->set_metadata(0, i); + t->add_button(0, input_editor->get_theme_icon("Remove", "EditorIcons"), 0, false, TTR("Remove")); + } + } + updating_translations = false; } @@ -2108,6 +2190,38 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { translation_filter->connect("item_edited", callable_mp(this, &ProjectSettingsEditor::_translation_filter_option_changed)); } + { + VBoxContainer *tvb = memnew(VBoxContainer); + translations->add_child(tvb); + tvb->set_name(TTR("POT Generation")); + HBoxContainer *thb = memnew(HBoxContainer); + tvb->add_child(thb); + thb->add_child(memnew(Label(TTR("Files with translation strings:")))); + thb->add_spacer(); + Button *addtr = memnew(Button(TTR("Add..."))); + addtr->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_translation_pot_file_open)); + thb->add_child(addtr); + Button *generate = memnew(Button(TTR("Generate POT"))); + generate->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_translation_pot_generate_open)); + thb->add_child(generate); + VBoxContainer *tmc = memnew(VBoxContainer); + tvb->add_child(tmc); + tmc->set_v_size_flags(Control::SIZE_EXPAND_FILL); + translation_pot_list = memnew(Tree); + translation_pot_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); + tmc->add_child(translation_pot_list); + + translation_pot_generate = memnew(EditorFileDialog); + add_child(translation_pot_generate); + translation_pot_generate->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE); + translation_pot_generate->connect("file_selected", callable_mp(this, &ProjectSettingsEditor::_translation_pot_generate)); + + translation_pot_file_open = memnew(EditorFileDialog); + add_child(translation_pot_file_open); + translation_pot_file_open->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); + translation_pot_file_open->connect("file_selected", callable_mp(this, &ProjectSettingsEditor::_translation_pot_add)); + } + autoload_settings = memnew(EditorAutoloadSettings); autoload_settings->set_name(TTR("AutoLoad")); tab_container->add_child(autoload_settings); diff --git a/editor/project_settings_editor.h b/editor/project_settings_editor.h index 728f31efa86..6e86634ca5e 100644 --- a/editor/project_settings_editor.h +++ b/editor/project_settings_editor.h @@ -110,6 +110,10 @@ class ProjectSettingsEditor : public AcceptDialog { Vector translation_filter_treeitems; Vector translation_locales_idxs_remap; + Tree *translation_pot_list; + EditorFileDialog *translation_pot_file_open; + EditorFileDialog *translation_pot_generate; + EditorAutoloadSettings *autoload_settings; EditorPluginSettings *plugin_settings; @@ -159,6 +163,12 @@ class ProjectSettingsEditor : public AcceptDialog { void _translation_filter_option_changed(); void _translation_filter_mode_changed(int p_mode); + void _translation_pot_add(const String &p_path); + void _translation_pot_delete(Object *p_item, int p_column, int p_button); + void _translation_pot_file_open(); + void _translation_pot_generate_open(); + void _translation_pot_generate(const String &p_file); + void _toggle_search_bar(bool p_pressed); Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);