Merge pull request #68784 from bruvzg/localize_numeral_system
Add `Control::localize_numeral_system` property to toggle automatic numeral system conversion.
This commit is contained in:
commit
dc28e82b74
|
@ -1010,6 +1010,10 @@
|
|||
<member name="layout_direction" type="int" setter="set_layout_direction" getter="get_layout_direction" enum="Control.LayoutDirection" default="0">
|
||||
Controls layout direction and text writing direction. Right-to-left layouts are necessary for certain languages (e.g. Arabic and Hebrew).
|
||||
</member>
|
||||
<member name="localize_numeral_system" type="bool" setter="set_localize_numeral_system" getter="is_localizing_numeral_system" default="true">
|
||||
If [code]true[/code], automatically converts code line numbers, list indices, [SpinBox] and [ProgressBar] values from the Western Arabic (0..9) to the numeral systems used in current locale.
|
||||
[b]Note:[/b] Numbers within the text are not automatically converted, it can be done manually, using [method TextServer.format_number].
|
||||
</member>
|
||||
<member name="mouse_default_cursor_shape" type="int" setter="set_default_cursor_shape" getter="get_default_cursor_shape" enum="Control.CursorShape" default="0">
|
||||
The default cursor shape for this control. Useful for Godot plugins and applications or games that use the system's mouse cursors.
|
||||
[b]Note:[/b] On Linux, shapes may vary depending on the cursor theme of the system.
|
||||
|
|
|
@ -1425,7 +1425,10 @@ bool CodeEdit::is_line_numbers_zero_padded() const {
|
|||
}
|
||||
|
||||
void CodeEdit::_line_number_draw_callback(int p_line, int p_gutter, const Rect2 &p_region) {
|
||||
String fc = TS->format_number(String::num(p_line + 1).lpad(line_number_digits, line_number_padding));
|
||||
String fc = String::num(p_line + 1).lpad(line_number_digits, line_number_padding);
|
||||
if (is_localizing_numeral_system()) {
|
||||
fc = TS->format_number(fc);
|
||||
}
|
||||
Ref<TextLine> tl;
|
||||
tl.instantiate();
|
||||
tl->add_string(fc, font, font_size);
|
||||
|
|
|
@ -2773,6 +2773,20 @@ bool Control::is_layout_rtl() const {
|
|||
return data.is_rtl;
|
||||
}
|
||||
|
||||
void Control::set_localize_numeral_system(bool p_enable) {
|
||||
if (p_enable == data.localize_numeral_system) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.localize_numeral_system = p_enable;
|
||||
|
||||
notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED);
|
||||
}
|
||||
|
||||
bool Control::is_localizing_numeral_system() const {
|
||||
return data.localize_numeral_system;
|
||||
}
|
||||
|
||||
void Control::set_auto_translate(bool p_enable) {
|
||||
if (p_enable == data.auto_translate) {
|
||||
return;
|
||||
|
@ -3154,6 +3168,9 @@ void Control::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Control::set_auto_translate);
|
||||
ClassDB::bind_method(D_METHOD("is_auto_translating"), &Control::is_auto_translating);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_localize_numeral_system", "enable"), &Control::set_localize_numeral_system);
|
||||
ClassDB::bind_method(D_METHOD("is_localizing_numeral_system"), &Control::is_localizing_numeral_system);
|
||||
|
||||
ADD_GROUP("Layout", "");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_contents"), "set_clip_contents", "is_clipping_contents");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "custom_minimum_size", PROPERTY_HINT_NONE, "suffix:px"), "set_custom_minimum_size", "get_custom_minimum_size");
|
||||
|
@ -3198,8 +3215,9 @@ void Control::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill:1,Expand:2,Shrink Center:4,Shrink End:8"), "set_v_size_flags", "get_v_size_flags");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio");
|
||||
|
||||
ADD_GROUP("Auto Translate", "");
|
||||
ADD_GROUP("Localization", "");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "localize_numeral_system"), "set_localize_numeral_system", "is_localizing_numeral_system");
|
||||
|
||||
ADD_GROUP("Tooltip", "tooltip_");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "tooltip_text", PROPERTY_HINT_MULTILINE_TEXT), "set_tooltip_text", "get_tooltip_text");
|
||||
|
|
|
@ -249,6 +249,7 @@ private:
|
|||
bool is_rtl = false;
|
||||
|
||||
bool auto_translate = true;
|
||||
bool localize_numeral_system = true;
|
||||
|
||||
// Extra properties.
|
||||
|
||||
|
@ -595,6 +596,9 @@ public:
|
|||
LayoutDirection get_layout_direction() const;
|
||||
virtual bool is_layout_rtl() const;
|
||||
|
||||
void set_localize_numeral_system(bool p_enable);
|
||||
bool is_localizing_numeral_system() const;
|
||||
|
||||
void set_auto_translate(bool p_enable);
|
||||
bool is_auto_translating() const;
|
||||
_FORCE_INLINE_ String atr(const String p_string) const {
|
||||
|
|
|
@ -103,7 +103,12 @@ void ProgressBar::_notification(int p_what) {
|
|||
}
|
||||
|
||||
if (show_percentage) {
|
||||
String txt = TS->format_number(itos(int(get_as_ratio() * 100))) + TS->percent_sign();
|
||||
String txt = itos(int(get_as_ratio() * 100));
|
||||
if (is_localizing_numeral_system()) {
|
||||
txt = TS->format_number(txt) + TS->percent_sign();
|
||||
} else {
|
||||
txt += String("%");
|
||||
}
|
||||
TextLine tl = TextLine(txt, theme_cache.font, theme_cache.font_size);
|
||||
Vector2 text_pos = (Point2(get_size().width - tl.get_size().x, get_size().height - tl.get_size().y) / 2).round();
|
||||
|
||||
|
|
|
@ -752,7 +752,10 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
|
|||
prefix = _prefix;
|
||||
break;
|
||||
} else if (list_items[i]->list_type == LIST_NUMBERS) {
|
||||
segment = TS->format_number(itos(list_index[i]), _find_language(l.from));
|
||||
segment = itos(list_index[i]);
|
||||
if (is_localizing_numeral_system()) {
|
||||
segment = TS->format_number(segment, _find_language(l.from));
|
||||
}
|
||||
} else if (list_items[i]->list_type == LIST_LETTERS) {
|
||||
segment = _letters(list_index[i], list_items[i]->capitalize);
|
||||
} else if (list_items[i]->list_type == LIST_ROMAN) {
|
||||
|
|
|
@ -40,7 +40,10 @@ Size2 SpinBox::get_minimum_size() const {
|
|||
}
|
||||
|
||||
void SpinBox::_value_changed(double p_value) {
|
||||
String value = TS->format_number(String::num(get_value(), Math::range_step_decimals(get_step())));
|
||||
String value = String::num(get_value(), Math::range_step_decimals(get_step()));
|
||||
if (is_localizing_numeral_system()) {
|
||||
value = TS->format_number(value);
|
||||
}
|
||||
|
||||
if (!line_edit->has_focus()) {
|
||||
if (!prefix.is_empty()) {
|
||||
|
|
Loading…
Reference in New Issue