Skip to content

Commit 87ebd2d

Browse files
committed
Improve auto-translation of settings dialogs
1 parent 99f5a3d commit 87ebd2d

14 files changed

+177
-128
lines changed

editor/action_map_editor.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ String ActionMapEditor::_check_new_action_name(const String &p_name) {
8585
}
8686

8787
void ActionMapEditor::_add_edit_text_changed(const String &p_name) {
88-
String error = _check_new_action_name(p_name);
88+
const String error = _check_new_action_name(p_name);
8989
add_button->set_tooltip_text(error);
9090
add_button->set_disabled(!error.is_empty());
9191
}
@@ -361,6 +361,15 @@ void ActionMapEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data,
361361

362362
void ActionMapEditor::_notification(int p_what) {
363363
switch (p_what) {
364+
case NOTIFICATION_TRANSLATION_CHANGED: {
365+
if (!actions_cache.is_empty()) {
366+
update_action_list();
367+
}
368+
if (!add_button->get_tooltip_text().is_empty()) {
369+
_add_edit_text_changed(add_edit->get_text());
370+
}
371+
} break;
372+
364373
case NOTIFICATION_THEME_CHANGED: {
365374
action_list_search->set_right_icon(get_editor_theme_icon(SNAME("Search")));
366375
add_button->set_button_icon(get_editor_theme_icon(SNAME("Add")));
@@ -455,10 +464,10 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
455464
bool events_eq = Shortcut::is_event_array_equal(action_info.action_initial["events"], action_info.action["events"]);
456465
bool action_eq = deadzone_eq && events_eq;
457466
action_item->set_meta("__action_initial", action_info.action_initial);
458-
action_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("ReloadSmall")), BUTTON_REVERT_ACTION, action_eq, action_eq ? TTR("Cannot Revert - Action is same as initial") : TTR("Revert Action"));
467+
action_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("ReloadSmall")), BUTTON_REVERT_ACTION, action_eq, action_eq ? TTRC("Cannot Revert - Action is same as initial") : TTRC("Revert Action"));
459468
}
460-
action_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Add")), BUTTON_ADD_EVENT, false, TTR("Add Event"));
461-
action_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_ACTION, !action_info.editable, action_info.editable ? TTR("Remove Action") : TTR("Cannot Remove Action"));
469+
action_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Add")), BUTTON_ADD_EVENT, false, TTRC("Add Event"));
470+
action_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_ACTION, !action_info.editable, action_info.editable ? TTRC("Remove Action") : TTRC("Cannot Remove Action"));
462471

463472
action_item->set_custom_bg_color(0, action_tree->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
464473
action_item->set_custom_bg_color(1, action_tree->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
@@ -506,8 +515,8 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
506515
}
507516

508517
// Third Column - Buttons
509-
event_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Edit")), BUTTON_EDIT_EVENT, false, TTR("Edit Event"), TTR("Edit Event"));
510-
event_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_EVENT, false, TTR("Remove Event"), TTR("Remove Event"));
518+
event_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Edit")), BUTTON_EDIT_EVENT, false, TTRC("Edit Event"), TTRC("Edit Event"));
519+
event_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_EVENT, false, TTRC("Remove Event"), TTRC("Remove Event"));
511520
event_item->set_button_color(2, 0, Color(1, 1, 1, 0.75));
512521
event_item->set_button_color(2, 1, Color(1, 1, 1, 0.75));
513522
}
@@ -547,7 +556,7 @@ ActionMapEditor::ActionMapEditor() {
547556

548557
action_list_search = memnew(LineEdit);
549558
action_list_search->set_h_size_flags(Control::SIZE_EXPAND_FILL);
550-
action_list_search->set_placeholder(TTR("Filter by Name"));
559+
action_list_search->set_placeholder(TTRC("Filter by Name"));
551560
action_list_search->set_accessibility_name(TTRC("Filter by Name"));
552561
action_list_search->set_clear_button_enabled(true);
553562
action_list_search->connect(SceneStringName(text_changed), callable_mp(this, &ActionMapEditor::_search_term_updated));
@@ -563,8 +572,8 @@ ActionMapEditor::ActionMapEditor() {
563572
top_hbox->add_child(action_list_search_by_event);
564573

565574
clear_all_search = memnew(Button);
566-
clear_all_search->set_text(TTR("Clear All"));
567-
clear_all_search->set_tooltip_text(TTR("Clear all search filters."));
575+
clear_all_search->set_text(TTRC("Clear All"));
576+
clear_all_search->set_tooltip_text(TTRC("Clear all search filters."));
568577
clear_all_search->connect(SceneStringName(pressed), callable_mp(action_list_search_by_event, &EventListenerLineEdit::clear_event));
569578
clear_all_search->connect(SceneStringName(pressed), callable_mp(action_list_search, &LineEdit::clear));
570579
top_hbox->add_child(clear_all_search);
@@ -575,7 +584,7 @@ ActionMapEditor::ActionMapEditor() {
575584

576585
add_edit = memnew(LineEdit);
577586
add_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
578-
add_edit->set_placeholder(TTR("Add New Action"));
587+
add_edit->set_placeholder(TTRC("Add New Action"));
579588
add_edit->set_accessibility_name(TTRC("Add New Action"));
580589
add_edit->set_clear_button_enabled(true);
581590
add_edit->set_keep_editing_on_text_submit(true);
@@ -584,7 +593,7 @@ ActionMapEditor::ActionMapEditor() {
584593
add_hbox->add_child(add_edit);
585594

586595
add_button = memnew(Button);
587-
add_button->set_text(TTR("Add"));
596+
add_button->set_text(TTRC("Add"));
588597
add_button->connect(SceneStringName(pressed), callable_mp(this, &ActionMapEditor::_add_action_pressed));
589598
add_hbox->add_child(add_button);
590599
// Disable the button and set its tooltip.
@@ -593,7 +602,7 @@ ActionMapEditor::ActionMapEditor() {
593602
add_hbox->add_child(memnew(VSeparator));
594603

595604
show_builtin_actions_checkbutton = memnew(CheckButton);
596-
show_builtin_actions_checkbutton->set_text(TTR("Show Built-in Actions"));
605+
show_builtin_actions_checkbutton->set_text(TTRC("Show Built-in Actions"));
597606
show_builtin_actions_checkbutton->connect(SceneStringName(toggled), callable_mp(this, &ActionMapEditor::set_show_builtin_actions));
598607
add_hbox->add_child(show_builtin_actions_checkbutton);
599608

@@ -609,9 +618,9 @@ ActionMapEditor::ActionMapEditor() {
609618
action_tree->set_columns(3);
610619
action_tree->set_hide_root(true);
611620
action_tree->set_column_titles_visible(true);
612-
action_tree->set_column_title(0, TTR("Action"));
621+
action_tree->set_column_title(0, TTRC("Action"));
613622
action_tree->set_column_clip_content(0, true);
614-
action_tree->set_column_title(1, TTR("Deadzone"));
623+
action_tree->set_column_title(1, TTRC("Deadzone"));
615624
action_tree->set_column_expand(1, false);
616625
action_tree->set_column_custom_minimum_width(1, 80 * EDSCALE);
617626
action_tree->set_column_expand(2, false);

editor/editor_autoload_settings.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ void EditorAutoloadSettings::_notification(int p_what) {
5757
browse_button->set_button_icon(get_editor_theme_icon(SNAME("Folder")));
5858
} break;
5959

60+
case NOTIFICATION_TRANSLATION_CHANGED: {
61+
if (!error_message->get_text().is_empty()) {
62+
_autoload_text_changed(autoload_add_name->get_text());
63+
}
64+
} break;
65+
6066
case NOTIFICATION_THEME_CHANGED: {
6167
browse_button->set_button_icon(get_editor_theme_icon(SNAME("Folder")));
6268
add_autoload->set_button_icon(get_editor_theme_icon(SNAME("Add")));
@@ -529,7 +535,7 @@ void EditorAutoloadSettings::update_autoload() {
529535

530536
item->set_cell_mode(2, TreeItem::CELL_MODE_CHECK);
531537
item->set_editable(2, true);
532-
item->set_text(2, TTR("Enable"));
538+
item->set_text(2, TTRC("Enable"));
533539
item->set_checked(2, info.is_singleton);
534540
item->add_button(3, get_editor_theme_icon(SNAME("Load")), BUTTON_OPEN);
535541
item->add_button(3, get_editor_theme_icon(SNAME("MoveUp")), BUTTON_MOVE_UP);
@@ -888,22 +894,23 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
888894
add_child(hbc);
889895

890896
error_message = memnew(Label);
897+
error_message->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
891898
error_message->set_focus_mode(FOCUS_ACCESSIBILITY);
892899
error_message->hide();
893900
error_message->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
894901
error_message->add_theme_color_override(SceneStringName(font_color), EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("error_color"), EditorStringName(Editor)));
895902
add_child(error_message);
896903

897904
Label *l = memnew(Label);
898-
l->set_text(TTR("Path:"));
905+
l->set_text(TTRC("Path:"));
899906
hbc->add_child(l);
900907

901908
autoload_add_path = memnew(LineEdit);
902909
hbc->add_child(autoload_add_path);
903910
autoload_add_path->set_accessibility_name(TTRC("Autoload Path"));
904911
autoload_add_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
905912
autoload_add_path->set_clear_button_enabled(true);
906-
autoload_add_path->set_placeholder(vformat(TTR("Set path or press \"%s\" to create a script."), TTR("Add")));
913+
autoload_add_path->set_placeholder(TTRC("Set path or press \"Add\" to create a script."));
907914
autoload_add_path->connect(SceneStringName(text_changed), callable_mp(this, &EditorAutoloadSettings::_autoload_path_text_changed));
908915

909916
browse_button = memnew(Button);
@@ -922,7 +929,7 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
922929
file_dialog->connect("file_selected", callable_mp(this, &EditorAutoloadSettings::_autoload_file_callback));
923930

924931
l = memnew(Label);
925-
l->set_text(TTR("Node Name:"));
932+
l->set_text(TTRC("Node Name:"));
926933
hbc->add_child(l);
927934

928935
autoload_add_name = memnew(LineEdit);
@@ -933,7 +940,7 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
933940
hbc->add_child(autoload_add_name);
934941

935942
add_autoload = memnew(Button);
936-
add_autoload->set_text(TTR("Add"));
943+
add_autoload->set_text(TTRC("Add"));
937944
add_autoload->connect(SceneStringName(pressed), callable_mp(this, &EditorAutoloadSettings::_autoload_add));
938945
// The button will be enabled once a valid name is entered (either automatically or manually).
939946
add_autoload->set_disabled(true);
@@ -950,16 +957,16 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
950957
tree->set_columns(4);
951958
tree->set_column_titles_visible(true);
952959

953-
tree->set_column_title(0, TTR("Name"));
960+
tree->set_column_title(0, TTRC("Name"));
954961
tree->set_column_expand(0, true);
955962
tree->set_column_expand_ratio(0, 1);
956963

957-
tree->set_column_title(1, TTR("Path"));
964+
tree->set_column_title(1, TTRC("Path"));
958965
tree->set_column_expand(1, true);
959966
tree->set_column_clip_content(1, true);
960967
tree->set_column_expand_ratio(1, 2);
961968

962-
tree->set_column_title(2, TTR("Global Variable"));
969+
tree->set_column_title(2, TTRC("Global Variable"));
963970
tree->set_column_expand(2, false);
964971

965972
tree->set_column_expand(3, false);

editor/editor_locale_dialog.cpp

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
#include "scene/gui/option_button.h"
4040
#include "scene/gui/tree.h"
4141

42+
void EditorLocaleDialog::_notification(int p_what) {
43+
if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
44+
// TRANSLATORS: This is the label for a list of writing systems.
45+
script_label1->set_text(TTR("Script:", "Locale"));
46+
// TRANSLATORS: This refers to a writing system.
47+
script_label2->set_text(TTR("Script", "Locale"));
48+
49+
script_list->set_accessibility_name(TTR("Script", "Locale"));
50+
script_code->set_accessibility_name(TTR("Script", "Locale"));
51+
}
52+
}
53+
4254
void EditorLocaleDialog::_bind_methods() {
4355
ADD_SIGNAL(MethodInfo("locale_selected", PropertyInfo(Variant::STRING, "locale")));
4456
}
@@ -295,7 +307,7 @@ void EditorLocaleDialog::_update_tree() {
295307

296308
if (!is_edit_mode) {
297309
TreeItem *t = script_list->create_item(s_root);
298-
t->set_text(0, TTR("[Default]"));
310+
t->set_text(0, TTRC("[Default]"));
299311
t->set_metadata(0, "");
300312
}
301313

@@ -323,7 +335,7 @@ void EditorLocaleDialog::_update_tree() {
323335

324336
if (!is_edit_mode) {
325337
TreeItem *t = cnt_list->create_item(c_root);
326-
t->set_text(0, TTR("[Default]"));
338+
t->set_text(0, TTRC("[Default]"));
327339
t->set_metadata(0, "");
328340
}
329341

@@ -389,32 +401,32 @@ void EditorLocaleDialog::popup_locale_dialog() {
389401
}
390402

391403
EditorLocaleDialog::EditorLocaleDialog() {
392-
set_title(TTR("Select a Locale"));
404+
set_title(TTRC("Select a Locale"));
393405

394406
VBoxContainer *vb = memnew(VBoxContainer);
395407
{
396408
HBoxContainer *hb_filter = memnew(HBoxContainer);
397409
{
398410
filter_mode = memnew(OptionButton);
399411
filter_mode->set_accessibility_name(TTRC("Locale Filter"));
400-
filter_mode->add_item(TTR("Show All Locales"), SHOW_ALL_LOCALES);
412+
filter_mode->add_item(TTRC("Show All Locales"), SHOW_ALL_LOCALES);
401413
filter_mode->set_h_size_flags(Control::SIZE_EXPAND_FILL);
402-
filter_mode->add_item(TTR("Show Selected Locales Only"), SHOW_ONLY_SELECTED_LOCALES);
414+
filter_mode->add_item(TTRC("Show Selected Locales Only"), SHOW_ONLY_SELECTED_LOCALES);
403415
filter_mode->select(0);
404416
filter_mode->connect(SceneStringName(item_selected), callable_mp(this, &EditorLocaleDialog::_filter_mode_changed));
405417
hb_filter->add_child(filter_mode);
406418
}
407419
{
408420
edit_filters = memnew(CheckButton);
409-
edit_filters->set_text(TTR("Edit Filters"));
421+
edit_filters->set_text(TTRC("Edit Filters"));
410422
edit_filters->set_toggle_mode(true);
411423
edit_filters->set_pressed(false);
412424
edit_filters->connect(SceneStringName(toggled), callable_mp(this, &EditorLocaleDialog::_edit_filters));
413425
hb_filter->add_child(edit_filters);
414426
}
415427
{
416428
advanced = memnew(CheckButton);
417-
advanced->set_text(TTR("Advanced"));
429+
advanced->set_text(TTRC("Advanced"));
418430
advanced->set_toggle_mode(true);
419431
advanced->set_pressed(false);
420432
advanced->connect(SceneStringName(toggled), callable_mp(this, &EditorLocaleDialog::_toggle_advanced));
@@ -430,7 +442,7 @@ EditorLocaleDialog::EditorLocaleDialog() {
430442
vb_lang_list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
431443
{
432444
Label *lang_lbl = memnew(Label);
433-
lang_lbl->set_text(TTR("Language:"));
445+
lang_lbl->set_text(TTRC("Language:"));
434446
vb_lang_list->add_child(lang_lbl);
435447
}
436448
{
@@ -449,14 +461,12 @@ EditorLocaleDialog::EditorLocaleDialog() {
449461
vb_script_list = memnew(VBoxContainer);
450462
vb_script_list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
451463
{
452-
Label *script_lbl = memnew(Label);
453-
// TRANSLATORS: This is the label for a list of writing systems.
454-
script_lbl->set_text(TTR("Script:", "Locale"));
455-
vb_script_list->add_child(script_lbl);
464+
script_label1 = memnew(Label);
465+
script_label1->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
466+
vb_script_list->add_child(script_label1);
456467
}
457468
{
458469
script_list = memnew(Tree);
459-
script_list->set_accessibility_name(TTR("Script", "Locale"));
460470
script_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
461471
script_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
462472
script_list->connect("cell_selected", callable_mp(this, &EditorLocaleDialog::_item_selected));
@@ -471,7 +481,7 @@ EditorLocaleDialog::EditorLocaleDialog() {
471481
vb_cnt_list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
472482
{
473483
Label *cnt_lbl = memnew(Label);
474-
cnt_lbl->set_text(TTR("Country:"));
484+
cnt_lbl->set_text(TTRC("Country:"));
475485
vb_cnt_list->add_child(cnt_lbl);
476486
}
477487
{
@@ -497,7 +507,7 @@ EditorLocaleDialog::EditorLocaleDialog() {
497507
vb_language->set_h_size_flags(Control::SIZE_EXPAND_FILL);
498508
{
499509
Label *language_lbl = memnew(Label);
500-
language_lbl->set_text(TTR("Language"));
510+
language_lbl->set_text(TTRC("Language"));
501511
vb_language->add_child(language_lbl);
502512
}
503513
{
@@ -512,15 +522,13 @@ EditorLocaleDialog::EditorLocaleDialog() {
512522
VBoxContainer *vb_script = memnew(VBoxContainer);
513523
vb_script->set_h_size_flags(Control::SIZE_EXPAND_FILL);
514524
{
515-
Label *script_lbl = memnew(Label);
516-
// TRANSLATORS: This refers to a writing system.
517-
script_lbl->set_text(TTR("Script", "Locale"));
518-
vb_script->add_child(script_lbl);
525+
script_label2 = memnew(Label);
526+
script_label2->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
527+
vb_script->add_child(script_label2);
519528
}
520529
{
521530
script_code = memnew(LineEdit);
522531
script_code->set_max_length(4);
523-
script_code->set_accessibility_name("Script");
524532
vb_script->add_child(script_code);
525533
}
526534
hb_locale->add_child(vb_script);
@@ -530,7 +538,7 @@ EditorLocaleDialog::EditorLocaleDialog() {
530538
vb_country->set_h_size_flags(Control::SIZE_EXPAND_FILL);
531539
{
532540
Label *country_lbl = memnew(Label);
533-
country_lbl->set_text(TTR("Country"));
541+
country_lbl->set_text(TTRC("Country"));
534542
vb_country->add_child(country_lbl);
535543
}
536544
{
@@ -546,7 +554,7 @@ EditorLocaleDialog::EditorLocaleDialog() {
546554
vb_variant->set_h_size_flags(Control::SIZE_EXPAND_FILL);
547555
{
548556
Label *variant_lbl = memnew(Label);
549-
variant_lbl->set_text(TTR("Variant"));
557+
variant_lbl->set_text(TTRC("Variant"));
550558
vb_variant->add_child(variant_lbl);
551559
}
552560
{
@@ -564,5 +572,5 @@ EditorLocaleDialog::EditorLocaleDialog() {
564572
add_child(vb);
565573
_update_tree();
566574

567-
set_ok_button_text(TTR("Select"));
575+
set_ok_button_text(TTRC("Select"));
568576
}

editor/editor_locale_dialog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ class EditorLocaleDialog : public ConfirmationDialog {
6060
Tree *script_list = nullptr;
6161
Tree *cnt_list = nullptr;
6262

63+
Label *script_label1 = nullptr;
64+
Label *script_label2 = nullptr;
65+
6366
bool locale_set = false;
6467
bool updating_lists = false;
6568

6669
protected:
70+
void _notification(int p_what);
6771
static void _bind_methods();
6872
virtual void _post_popup() override;
6973
virtual void ok_pressed() override;

editor/editor_sectioned_inspector.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void SectionedInspector::_search_changed(const String &p_what) {
326326
} else {
327327
advanced_toggle->set_pressed_no_signal(true);
328328
advanced_toggle->set_disabled(true);
329-
advanced_toggle->set_tooltip_text(TTR("Advanced settings are always shown when searching."));
329+
advanced_toggle->set_tooltip_text(TTRC("Advanced settings are always shown when searching."));
330330
}
331331
}
332332
update_category_list();
@@ -338,6 +338,15 @@ void SectionedInspector::_advanced_toggled(bool p_toggled_on) {
338338
inspector->set_restrict_to_basic_settings(restrict_to_basic);
339339
}
340340

341+
void SectionedInspector::_notification(int p_notification) {
342+
if (p_notification == NOTIFICATION_TRANSLATION_CHANGED) {
343+
if (sections->get_root()) {
344+
// Only update when initialized.
345+
callable_mp(this, &SectionedInspector::update_category_list).call_deferred();
346+
}
347+
}
348+
}
349+
341350
EditorInspector *SectionedInspector::get_inspector() {
342351
return inspector;
343352
}

0 commit comments

Comments
 (0)