summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2023-03-02 14:38:59 +0800
committerYuri Sizov <yuris@humnom.net>2023-03-30 19:24:52 +0200
commitd6b36e800dfa8970c6bdeab2ed9a0e027e30068b (patch)
treeead788a95bf867a7e3f3d3421d261c038824377b
parentae0a98ef9b7772998f475bb169c435c7d4f22dab (diff)
Improve POT Generation dialog
* Avoid "property not found" warnings when adding a file for the first time. * When no file is added, disable the Generate POT button instead of printing a warning. (cherry picked from commit 584136271cf92b7731f82dce22c4e99075b9b5d7)
-rw-r--r--core/config/project_settings.cpp1
-rw-r--r--editor/localization_editor.cpp26
-rw-r--r--editor/localization_editor.h1
-rw-r--r--editor/pot_generator.cpp6
4 files changed, 18 insertions, 16 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp
index ac51380c30..123e01860e 100644
--- a/core/config/project_settings.cpp
+++ b/core/config/project_settings.cpp
@@ -1348,6 +1348,7 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF_INTERNAL("application/config/features", PackedStringArray());
GLOBAL_DEF_INTERNAL("internationalization/locale/translation_remaps", PackedStringArray());
GLOBAL_DEF_INTERNAL("internationalization/locale/translations", PackedStringArray());
+ GLOBAL_DEF_INTERNAL("internationalization/locale/translations_pot_files", PackedStringArray());
}
ProjectSettings::~ProjectSettings() {
diff --git a/editor/localization_editor.cpp b/editor/localization_editor.cpp
index 5503645930..fac1ec3523 100644
--- a/editor/localization_editor.cpp
+++ b/editor/localization_editor.cpp
@@ -576,21 +576,21 @@ void LocalizationEditor::update_translations() {
translation_pot_list->clear();
root = translation_pot_list->create_item(nullptr);
translation_pot_list->set_hide_root(true);
- if (ProjectSettings::get_singleton()->has_setting("internationalization/locale/translations_pot_files")) {
- PackedStringArray pot_translations = GLOBAL_GET("internationalization/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_text(0, pot_translations[i]);
- t->set_metadata(0, i);
- t->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), 0, false, TTR("Remove"));
- }
+ PackedStringArray pot_translations = GLOBAL_GET("internationalization/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_text(0, pot_translations[i]);
+ t->set_metadata(0, i);
+ t->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), 0, false, TTR("Remove"));
}
// New translation parser plugin might extend possible file extensions in POT generation.
_update_pot_file_extensions();
+ pot_generate_button->set_disabled(pot_translations.is_empty());
+
updating_translations = false;
}
@@ -726,9 +726,9 @@ LocalizationEditor::LocalizationEditor() {
addtr->connect("pressed", callable_mp(this, &LocalizationEditor::_pot_file_open));
thb->add_child(addtr);
- Button *generate = memnew(Button(TTR("Generate POT")));
- generate->connect("pressed", callable_mp(this, &LocalizationEditor::_pot_generate_open));
- thb->add_child(generate);
+ pot_generate_button = memnew(Button(TTR("Generate POT")));
+ pot_generate_button->connect("pressed", callable_mp(this, &LocalizationEditor::_pot_generate_open));
+ thb->add_child(pot_generate_button);
VBoxContainer *tmc = memnew(VBoxContainer);
tmc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
diff --git a/editor/localization_editor.h b/editor/localization_editor.h
index 670ac5793b..b9a78a3c82 100644
--- a/editor/localization_editor.h
+++ b/editor/localization_editor.h
@@ -54,6 +54,7 @@ class LocalizationEditor : public VBoxContainer {
Tree *translation_pot_list = nullptr;
EditorFileDialog *pot_file_open_dialog = nullptr;
EditorFileDialog *pot_generate_dialog = nullptr;
+ Button *pot_generate_button = nullptr;
bool updating_translations = false;
String localization_changed;
diff --git a/editor/pot_generator.cpp b/editor/pot_generator.cpp
index f70a795683..9428d29088 100644
--- a/editor/pot_generator.cpp
+++ b/editor/pot_generator.cpp
@@ -55,7 +55,9 @@ void POTGenerator::_print_all_translation_strings() {
#endif
void POTGenerator::generate_pot(const String &p_file) {
- if (!ProjectSettings::get_singleton()->has_setting("internationalization/locale/translations_pot_files")) {
+ Vector<String> files = GLOBAL_GET("internationalization/locale/translations_pot_files");
+
+ if (files.is_empty()) {
WARN_PRINT("No files selected for POT generation.");
return;
}
@@ -63,8 +65,6 @@ void POTGenerator::generate_pot(const String &p_file) {
// Clear all_translation_strings of the previous round.
all_translation_strings.clear();
- Vector<String> files = GLOBAL_GET("internationalization/locale/translations_pot_files");
-
// Collect all translatable strings according to files order in "POT Generation" setting.
for (int i = 0; i < files.size(); i++) {
Vector<String> msgids;