Merge pull request #74117 from Animtim/RichTextLabel_LocalizationFix

Add translation support to RichTextLabel
This commit is contained in:
Rémi Verschelde 2023-04-11 19:40:07 +02:00
commit 23a3e3984b
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 13 additions and 14 deletions

View File

@ -34,6 +34,7 @@
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/os/keyboard.h" #include "core/os/keyboard.h"
#include "core/os/os.h" #include "core/os/os.h"
#include "core/string/translation.h"
#include "label.h" #include "label.h"
#include "scene/scene_string_names.h" #include "scene/scene_string_names.h"
#include "servers/display_server.h" #include "servers/display_server.h"
@ -1799,8 +1800,7 @@ void RichTextLabel::_notification(int p_what) {
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED: { case NOTIFICATION_TRANSLATION_CHANGED: {
_stop_thread(); _apply_translation();
main->first_invalid_line.store(0); //invalidate ALL
queue_redraw(); queue_redraw();
} break; } break;
@ -5123,13 +5123,17 @@ void RichTextLabel::set_text(const String &p_bbcode) {
if (text == p_bbcode) { if (text == p_bbcode) {
return; return;
} }
text = p_bbcode; text = p_bbcode;
_apply_translation();
}
void RichTextLabel::_apply_translation() {
String xl_text = atr(text);
if (use_bbcode) { if (use_bbcode) {
parse_bbcode(p_bbcode); parse_bbcode(xl_text);
} else { // raw text } else { // raw text
clear(); clear();
add_text(p_bbcode); add_text(xl_text);
} }
} }
@ -5144,13 +5148,7 @@ void RichTextLabel::set_use_bbcode(bool p_enable) {
use_bbcode = p_enable; use_bbcode = p_enable;
notify_property_list_changed(); notify_property_list_changed();
const String current_text = text; _apply_translation();
if (use_bbcode) {
parse_bbcode(current_text);
} else { // raw text
clear();
add_text(current_text);
}
} }
bool RichTextLabel::is_using_bbcode() const { bool RichTextLabel::is_using_bbcode() const {
@ -5285,7 +5283,7 @@ float RichTextLabel::get_visible_ratio() const {
void RichTextLabel::set_effects(Array p_effects) { void RichTextLabel::set_effects(Array p_effects) {
custom_effects = p_effects; custom_effects = p_effects;
if ((!text.is_empty()) && use_bbcode) { if ((!text.is_empty()) && use_bbcode) {
parse_bbcode(text); parse_bbcode(atr(text));
} }
} }
@ -5300,7 +5298,7 @@ void RichTextLabel::install_effect(const Variant effect) {
ERR_FAIL_COND_MSG(rteffect.is_null(), "Invalid RichTextEffect resource."); ERR_FAIL_COND_MSG(rteffect.is_null(), "Invalid RichTextEffect resource.");
custom_effects.push_back(effect); custom_effects.push_back(effect);
if ((!text.is_empty()) && use_bbcode) { if ((!text.is_empty()) && use_bbcode) {
parse_bbcode(text); parse_bbcode(atr(text));
} }
} }

View File

@ -527,6 +527,7 @@ private:
#endif #endif
bool use_bbcode = false; bool use_bbcode = false;
String text; String text;
void _apply_translation();
bool fit_content = false; bool fit_content = false;