Skip to content

Commit

Permalink
Merge pull request #87530 from YeldhamDev/atr_inheritance
Browse files Browse the repository at this point in the history
Rework the auto translation system
  • Loading branch information
akien-mga committed Feb 17, 2024
2 parents e31b253 + 7b42c24 commit 2c5fa95
Show file tree
Hide file tree
Showing 51 changed files with 282 additions and 134 deletions.
3 changes: 1 addition & 2 deletions doc/classes/Control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,8 @@
<member name="anchor_top" type="float" setter="_set_anchor" getter="get_anchor" default="0.0">
Anchors the top edge of the node to the origin, the center or the end of its parent control. It changes how the top offset updates when the node moves or changes size. You can use one of the [enum Anchor] constants for convenience.
</member>
<member name="auto_translate" type="bool" setter="set_auto_translate" getter="is_auto_translating" default="true">
<member name="auto_translate" type="bool" setter="set_auto_translate" getter="is_auto_translating" default="true" deprecated="Use [member Node.auto_translate_mode] instead.">
Toggles if any text should automatically change to its translated version depending on the current locale.
Also decides if the node's strings should be parsed for POT generation.
</member>
<member name="clip_contents" type="bool" setter="set_clip_contents" getter="is_clipping_contents" default="false">
Enables whether rendering of [CanvasItem] based children should be clipped to this control's rectangle. If [code]true[/code], parts of a child which would be visibly outside of this control's rectangle will not be rendered and won't receive input.
Expand Down
46 changes: 43 additions & 3 deletions doc/classes/Node.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,32 @@
[b]Note:[/b] [SceneTree]'s group methods will [i]not[/i] work on this node if not inside the tree (see [method is_inside_tree]).
</description>
</method>
<method name="atr" qualifiers="const">
<return type="String" />
<param index="0" name="message" type="String" />
<param index="1" name="context" type="StringName" default="&quot;&quot;" />
<description>
Translates a [param message], using the translation catalogs configured in the Project Settings. Further [param context] can be specified to help with the translation.
This method works the same as [method Object.tr], with the addition of respecting the [member auto_translate_mode] state.
If [method Object.can_translate_messages] is [code]false[/code], or no translation is available, this method returns the [param message] without changes. See [method Object.set_message_translation].
For detailed examples, see [url=$DOCS_URL/tutorials/i18n/internationalizing_games.html]Internationalizing games[/url].
</description>
</method>
<method name="atr_n" qualifiers="const">
<return type="String" />
<param index="0" name="message" type="String" />
<param index="1" name="plural_message" type="StringName" />
<param index="2" name="n" type="int" />
<param index="3" name="context" type="StringName" default="&quot;&quot;" />
<description>
Translates a [param message] or [param plural_message], using the translation catalogs configured in the Project Settings. Further [param context] can be specified to help with the translation.
This method works the same as [method Object.tr_n], with the addition of respecting the [member auto_translate_mode] state.
If [method Object.can_translate_messages] is [code]false[/code], or no translation is available, this method returns [param message] or [param plural_message], without changes. See [method Object.set_message_translation].
The [param n] is the number, or amount, of the message's subject. It is used by the translation system to fetch the correct plural form for the current language.
For detailed examples, see [url=$DOCS_URL/tutorials/i18n/localization_using_gettext.html]Localization using gettext[/url].
[b]Note:[/b] Negative and [float] numbers may not properly apply to some countable subjects. It's recommended to handle these cases with [method atr].
</description>
</method>
<method name="call_deferred_thread_group" qualifiers="vararg">
<return type="Variant" />
<param index="0" name="method" type="StringName" />
Expand All @@ -203,7 +229,7 @@
<method name="can_process" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if the node can receive processing notifications and input callbacks ([constant NOTIFICATION_PROCESS], [method _input], etc) from the [SceneTree] and [Viewport]. The returned value depends on [member process_mode]:
Returns [code]true[/code] if the node can receive processing notifications and input callbacks ([constant NOTIFICATION_PROCESS], [method _input], etc.) from the [SceneTree] and [Viewport]. The returned value depends on [member process_mode]:
- If set to [constant PROCESS_MODE_PAUSABLE], returns [code]true[/code] when the game is processing, i.e. [member SceneTree.paused] is [code]false[/code];
- If set to [constant PROCESS_MODE_WHEN_PAUSED], returns [code]true[/code] when the game is paused, i.e. [member SceneTree.paused] is [code]true[/code];
- If set to [constant PROCESS_MODE_ALWAYS], always returns [code]true[/code];
Expand Down Expand Up @@ -923,6 +949,10 @@
</method>
</methods>
<members>
<member name="auto_translate_mode" type="int" setter="set_auto_translate_mode" getter="get_auto_translate_mode" enum="Node.AutoTranslateMode" default="0">
Defines if any text should automatically change to its translated version depending on the current locale (for nodes such as [Label], [RichTextLabel], [Window], etc.). See [enum AutoTranslateMode].
Also decides if the node's strings should be parsed for POT generation.
</member>
<member name="editor_description" type="String" setter="set_editor_description" getter="get_editor_description" default="&quot;&quot;">
An optional description to the node. It will be displayed as a tooltip when hovering over the node in the editor's Scene dock.
</member>
Expand Down Expand Up @@ -1180,10 +1210,10 @@
Notification received when the [TextServer] is changed.
</constant>
<constant name="PROCESS_MODE_INHERIT" value="0" enum="ProcessMode">
Inherits [member process_mode] from the node's parent. For the root node, it is equivalent to [constant PROCESS_MODE_PAUSABLE]. This is the default for any newly created node.
Inherits [member process_mode] from the node's parent. This is the default for any newly created node.
</constant>
<constant name="PROCESS_MODE_PAUSABLE" value="1" enum="ProcessMode">
Stops processing when [member SceneTree.paused] is [code]true[/code]. This is the inverse of [constant PROCESS_MODE_WHEN_PAUSED].
Stops processing when [member SceneTree.paused] is [code]true[/code]. This is the inverse of [constant PROCESS_MODE_WHEN_PAUSED], and the default for the root node.
</constant>
<constant name="PROCESS_MODE_WHEN_PAUSED" value="2" enum="ProcessMode">
Process [b]only[/b] when [member SceneTree.paused] is [code]true[/code]. This is the inverse of [constant PROCESS_MODE_PAUSABLE].
Expand Down Expand Up @@ -1233,5 +1263,15 @@
<constant name="INTERNAL_MODE_BACK" value="2" enum="InternalMode">
The node will be placed at the end of the parent's children list, after any non-internal sibling.
</constant>
<constant name="AUTO_TRANSLATE_MODE_INHERIT" value="0" enum="AutoTranslateMode">
Inherits [member auto_translate_mode] from the node's parent. This is the default for any newly created node.
</constant>
<constant name="AUTO_TRANSLATE_MODE_ALWAYS" value="1" enum="AutoTranslateMode">
Always automatically translate. This is the inverse of [constant AUTO_TRANSLATE_MODE_DISABLED], and the default for the root node.
</constant>
<constant name="AUTO_TRANSLATE_MODE_DISABLED" value="2" enum="AutoTranslateMode">
Never automatically translate. This is the inverse of [constant AUTO_TRANSLATE_MODE_ALWAYS].
String parsing for POT generation will be skipped for this node and children that are set to [constant AUTO_TRANSLATE_MODE_INHERIT].
</constant>
</constants>
</class>
2 changes: 1 addition & 1 deletion doc/classes/Object.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@
If [method can_translate_messages] is [code]false[/code], or no translation is available, this method returns [param message] or [param plural_message], without changes. See [method set_message_translation].
The [param n] is the number, or amount, of the message's subject. It is used by the translation system to fetch the correct plural form for the current language.
For detailed examples, see [url=$DOCS_URL/tutorials/i18n/localization_using_gettext.html]Localization using gettext[/url].
[b]Note:[/b] Negative and [float] numbers may not properly apply to some countable subjects. It's recommended handling these cases with [method tr].
[b]Note:[/b] Negative and [float] numbers may not properly apply to some countable subjects. It's recommended to handle these cases with [method tr].
</description>
</method>
</methods>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Window.xml
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@
<member name="always_on_top" type="bool" setter="set_flag" getter="get_flag" default="false">
If [code]true[/code], the window will be on top of all other windows. Does not work if [member transient] is enabled.
</member>
<member name="auto_translate" type="bool" setter="set_auto_translate" getter="is_auto_translating" default="true">
<member name="auto_translate" type="bool" setter="set_auto_translate" getter="is_auto_translating" default="true" deprecated="Use [member Node.auto_translate_mode] instead.">
Toggles if any text should automatically change to its translated version depending on the current locale.
</member>
<member name="borderless" type="bool" setter="set_flag" getter="get_flag" default="false">
Expand Down
4 changes: 2 additions & 2 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7143,14 +7143,14 @@ AnimationTrackEditor::AnimationTrackEditor() {
transition_selection->add_item(TTR("Back", "Transition Type"), Tween::TRANS_BACK);
transition_selection->add_item(TTR("Spring", "Transition Type"), Tween::TRANS_SPRING);
transition_selection->select(Tween::TRANS_LINEAR); // Default
transition_selection->set_auto_translate(false); // Translation context is needed.
transition_selection->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Translation context is needed.
ease_selection = memnew(OptionButton);
ease_selection->add_item(TTR("In", "Ease Type"), Tween::EASE_IN);
ease_selection->add_item(TTR("Out", "Ease Type"), Tween::EASE_OUT);
ease_selection->add_item(TTR("InOut", "Ease Type"), Tween::EASE_IN_OUT);
ease_selection->add_item(TTR("OutIn", "Ease Type"), Tween::EASE_OUT_IN);
ease_selection->select(Tween::EASE_IN_OUT); // Default
ease_selection->set_auto_translate(false); // Translation context is needed.
ease_selection->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Translation context is needed.
ease_fps = memnew(SpinBox);
ease_fps->set_min(1);
ease_fps->set_max(999);
Expand Down
2 changes: 1 addition & 1 deletion editor/create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ CreateDialog::CreateDialog() {
rec_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL);

recent = memnew(ItemList);
recent->set_auto_translate(false);
recent->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
rec_vb->add_margin_child(TTR("Recent:"), recent, true);
recent->set_allow_reselect(true);
recent->connect("item_selected", callable_mp(this, &CreateDialog::_history_selected));
Expand Down
2 changes: 1 addition & 1 deletion editor/dependency_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ DependencyEditorOwners::DependencyEditorOwners() {
file_options->connect("id_pressed", callable_mp(this, &DependencyEditorOwners::_file_option));

owners = memnew(ItemList);
owners->set_auto_translate(false);
owners->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
owners->set_select_mode(ItemList::SELECT_MULTI);
owners->connect("item_clicked", callable_mp(this, &DependencyEditorOwners::_list_rmb_clicked));
owners->connect("item_activated", callable_mp(this, &DependencyEditorOwners::_select_file));
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ ScrollContainer *EditorAbout::_populate_list(const String &p_name, const List<St
vbc->add_child(lbl);

ItemList *il = memnew(ItemList);
il->set_auto_translate(false);
il->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
il->set_h_size_flags(Control::SIZE_EXPAND_FILL);
il->set_same_column_width(true);
il->set_auto_height(true);
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_feature_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ EditorFeatureProfileManager::EditorFeatureProfileManager() {
HBoxContainer *profiles_hbc = memnew(HBoxContainer);
profile_list = memnew(OptionButton);
profile_list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
profile_list->set_auto_translate(false);
profile_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
profiles_hbc->add_child(profile_list);
profile_list->connect("item_selected", callable_mp(this, &EditorFeatureProfileManager::_profile_selected));

Expand Down
2 changes: 1 addition & 1 deletion editor/editor_layouts_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ EditorLayoutsDialog::EditorLayoutsDialog() {
add_child(makevb);

layout_names = memnew(ItemList);
layout_names->set_auto_translate(false);
layout_names->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
layout_names->set_auto_height(true);
layout_names->set_custom_minimum_size(Size2(300 * EDSCALE, 50 * EDSCALE));
layout_names->set_visible(true);
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6949,7 +6949,7 @@ EditorNode::EditorNode() {

editor_layouts = memnew(PopupMenu);
editor_layouts->set_name("Layouts");
editor_layouts->set_auto_translate(false);
editor_layouts->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
settings_menu->add_child(editor_layouts);
editor_layouts->connect("id_pressed", callable_mp(this, &EditorNode::_layout_menu_option));
settings_menu->add_submenu_item(TTR("Editor Layout"), "Layouts");
Expand Down
6 changes: 3 additions & 3 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ EditorPropertyTextEnum::EditorPropertyTextEnum() {
option_button->set_h_size_flags(SIZE_EXPAND_FILL);
option_button->set_clip_text(true);
option_button->set_flat(true);
option_button->set_auto_translate(false);
option_button->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
default_layout->add_child(option_button);
option_button->connect("item_selected", callable_mp(this, &EditorPropertyTextEnum::_option_selected));

Expand Down Expand Up @@ -728,7 +728,7 @@ EditorPropertyEnum::EditorPropertyEnum() {
options = memnew(OptionButton);
options->set_clip_text(true);
options->set_flat(true);
options->set_auto_translate(false);
options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
add_child(options);
add_focusable(options);
options->connect("item_selected", callable_mp(this, &EditorPropertyEnum::_option_selected));
Expand Down Expand Up @@ -2955,7 +2955,7 @@ EditorPropertyNodePath::EditorPropertyNodePath() {
assign->set_flat(true);
assign->set_h_size_flags(SIZE_EXPAND_FILL);
assign->set_clip_text(true);
assign->set_auto_translate(false);
assign->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
assign->set_expand_icon(true);
assign->connect("pressed", callable_mp(this, &EditorPropertyNodePath::_node_assign));
SET_DRAG_FORWARDING_CD(assign, EditorPropertyNodePath);
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_resource_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ EditorResourcePicker::EditorResourcePicker(bool p_hide_assign_button_controls) {
assign_button->set_h_size_flags(SIZE_EXPAND_FILL);
assign_button->set_expand_icon(true);
assign_button->set_clip_text(true);
assign_button->set_auto_translate(false);
assign_button->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
SET_DRAG_FORWARDING_GCD(assign_button, EditorResourcePicker);
add_child(assign_button);
assign_button->connect("pressed", callable_mp(this, &EditorResourcePicker::_resource_selected));
Expand Down
2 changes: 1 addition & 1 deletion editor/export/project_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ ProjectExportDialog::ProjectExportDialog() {
preset_vb->add_child(mc);
mc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
presets = memnew(ItemList);
presets->set_auto_translate(false);
presets->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
SET_DRAG_FORWARDING_GCD(presets, ProjectExportDialog);
mc->add_child(presets);
presets->connect("item_selected", callable_mp(this, &ProjectExportDialog::_edit_preset));
Expand Down
6 changes: 3 additions & 3 deletions editor/gui/editor_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ EditorFileDialog::EditorFileDialog() {
fav_down->connect("pressed", callable_mp(this, &EditorFileDialog::_favorite_move_down));

favorites = memnew(ItemList);
favorites->set_auto_translate(false);
favorites->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
fav_vb->add_child(favorites);
favorites->set_v_size_flags(Control::SIZE_EXPAND_FILL);
favorites->connect("item_selected", callable_mp(this, &EditorFileDialog::_favorite_selected));
Expand All @@ -1920,7 +1920,7 @@ EditorFileDialog::EditorFileDialog() {
rec_vb->set_custom_minimum_size(Size2(150, 100) * EDSCALE);
rec_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
recent = memnew(ItemList);
recent->set_auto_translate(false);
recent->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
recent->set_allow_reselect(true);
rec_vb->add_margin_child(TTR("Recent:"), recent, true);
recent->connect("item_selected", callable_mp(this, &EditorFileDialog::_recent_selected));
Expand All @@ -1944,7 +1944,7 @@ EditorFileDialog::EditorFileDialog() {
// Item (files and folders) list with context menu.

item_list = memnew(ItemList);
item_list->set_auto_translate(false);
item_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
item_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
item_list->connect("item_clicked", callable_mp(this, &EditorFileDialog::_item_list_item_rmb_clicked));
item_list->connect("empty_clicked", callable_mp(this, &EditorFileDialog::_item_list_empty_clicked));
Expand Down
4 changes: 2 additions & 2 deletions editor/gui/editor_object_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ EditorObjectSelector::EditorObjectSelector(EditorSelectionHistory *p_history) {
current_object_label = memnew(Label);
current_object_label->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
current_object_label->set_h_size_flags(SIZE_EXPAND_FILL);
current_object_label->set_auto_translate(false);
current_object_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
main_hb->add_child(current_object_label);

sub_objects_icon = memnew(TextureRect);
Expand All @@ -247,7 +247,7 @@ EditorObjectSelector::EditorObjectSelector(EditorSelectionHistory *p_history) {
main_hb->add_child(sub_objects_icon);

sub_objects_menu = memnew(PopupMenu);
sub_objects_menu->set_auto_translate(false);
sub_objects_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
add_child(sub_objects_menu);
sub_objects_menu->connect("about_to_popup", callable_mp(this, &EditorObjectSelector::_about_to_show));
sub_objects_menu->connect("id_pressed", callable_mp(this, &EditorObjectSelector::_id_pressed));
Expand Down
2 changes: 1 addition & 1 deletion editor/gui/editor_scene_tabs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ EditorSceneTabs::EditorSceneTabs() {
scene_tabs->set_tab_close_display_policy((TabBar::CloseButtonDisplayPolicy)EDITOR_GET("interface/scene_tabs/display_close_button").operator int());
scene_tabs->set_max_tab_width(int(EDITOR_GET("interface/scene_tabs/maximum_width")) * EDSCALE);
scene_tabs->set_drag_to_rearrange_enabled(true);
scene_tabs->set_auto_translate(false);
scene_tabs->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
scene_tabs->set_h_size_flags(Control::SIZE_EXPAND_FILL);
tabbar_container->add_child(scene_tabs);

Expand Down
2 changes: 1 addition & 1 deletion editor/gui/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ void SceneTreeDialog::set_valid_types(const Vector<StringName> &p_valid) {
Label *label = memnew(Label);
hb->add_child(label);
label->set_text(name);
label->set_auto_translate(false);
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
}

show_all_nodes->show();
Expand Down
2 changes: 1 addition & 1 deletion editor/history_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ HistoryDock::HistoryDock() {
global_history_checkbox->connect("toggled", callable_mp(this, &HistoryDock::refresh_history).unbind(1));

action_list = memnew(ItemList);
action_list->set_auto_translate(false);
action_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
add_child(action_list);
action_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
action_list->connect("item_selected", callable_mp(this, &HistoryDock::seek_history));
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/animation_blend_space_1d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() {
animations_menu = memnew(PopupMenu);
menu->add_child(animations_menu);
animations_menu->set_name("AddAnimations");
animations_menu->set_auto_translate(false);
animations_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
animations_menu->connect("index_pressed", callable_mp(this, &AnimationNodeBlendSpace1DEditor::_add_animation_type));

open_file = memnew(EditorFileDialog);
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/animation_blend_space_2d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
animations_menu = memnew(PopupMenu);
menu->add_child(animations_menu);
animations_menu->set_name("AddAnimations");
animations_menu->set_auto_translate(false);
animations_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
animations_menu->connect("index_pressed", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_add_animation_type));

open_file = memnew(EditorFileDialog);
Expand Down
Loading

0 comments on commit 2c5fa95

Please sign in to comment.