diff --git a/doc/classes/TreeItem.xml b/doc/classes/TreeItem.xml
index 861a53aaad10..132ecc3f9265 100644
--- a/doc/classes/TreeItem.xml
+++ b/doc/classes/TreeItem.xml
@@ -73,6 +73,13 @@
Removes the button at index [param button_index] in column [param column].
+
+
+
+
+ Returns the column's auto translate mode.
+
+
@@ -493,6 +500,15 @@
Selects the given [param column].
+
+
+
+
+
+ Sets the given column's auto translate mode to [param mode].
+ All columns use [constant Node.AUTO_TRANSLATE_MODE_INHERIT] by default, which uses the same auto translate mode as the [Tree] itself.
+
+
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index e4f52ee8ee06..8238d54381b5 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -185,6 +185,26 @@ TreeItem::TreeCellMode TreeItem::get_cell_mode(int p_column) const {
return cells[p_column].mode;
}
+/* auto translate mode */
+void TreeItem::set_auto_translate_mode(int p_column, Node::AutoTranslateMode p_mode) {
+ ERR_FAIL_INDEX(p_column, cells.size());
+
+ if (cells[p_column].auto_translate_mode == p_mode) {
+ return;
+ }
+
+ cells.write[p_column].auto_translate_mode = p_mode;
+ cells.write[p_column].dirty = true;
+ cells.write[p_column].cached_minimum_size_dirty = true;
+
+ _changed_notify(p_column);
+}
+
+Node::AutoTranslateMode TreeItem::get_auto_translate_mode(int p_column) const {
+ ERR_FAIL_INDEX_V(p_column, cells.size(), Node::AUTO_TRANSLATE_MODE_INHERIT);
+ return cells[p_column].auto_translate_mode;
+}
+
/* multiline editable */
void TreeItem::set_edit_multiline(int p_column, bool p_multiline) {
ERR_FAIL_INDEX(p_column, cells.size());
@@ -247,6 +267,24 @@ void TreeItem::propagate_check(int p_column, bool p_emit_signal) {
_propagate_check_through_parents(p_column, p_emit_signal);
}
+String TreeItem::atr(int p_column, const String &p_text) const {
+ ERR_FAIL_INDEX_V(p_column, cells.size(), tree->atr(p_text));
+
+ switch (cells[p_column].auto_translate_mode) {
+ case Node::AUTO_TRANSLATE_MODE_INHERIT: {
+ return tree->atr(p_text);
+ } break;
+ case Node::AUTO_TRANSLATE_MODE_ALWAYS: {
+ return tree->tr(p_text);
+ } break;
+ case Node::AUTO_TRANSLATE_MODE_DISABLED: {
+ return p_text;
+ } break;
+ }
+
+ ERR_FAIL_V_MSG(tree->atr(p_text), "Unexpected auto translate mode: " + itos(cells[p_column].auto_translate_mode));
+}
+
void TreeItem::_propagate_check_through_children(int p_column, bool p_checked, bool p_emit_signal) {
TreeItem *current = get_first_child();
while (current) {
@@ -323,7 +361,7 @@ void TreeItem::set_text(int p_column, String p_text) {
} else {
// Don't auto translate if it's in string mode and editable, as the text can be changed to anything by the user.
if (tree && (!cells[p_column].editable || cells[p_column].mode != TreeItem::CELL_MODE_STRING)) {
- cells.write[p_column].xl_text = tree->atr(p_text);
+ cells.write[p_column].xl_text = atr(p_column, p_text);
} else {
cells.write[p_column].xl_text = p_text;
}
@@ -1621,6 +1659,9 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_cell_mode", "column", "mode"), &TreeItem::set_cell_mode);
ClassDB::bind_method(D_METHOD("get_cell_mode", "column"), &TreeItem::get_cell_mode);
+ ClassDB::bind_method(D_METHOD("set_auto_translate_mode", "column", "mode"), &TreeItem::set_auto_translate_mode);
+ ClassDB::bind_method(D_METHOD("get_auto_translate_mode", "column"), &TreeItem::get_auto_translate_mode);
+
ClassDB::bind_method(D_METHOD("set_edit_multiline", "column", "multiline"), &TreeItem::set_edit_multiline);
ClassDB::bind_method(D_METHOD("is_edit_multiline", "column"), &TreeItem::is_edit_multiline);
@@ -2009,7 +2050,7 @@ void Tree::update_item_cell(TreeItem *p_item, int p_col) {
int option = (int)p_item->cells[p_col].val;
- valtext = atr(ETR("(Other)"));
+ valtext = p_item->atr(p_col, ETR("(Other)"));
Vector strings = p_item->cells[p_col].text.split(",");
for (int j = 0; j < strings.size(); j++) {
int value = j;
@@ -2017,7 +2058,7 @@ void Tree::update_item_cell(TreeItem *p_item, int p_col) {
value = strings[j].get_slicec(':', 1).to_int();
}
if (option == value) {
- valtext = atr(strings[j].get_slicec(':', 0));
+ valtext = p_item->atr(p_col, strings[j].get_slicec(':', 0));
break;
}
}
@@ -2028,7 +2069,7 @@ void Tree::update_item_cell(TreeItem *p_item, int p_col) {
} else {
// Don't auto translate if it's in string mode and editable, as the text can be changed to anything by the user.
if (!p_item->cells[p_col].editable || p_item->cells[p_col].mode != TreeItem::CELL_MODE_STRING) {
- p_item->cells.write[p_col].xl_text = atr(p_item->cells[p_col].text);
+ p_item->cells.write[p_col].xl_text = p_item->atr(p_col, p_item->cells[p_col].text);
} else {
p_item->cells.write[p_col].xl_text = p_item->cells[p_col].text;
}
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 17ea31a733f4..86efdfec522f 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -64,6 +64,7 @@ class TreeItem : public Object {
Rect2i icon_region;
String text;
String xl_text;
+ Node::AutoTranslateMode auto_translate_mode = Node::AUTO_TRANSLATE_MODE_INHERIT;
bool edit_multiline = false;
String suffix;
Ref text_buf;
@@ -210,6 +211,10 @@ class TreeItem : public Object {
void set_cell_mode(int p_column, TreeCellMode p_mode);
TreeCellMode get_cell_mode(int p_column) const;
+ /* auto translate mode */
+ void set_auto_translate_mode(int p_column, Node::AutoTranslateMode p_mode);
+ Node::AutoTranslateMode get_auto_translate_mode(int p_column) const;
+
/* multiline editable */
void set_edit_multiline(int p_column, bool p_multiline);
bool is_edit_multiline(int p_column) const;
@@ -222,6 +227,8 @@ class TreeItem : public Object {
void propagate_check(int p_column, bool p_emit_signal = true);
+ String atr(int p_column, const String &p_text) const;
+
private:
// Check helpers.
void _propagate_check_through_children(int p_column, bool p_checked, bool p_emit_signal);