Merge pull request #110378 from timothyqiu/rtl-preview

Make text-related nodes translation domain aware
This commit is contained in:
Thaddeus Crews
2025-10-16 12:48:05 -05:00
23 changed files with 132 additions and 101 deletions

View File

@@ -39,7 +39,6 @@
#include "core/os/os.h"
#include "core/string/alt_codes.h"
#include "core/string/string_builder.h"
#include "core/string/translation_server.h"
#include "scene/gui/label.h"
#include "scene/main/window.h"
#include "scene/theme/theme_db.h"
@@ -863,7 +862,7 @@ void TextEdit::_notification(int p_what) {
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_THEME_CHANGED: {
if (is_inside_tree()) {
_update_caches();
_update_caches(p_what == NOTIFICATION_TRANSLATION_CHANGED);
_update_wrap_at_column(true);
}
} break;
@@ -1435,7 +1434,7 @@ void TextEdit::_notification(int p_what) {
Ref<TextLine> tl;
tl.instantiate();
tl->add_string(txt, theme_cache.font, theme_cache.font_size);
tl->add_string(txt, theme_cache.font, theme_cache.font_size, _get_locale());
int yofs = ofs_y + (row_height - tl->get_size().y) / 2;
if (theme_cache.outline_size > 0 && theme_cache.outline_color.a > 0) {
@@ -3356,7 +3355,8 @@ void TextEdit::_update_placeholder() {
placeholder_data_buf->set_direction((TextServer::Direction)text_direction);
}
placeholder_data_buf->set_preserve_control(draw_control_chars);
placeholder_data_buf->add_string(placeholder_translated, theme_cache.font, theme_cache.font_size, language);
const String &lang = language.is_empty() ? _get_locale() : language;
placeholder_data_buf->add_string(placeholder_translated, theme_cache.font, theme_cache.font_size, lang);
placeholder_bidi_override = structured_text_parser(st_parser, st_args, placeholder_translated);
if (placeholder_bidi_override.is_empty()) {
@@ -3402,7 +3402,7 @@ void TextEdit::_update_theme_item_cache() {
}
}
void TextEdit::_update_caches() {
void TextEdit::_update_caches(bool p_invalidate_all) {
/* Text properties. */
TextServer::Direction dir;
if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
@@ -3410,11 +3410,16 @@ void TextEdit::_update_caches() {
} else {
dir = (TextServer::Direction)text_direction;
}
text.set_direction_and_language(dir, (!language.is_empty()) ? language : TranslationServer::get_singleton()->get_tool_locale());
const String &lang = language.is_empty() ? _get_locale() : language;
text.set_direction_and_language(dir, lang);
text.set_draw_control_chars(draw_control_chars);
text.set_font(theme_cache.font);
text.set_font_size(theme_cache.font_size);
text.invalidate_font();
if (p_invalidate_all) {
text.invalidate_all();
} else {
text.invalidate_font();
}
_update_placeholder();
/* Syntax highlighting. */
@@ -3741,8 +3746,9 @@ void TextEdit::set_text_direction(Control::TextDirection p_text_direction) {
} else {
dir = (TextServer::Direction)text_direction;
}
text.set_direction_and_language(dir, (!language.is_empty()) ? language : TranslationServer::get_singleton()->get_tool_locale());
text.invalidate_font();
const String &lang = language.is_empty() ? _get_locale() : language;
text.set_direction_and_language(dir, lang);
text.invalidate_all();
_update_placeholder();
if (menu_dir) {
@@ -3769,7 +3775,8 @@ void TextEdit::set_language(const String &p_language) {
} else {
dir = (TextServer::Direction)text_direction;
}
text.set_direction_and_language(dir, (!language.is_empty()) ? language : TranslationServer::get_singleton()->get_tool_locale());
const String &lang = language.is_empty() ? _get_locale() : language;
text.set_direction_and_language(dir, lang);
text.invalidate_all();
_update_placeholder();
queue_accessibility_update();