diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index 8d7c6a1f16f9..9b4244728a9f 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -30,6 +30,7 @@ #include "animation_bezier_editor.h" +#include "core/string/translation_server.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" @@ -439,6 +440,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { } const Color accent = get_theme_color(SNAME("accent_color"), EditorStringName(Editor)); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); // Guides. { @@ -469,7 +471,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { draw_line(Point2(limit, i), Point2(right_limit, i), lc, Math::round(EDSCALE)); Color c = color; c.a *= 0.5; - draw_string(font, Point2(limit + 8, i - 2), TS->format_number(rtos(Math::snapped((iv + 1) * scale, step))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, c); + draw_string(font, Point2(limit + 8, i - 2), TS->format_number(rtos(Math::snapped((iv + 1) * scale, step)), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, c); } first = false; @@ -556,8 +558,8 @@ void AnimationBezierTrackEdit::_notification(int p_what) { ep.point_rect.size = bezier_icon->get_size(); if (selection.has(IntPair(i, j))) { draw_texture(selected_icon, ep.point_rect.position); - draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height(font_size) - 8), TTR("Time:") + " " + TS->format_number(rtos(Math::snapped(offset, 0.0001))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, accent); - draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + TS->format_number(rtos(Math::snapped(value, 0.001))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, accent); + draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height(font_size) - 8), TTR("Time:") + " " + TS->format_number(rtos(Math::snapped(offset, 0.0001)), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, accent); + draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + TS->format_number(rtos(Math::snapped(value, 0.001)), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, accent); } else { Color track_color = Color(1, 1, 1, 1); if (i != selected_track) { diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index c210ad0761b2..9428de8ca178 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -33,6 +33,7 @@ #include "animation_track_editor_plugins.h" #include "core/error/error_macros.h" #include "core/input/input.h" +#include "core/string/translation_server.h" #include "editor/animation_bezier_editor.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" @@ -2787,7 +2788,8 @@ String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const { } if (key_idx != -1) { - String text = TTR("Time (s):") + " " + TS->format_number(rtos(Math::snapped(animation->track_get_key_time(track, key_idx), SECOND_DECIMAL))) + "\n"; + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); + String text = TTR("Time (s):") + " " + TS->format_number(rtos(Math::snapped(animation->track_get_key_time(track, key_idx), SECOND_DECIMAL)), lang) + "\n"; switch (animation->track_get_type(track)) { case Animation::TYPE_POSITION_3D: { Vector3 t = animation->track_get_key_value(track, key_idx); @@ -8562,7 +8564,8 @@ String AnimationMarkerEdit::get_tooltip(const Point2 &p_pos) const { if (key_idx != -1) { String name = names[key_idx]; - String text = TTR("Time (s):") + " " + TS->format_number(rtos(Math::snapped(animation->get_marker_time(name), 0.0001))) + "\n"; + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); + String text = TTR("Time (s):") + " " + TS->format_number(rtos(Math::snapped(animation->get_marker_time(name), 0.0001)), lang) + "\n"; text += TTR("Marker:") + " " + name + "\n"; return text; } diff --git a/editor/debugger/editor_performance_profiler.cpp b/editor/debugger/editor_performance_profiler.cpp index 1ea9a6653478..1860e04a3f00 100644 --- a/editor/debugger/editor_performance_profiler.cpp +++ b/editor/debugger/editor_performance_profiler.cpp @@ -30,6 +30,7 @@ #include "editor_performance_profiler.h" +#include "core/string/translation_server.h" #include "editor/editor_property_name_processor.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" @@ -80,15 +81,16 @@ void EditorPerformanceProfiler::Monitor::reset() { } String EditorPerformanceProfiler::_create_label(float p_value, Performance::MonitorType p_type) { + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); switch (p_type) { case Performance::MONITOR_TYPE_MEMORY: { return String::humanize_size(p_value); } case Performance::MONITOR_TYPE_TIME: { - return TS->format_number(rtos(p_value * 1000).pad_decimals(2)) + " " + TTR("ms"); + return TS->format_number(rtos(p_value * 1000).pad_decimals(2), lang) + " " + TTR("ms"); } default: { - return TS->format_number(rtos(p_value)); + return TS->format_number(rtos(p_value), lang); } } } diff --git a/editor/debugger/editor_profiler.cpp b/editor/debugger/editor_profiler.cpp index 33fa208f70a3..79519ad8b851 100644 --- a/editor/debugger/editor_profiler.cpp +++ b/editor/debugger/editor_profiler.cpp @@ -32,6 +32,7 @@ #include "core/io/image.h" #include "core/os/os.h" +#include "core/string/translation_server.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/themes/editor_scale.h" @@ -121,19 +122,21 @@ static String _get_percent_txt(float p_value, float p_total) { p_total = 0.00001; } - return TS->format_number(String::num((p_value / p_total) * 100, 1)) + TS->percent_sign(); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); + return TS->format_number(String::num((p_value / p_total) * 100, 1), lang) + TS->percent_sign(lang); } String EditorProfiler::_get_time_as_text(const Metric &m, float p_time, int p_calls) { const int dmode = display_mode->get_selected(); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); if (dmode == DISPLAY_FRAME_TIME) { - return TS->format_number(rtos(p_time * 1000).pad_decimals(2)) + " " + TTR("ms"); + return TS->format_number(rtos(p_time * 1000).pad_decimals(2), lang) + " " + TTR("ms"); } else if (dmode == DISPLAY_AVERAGE_TIME) { if (p_calls == 0) { - return TS->format_number("0.00") + " " + TTR("ms"); + return TS->format_number("0.00", lang) + " " + TTR("ms"); } else { - return TS->format_number(rtos((p_time / p_calls) * 1000).pad_decimals(2)) + " " + TTR("ms"); + return TS->format_number(rtos((p_time / p_calls) * 1000).pad_decimals(2), lang) + " " + TTR("ms"); } } else if (dmode == DISPLAY_FRAME_PERCENT) { return _get_percent_txt(p_time, m.frame_time); diff --git a/editor/debugger/editor_visual_profiler.cpp b/editor/debugger/editor_visual_profiler.cpp index 9a83277e99af..b1c488f60117 100644 --- a/editor/debugger/editor_visual_profiler.cpp +++ b/editor/debugger/editor_visual_profiler.cpp @@ -32,6 +32,7 @@ #include "core/io/image.h" #include "core/os/os.h" +#include "core/string/translation_server.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/themes/editor_scale.h" @@ -117,11 +118,12 @@ void EditorVisualProfiler::clear() { String EditorVisualProfiler::_get_time_as_text(float p_time) { int dmode = display_mode->get_selected(); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); if (dmode == DISPLAY_FRAME_TIME) { - return TS->format_number(String::num(p_time, 2)) + " " + TTR("ms"); + return TS->format_number(String::num(p_time, 2), lang) + " " + TTR("ms"); } else if (dmode == DISPLAY_FRAME_PERCENT) { - return TS->format_number(String::num(p_time * 100 / graph_limit, 2)) + " " + TS->percent_sign(); + return TS->format_number(String::num(p_time * 100 / graph_limit, 2), lang) + " " + TS->percent_sign(lang); } return "err"; diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index b78aad172183..ba9d41ba1f76 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -33,7 +33,7 @@ #include "core/config/project_settings.h" #include "core/debugger/debugger_marshalls.h" #include "core/debugger/remote_debugger.h" -#include "core/io/marshalls.h" +#include "core/string/translation_server.h" #include "core/string/ustring.h" #include "core/version.h" #include "editor/debugger/debug_adapter/debug_adapter_protocol.h" @@ -849,7 +849,8 @@ void ScriptEditorDebugger::_set_reason_text(const String &p_reason, MessageType } reason->set_text(p_reason); - const PackedInt32Array boundaries = TS->string_get_word_breaks(p_reason, "", 80); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); + const PackedInt32Array boundaries = TS->string_get_word_breaks(p_reason, lang, 80); PackedStringArray lines; for (int i = 0; i < boundaries.size(); i += 2) { const int start = boundaries[i]; diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index ce75efa462ec..06535bc6f419 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -31,6 +31,7 @@ #include "editor_properties.h" #include "core/config/project_settings.h" +#include "core/string/translation_server.h" #include "editor/create_dialog.h" #include "editor/editor_node.h" #include "editor/editor_properties_array_dict.h" @@ -1564,7 +1565,8 @@ void EditorPropertyEasing::_draw_easing() { } else { decimals = 1; } - f->draw_string(ci, Point2(10, 10 + f->get_ascent(font_size)), TS->format_number(rtos(exp).pad_decimals(decimals)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); + f->draw_string(ci, Point2(10, 10 + f->get_ascent(font_size)), TS->format_number(rtos(exp).pad_decimals(decimals), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); } void EditorPropertyEasing::update_property() { @@ -1579,8 +1581,9 @@ void EditorPropertyEasing::_set_preset(int p_preset) { } void EditorPropertyEasing::_setup_spin() { + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); spin->setup_and_show(); - spin->get_line_edit()->set_text(TS->format_number(rtos(get_edited_property_value()))); + spin->get_line_edit()->set_text(TS->format_number(rtos(get_edited_property_value()), lang)); spin->show(); } diff --git a/editor/gui/editor_spin_slider.cpp b/editor/gui/editor_spin_slider.cpp index 27b6bbafb7ca..dcd9a6c72ad2 100644 --- a/editor/gui/editor_spin_slider.cpp +++ b/editor/gui/editor_spin_slider.cpp @@ -33,20 +33,23 @@ #include "core/input/input.h" #include "core/math/expression.h" #include "core/os/keyboard.h" +#include "core/string/translation_server.h" #include "editor/editor_settings.h" #include "editor/themes/editor_scale.h" #include "scene/theme/theme_db.h" String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const { + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); if (!read_only && grabber->is_visible()) { Key key = (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) ? Key::META : Key::CTRL; - return TS->format_number(rtos(get_value())) + "\n\n" + vformat(TTR("Hold %s to round to integers.\nHold Shift for more precise changes."), find_keycode_name(key)); + return TS->format_number(rtos(get_value()), lang) + "\n\n" + vformat(TTR("Hold %s to round to integers.\nHold Shift for more precise changes."), find_keycode_name(key)); } - return TS->format_number(rtos(get_value())); + return TS->format_number(rtos(get_value()), lang); } String EditorSpinSlider::get_text_value() const { - return TS->format_number(String::num(get_value(), Math::range_step_decimals(get_step()))); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); + return TS->format_number(String::num(get_value(), Math::range_step_decimals(get_step())), lang); } void EditorSpinSlider::gui_input(const Ref &p_event) { @@ -350,7 +353,8 @@ void EditorSpinSlider::_draw_spin_slider() { int suffix_start = numstr.length(); RID num_rid = TS->create_shaped_text(); - TS->shaped_text_add_string(num_rid, numstr + U"\u2009" + suffix, font->get_rids(), font_size, font->get_opentype_features()); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); + TS->shaped_text_add_string(num_rid, numstr + U"\u2009" + suffix, font->get_rids(), font_size, font->get_opentype_features(), lang); float text_start = rtl ? Math::round(sb->get_offset().x) : Math::round(sb->get_offset().x + label_width + sep); Vector2 text_ofs = rtl ? Vector2(text_start + (number_width - TS->shaped_text_get_width(num_rid)), vofs) : Vector2(text_start, vofs); @@ -548,19 +552,21 @@ String EditorSpinSlider::get_suffix() const { } void EditorSpinSlider::_evaluate_input_text() { + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); + Ref expr; expr.instantiate(); // Convert commas ',' to dots '.' for French/German etc. keyboard layouts. String text = value_input->get_text().replace(",", "."); text = text.replace(";", ","); - text = TS->parse_number(text); + text = TS->parse_number(text, lang); Error err = expr->parse(text); if (err != OK) { // If the expression failed try without converting commas to dots - they might have been for parameter separation. text = value_input->get_text(); - text = TS->parse_number(text); + text = TS->parse_number(text, lang); err = expr->parse(text); if (err != OK) { diff --git a/editor/gui/editor_zoom_widget.cpp b/editor/gui/editor_zoom_widget.cpp index ff232a854f21..a05c513d6cba 100644 --- a/editor/gui/editor_zoom_widget.cpp +++ b/editor/gui/editor_zoom_widget.cpp @@ -31,22 +31,24 @@ #include "editor_zoom_widget.h" #include "core/os/keyboard.h" +#include "core/string/translation_server.h" #include "editor/editor_settings.h" #include "editor/themes/editor_scale.h" void EditorZoomWidget::_update_zoom_label() { + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); String zoom_text; // The zoom level displayed is relative to the editor scale // (like in most image editors). Its lower bound is clamped to 1 as some people // lower the editor scale to increase the available real estate, // even if their display doesn't have a particularly low DPI. if (zoom >= 10) { - zoom_text = TS->format_number(rtos(Math::round((zoom / MAX(1, EDSCALE)) * 100))); + zoom_text = TS->format_number(rtos(Math::round((zoom / MAX(1, EDSCALE)) * 100)), lang); } else { // 2 decimal places if the zoom is below 10%, 1 decimal place if it's below 1000%. - zoom_text = TS->format_number(rtos(Math::snapped((zoom / MAX(1, EDSCALE)) * 100, (zoom >= 0.1) ? 0.1 : 0.01))); + zoom_text = TS->format_number(rtos(Math::snapped((zoom / MAX(1, EDSCALE)) * 100, (zoom >= 0.1) ? 0.1 : 0.01)), lang); } - zoom_text += " " + TS->percent_sign(); + zoom_text += " " + TS->percent_sign(lang); zoom_reset->set_text(zoom_text); } diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index 2e36b66025a2..e2fd1ca6f7cb 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -32,6 +32,7 @@ #include "core/config/project_settings.h" #include "core/object/script_language.h" +#include "core/string/translation_server.h" #include "editor/editor_dock_manager.h" #include "editor/editor_file_system.h" #include "editor/editor_node.h" @@ -144,7 +145,8 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i // Limit the line width while keeping some padding. // It is not efficient, but it does not have to be. - const PackedInt32Array boundaries = TS->string_get_word_breaks(all_warnings, "", 80); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); + const PackedInt32Array boundaries = TS->string_get_word_breaks(all_warnings, lang, 80); PackedStringArray lines; for (int i = 0; i < boundaries.size(); i += 2) { const int start = boundaries[i]; @@ -531,7 +533,8 @@ void SceneTreeEditor::_update_node_tooltip(Node *p_node, TreeItem *p_item) { tooltip += "\n" + TTR("Type:") + " " + (custom_type != StringName() ? String(custom_type) : p_node->get_class()); if (!p_node->get_editor_description().is_empty()) { - const PackedInt32Array boundaries = TS->string_get_word_breaks(p_node->get_editor_description(), "", 80); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); + const PackedInt32Array boundaries = TS->string_get_word_breaks(p_node->get_editor_description(), lang, 80); tooltip += "\n"; for (int i = 0; i < boundaries.size(); i += 2) { diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index e3cf3dbbf211..cff14d9efc2a 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -33,6 +33,7 @@ #include "core/config/project_settings.h" #include "core/input/input.h" #include "core/os/keyboard.h" +#include "core/string/translation_server.h" #include "editor/debugger/editor_debugger_node.h" #include "editor/editor_main_screen.h" #include "editor/editor_node.h" @@ -2857,14 +2858,16 @@ void CanvasItemEditor::_draw_text_at_position(Point2 p_position, const String &p } void CanvasItemEditor::_draw_margin_at_position(int p_value, Point2 p_position, Side p_side) { - String str = TS->format_number(vformat("%d " + TTR("px"), p_value)); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); + String str = TS->format_number(vformat("%d " + TTR("px"), p_value), lang); if (p_value != 0) { _draw_text_at_position(p_position, str, p_side); } } void CanvasItemEditor::_draw_percentage_at_position(real_t p_value, Point2 p_position, Side p_side) { - String str = TS->format_number(vformat("%.1f ", p_value * 100.0)) + TS->percent_sign(); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); + String str = TS->format_number(vformat("%.1f ", p_value * 100.0), lang) + TS->percent_sign(lang); if (p_value != 0) { _draw_text_at_position(p_position, str, p_side); } @@ -2906,8 +2909,9 @@ void CanvasItemEditor::_draw_guides() { Color text_color = get_theme_color(SceneStringName(font_color), EditorStringName(Editor)); Color outline_color = text_color.inverted(); const float outline_size = 2; + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); if (drag_type == DRAG_DOUBLE_GUIDE || drag_type == DRAG_V_GUIDE) { - String str = TS->format_number(vformat("%d px", Math::round(xform.affine_inverse().xform(dragged_guide_pos).x))); + String str = TS->format_number(vformat("%d px", Math::round(xform.affine_inverse().xform(dragged_guide_pos).x)), lang); Ref font = get_theme_font(SNAME("bold"), EditorStringName(EditorFonts)); int font_size = 1.3 * get_theme_font_size(SNAME("bold_size"), EditorStringName(EditorFonts)); Size2 text_size = font->get_string_size(str, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size); @@ -2916,7 +2920,7 @@ void CanvasItemEditor::_draw_guides() { viewport->draw_line(Point2(dragged_guide_pos.x, 0), Point2(dragged_guide_pos.x, viewport->get_size().y), guide_color, Math::round(EDSCALE)); } if (drag_type == DRAG_DOUBLE_GUIDE || drag_type == DRAG_H_GUIDE) { - String str = TS->format_number(vformat("%d px", Math::round(xform.affine_inverse().xform(dragged_guide_pos).y))); + String str = TS->format_number(vformat("%d px", Math::round(xform.affine_inverse().xform(dragged_guide_pos).y)), lang); Ref font = get_theme_font(SNAME("bold"), EditorStringName(EditorFonts)); int font_size = 1.3 * get_theme_font_size(SNAME("bold_size"), EditorStringName(EditorFonts)); Size2 text_size = font->get_string_size(str, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size); @@ -2947,6 +2951,7 @@ void CanvasItemEditor::_draw_rulers() { font_color.a = 0.8; Ref font = get_theme_font(SNAME("rulers"), EditorStringName(EditorFonts)); int font_size = get_theme_font_size(SNAME("rulers_size"), EditorStringName(EditorFonts)); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); // The rule transform Transform2D ruler_transform; @@ -2993,7 +2998,7 @@ void CanvasItemEditor::_draw_rulers() { if (i % (major_subdivision * minor_subdivision) == 0) { viewport->draw_line(Point2(position.x, 0), Point2(position.x, RULER_WIDTH), graduation_color, Math::round(EDSCALE)); real_t val = (ruler_transform * major_subdivide * minor_subdivide).xform(Point2(i, 0)).x; - viewport->draw_string(font, Point2(position.x + 2, font->get_height(font_size)), TS->format_number(vformat(((int)val == val) ? "%d" : "%.1f", val)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); + viewport->draw_string(font, Point2(position.x + 2, font->get_height(font_size)), TS->format_number(vformat(((int)val == val) ? "%d" : "%.1f", val), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); } else { if (i % minor_subdivision == 0) { viewport->draw_line(Point2(position.x, RULER_WIDTH * 0.33), Point2(position.x, RULER_WIDTH), graduation_color, Math::round(EDSCALE)); @@ -3013,7 +3018,7 @@ void CanvasItemEditor::_draw_rulers() { Transform2D text_xform = Transform2D(-Math_PI / 2.0, Point2(font->get_height(font_size), position.y - 2)); viewport->draw_set_transform_matrix(viewport->get_transform() * text_xform); - viewport->draw_string(font, Point2(), TS->format_number(vformat(((int)val == val) ? "%d" : "%.1f", val)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); + viewport->draw_string(font, Point2(), TS->format_number(vformat(((int)val == val) ? "%d" : "%.1f", val), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); viewport->draw_set_transform_matrix(viewport->get_transform()); } else { @@ -3179,8 +3184,9 @@ void CanvasItemEditor::_draw_ruler_tool() { return; } - viewport->draw_string_outline(font, text_pos, TS->format_number(vformat("%.1f px", length_vector.length())), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); - viewport->draw_string(font, text_pos, TS->format_number(vformat("%.1f px", length_vector.length())), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); + viewport->draw_string_outline(font, text_pos, TS->format_number(vformat("%.1f px", length_vector.length()), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); + viewport->draw_string(font, text_pos, TS->format_number(vformat("%.1f px", length_vector.length()), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); if (draw_secondary_lines) { const int horizontal_angle = round(180 * horizontal_angle_rad / Math_PI); @@ -3188,19 +3194,19 @@ void CanvasItemEditor::_draw_ruler_tool() { Point2 text_pos2 = text_pos; text_pos2.x = begin.x < text_pos.x ? MIN(text_pos.x - text_width, begin.x - text_width / 2) : MAX(text_pos.x + text_width, begin.x - text_width / 2); - viewport->draw_string_outline(font, text_pos2, TS->format_number(vformat("%.1f px", length_vector.y)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); - viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.1f px", length_vector.y)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); + viewport->draw_string_outline(font, text_pos2, TS->format_number(vformat("%.1f px", length_vector.y), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); + viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.1f px", length_vector.y), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); Point2 v_angle_text_pos; v_angle_text_pos.x = CLAMP(begin.x - angle_text_width / 2, angle_text_width / 2, viewport->get_rect().size.x - angle_text_width); v_angle_text_pos.y = begin.y < end.y ? MIN(text_pos2.y - 2 * text_height, begin.y - text_height * 0.5) : MAX(text_pos2.y + text_height * 3, begin.y + text_height * 1.5); - viewport->draw_string_outline(font, v_angle_text_pos, TS->format_number(vformat(U"%d°", vertical_angle)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); - viewport->draw_string(font, v_angle_text_pos, TS->format_number(vformat(U"%d°", vertical_angle)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); + viewport->draw_string_outline(font, v_angle_text_pos, TS->format_number(vformat(U"%d°", vertical_angle), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); + viewport->draw_string(font, v_angle_text_pos, TS->format_number(vformat(U"%d°", vertical_angle), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); text_pos2 = text_pos; text_pos2.y = end.y < text_pos.y ? MIN(text_pos.y - text_height * 2, end.y - text_height / 2) : MAX(text_pos.y + text_height * 2, end.y - text_height / 2); - viewport->draw_string_outline(font, text_pos2, TS->format_number(vformat("%.1f px", length_vector.x)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); - viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.1f px", length_vector.x)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); + viewport->draw_string_outline(font, text_pos2, TS->format_number(vformat("%.1f px", length_vector.x), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); + viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.1f px", length_vector.x), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); Point2 h_angle_text_pos; h_angle_text_pos.x = CLAMP(end.x - angle_text_width / 2, angle_text_width / 2, viewport->get_rect().size.x - angle_text_width); @@ -3217,8 +3223,8 @@ void CanvasItemEditor::_draw_ruler_tool() { h_angle_text_pos.y = MIN(text_pos.y - height_multiplier * text_height, MIN(end.y - text_height * 0.5, text_pos2.y - height_multiplier * text_height)); } } - viewport->draw_string_outline(font, h_angle_text_pos, TS->format_number(vformat(U"%d°", horizontal_angle)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); - viewport->draw_string(font, h_angle_text_pos, TS->format_number(vformat(U"%d°", horizontal_angle)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); + viewport->draw_string_outline(font, h_angle_text_pos, TS->format_number(vformat(U"%d°", horizontal_angle), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); + viewport->draw_string(font, h_angle_text_pos, TS->format_number(vformat(U"%d°", horizontal_angle), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); } if (grid_snap_active) { @@ -3227,21 +3233,21 @@ void CanvasItemEditor::_draw_ruler_tool() { text_pos.y = CLAMP(text_pos.y, text_height * 2.5, viewport->get_rect().size.y - text_height / 2); if (draw_secondary_lines) { - viewport->draw_string_outline(font, text_pos, TS->format_number(vformat("%.2f " + TTR("units"), (length_vector / grid_step).length())), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); - viewport->draw_string(font, text_pos, TS->format_number(vformat("%.2f " + TTR("units"), (length_vector / grid_step).length())), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); + viewport->draw_string_outline(font, text_pos, TS->format_number(vformat("%.2f " + TTR("units"), (length_vector / grid_step).length()), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); + viewport->draw_string(font, text_pos, TS->format_number(vformat("%.2f " + TTR("units"), (length_vector / grid_step).length()), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); Point2 text_pos2 = text_pos; text_pos2.x = begin.x < text_pos.x ? MIN(text_pos.x - text_width, begin.x - text_width / 2) : MAX(text_pos.x + text_width, begin.x - text_width / 2); - viewport->draw_string_outline(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.y / grid_step.y))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); - viewport->draw_string(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.y / grid_step.y))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); + viewport->draw_string_outline(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.y / grid_step.y)), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); + viewport->draw_string(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.y / grid_step.y)), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); text_pos2 = text_pos; text_pos2.y = end.y < text_pos.y ? MIN(text_pos.y - text_height * 2, end.y + text_height / 2) : MAX(text_pos.y + text_height * 2, end.y + text_height / 2); - viewport->draw_string_outline(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.x / grid_step.x))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); - viewport->draw_string(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.x / grid_step.x))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); + viewport->draw_string_outline(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.x / grid_step.x)), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); + viewport->draw_string(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.x / grid_step.x)), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); } else { - viewport->draw_string_outline(font, text_pos, TS->format_number(vformat("%d " + TTR("units"), roundf((length_vector / grid_step).length()))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); - viewport->draw_string(font, text_pos, TS->format_number(vformat("%d " + TTR("units"), roundf((length_vector / grid_step).length()))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); + viewport->draw_string_outline(font, text_pos, TS->format_number(vformat("%d " + TTR("units"), roundf((length_vector / grid_step).length())), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); + viewport->draw_string(font, text_pos, TS->format_number(vformat("%d " + TTR("units"), roundf((length_vector / grid_step).length())), lang), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); } } } else { @@ -3818,7 +3824,8 @@ void CanvasItemEditor::_draw_message() { double snap = EDITOR_GET("interface/inspector/default_float_step"); int snap_step_decimals = Math::range_step_decimals(snap); -#define FORMAT(value) (TS->format_number(String::num(value, snap_step_decimals))) + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); +#define FORMAT(value) (TS->format_number(String::num(value, snap_step_decimals), lang)) switch (drag_type) { case DRAG_MOVE: diff --git a/editor/plugins/editor_plugin_settings.cpp b/editor/plugins/editor_plugin_settings.cpp index 5949bc141f52..22fe0feac874 100644 --- a/editor/plugins/editor_plugin_settings.cpp +++ b/editor/plugins/editor_plugin_settings.cpp @@ -34,7 +34,7 @@ #include "core/io/config_file.h" #include "core/io/dir_access.h" #include "core/io/file_access.h" -#include "core/os/main_loop.h" +#include "core/string/translation_server.h" #include "editor/editor_node.h" #include "editor/editor_string_names.h" #include "editor/themes/editor_scale.h" @@ -62,6 +62,7 @@ void EditorPluginSettings::update_plugins() { Vector plugins = _get_plugins("res://addons"); plugins.sort(); + const String &lang = TranslationServer::get_singleton()->get_editor_domain()->get_locale(); for (int i = 0; i < plugins.size(); i++) { Ref cfg; cfg.instantiate(); @@ -91,7 +92,7 @@ void EditorPluginSettings::update_plugins() { bool is_enabled = EditorNode::get_singleton()->is_addon_plugin_enabled(path); Color disabled_color = get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)); - const PackedInt32Array boundaries = TS->string_get_word_breaks(description, "", 80); + const PackedInt32Array boundaries = TS->string_get_word_breaks(description, lang, 80); String wrapped_description; for (int j = 0; j < boundaries.size(); j += 2) { diff --git a/scene/3d/label_3d.cpp b/scene/3d/label_3d.cpp index 6b3510a72a17..c5cef3bdf4e0 100644 --- a/scene/3d/label_3d.cpp +++ b/scene/3d/label_3d.cpp @@ -30,6 +30,7 @@ #include "label_3d.h" +#include "core/string/translation_server.h" #include "scene/main/window.h" #include "scene/resources/theme.h" #include "scene/theme/theme_db.h" @@ -474,8 +475,9 @@ void Label3D::_shape() { TS->shaped_text_clear(text_rid); TS->shaped_text_set_direction(text_rid, text_direction); - String txt = (uppercase) ? TS->string_to_upper(xl_text, language) : xl_text; - TS->shaped_text_add_string(text_rid, txt, font->get_rids(), font_size, font->get_opentype_features(), language); + const String &lang = language.is_empty() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : language; + String txt = (uppercase) ? TS->string_to_upper(xl_text, lang) : xl_text; + TS->shaped_text_add_string(text_rid, txt, font->get_rids(), font_size, font->get_opentype_features(), lang); TypedArray stt; if (st_parser == TextServer::STRUCTURED_TEXT_CUSTOM) { diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index 4bd85cbde992..b464f8b943a1 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -30,6 +30,7 @@ #include "button.h" +#include "core/string/translation_server.h" #include "scene/theme/theme_db.h" Size2 Button::get_minimum_size() const { @@ -567,7 +568,8 @@ void Button::_shape(Ref p_paragraph, String p_text) { } else { p_paragraph->set_direction((TextServer::Direction)text_direction); } - p_paragraph->add_string(p_text, font, font_size, language); + const String &lang = language.is_empty() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : language; + p_paragraph->add_string(p_text, font, font_size, lang); p_paragraph->set_text_overrun_behavior(overrun_behavior); } diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 9d7e2496a223..5a6d2a7d6d8c 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -33,6 +33,7 @@ #include "core/os/keyboard.h" #include "core/string/string_builder.h" +#include "core/string/translation_server.h" #include "core/string/ustring.h" #include "scene/theme/theme_db.h" @@ -60,6 +61,7 @@ void CodeEdit::_notification(int p_what) { const bool caret_visible = is_caret_visible(); const bool rtl = is_layout_rtl(); const int row_height = get_line_height(); + const String &lang = TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale(); if (line_length_guideline_columns.size() > 0) { const int xmargin_beg = theme_cache.style_normal->get_margin(SIDE_LEFT) + get_total_gutter_width(); @@ -199,7 +201,7 @@ void CodeEdit::_notification(int p_what) { Ref tl; tl.instantiate(); - tl->add_string(code_completion_options[l].display, theme_cache.font, theme_cache.font_size); + tl->add_string(code_completion_options[l].display, theme_cache.font, theme_cache.font_size, lang); int yofs = (row_height - tl->get_size().y) / 2; Point2 title_pos(code_completion_rect.position.x, code_completion_rect.position.y + i * row_height + yofs); @@ -1481,14 +1483,15 @@ void CodeEdit::_line_number_draw_callback(int p_line, int p_gutter, const Rect2 if (E) { text_rid = E->value; } else { + const String &lang = TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale(); String fc = String::num_int64(p_line + 1).lpad(line_number_digits, line_number_padding); if (is_localizing_numeral_system()) { - fc = TS->format_number(fc); + fc = TS->format_number(fc, lang); } text_rid = TS->create_shaped_text(); if (theme_cache.font.is_valid()) { - TS->shaped_text_add_string(text_rid, fc, theme_cache.font->get_rids(), theme_cache.font_size, theme_cache.font->get_opentype_features()); + TS->shaped_text_add_string(text_rid, fc, theme_cache.font->get_rids(), theme_cache.font_size, theme_cache.font->get_opentype_features(), lang); } line_number_text_cache.insert(p_line, text_rid); } diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 1ba5ef309b0f..4801cbcb728c 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -32,6 +32,7 @@ #include "core/config/project_settings.h" #include "core/os/os.h" +#include "core/string/translation_server.h" #include "scene/theme/theme_db.h" void ItemList::_shape_text(int p_idx) { @@ -43,7 +44,8 @@ void ItemList::_shape_text(int p_idx) { } else { item.text_buf->set_direction((TextServer::Direction)item.text_direction); } - item.text_buf->add_string(item.xl_text, theme_cache.font, theme_cache.font_size, item.language); + const String &lang = item.language.is_empty() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : item.language; + item.text_buf->add_string(item.xl_text, theme_cache.font, theme_cache.font_size, lang); if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) { item.text_buf->set_break_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::BREAK_GRAPHEME_BOUND | TextServer::BREAK_TRIM_EDGE_SPACES); } else { diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 42b4e56b484b..7e30e0329859 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -32,7 +32,7 @@ #include "core/config/project_settings.h" #include "core/string/print_string.h" -#include "core/string/translation.h" +#include "core/string/translation_server.h" #include "scene/gui/container.h" #include "scene/theme/theme_db.h" #include "servers/text_server.h" @@ -117,12 +117,13 @@ void Label::_shape() { const Ref &font = (settings.is_valid() && settings->get_font().is_valid()) ? settings->get_font() : theme_cache.font; int font_size = settings.is_valid() ? settings->get_font_size() : theme_cache.font_size; ERR_FAIL_COND(font.is_null()); - String txt = (uppercase) ? TS->string_to_upper(xl_text, language) : xl_text; + const String &lang = language.is_empty() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : language; + String txt = (uppercase) ? TS->string_to_upper(xl_text, lang) : xl_text; if (visible_chars >= 0 && visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING) { txt = txt.substr(0, visible_chars); } if (dirty) { - TS->shaped_text_add_string(text_rid, txt, font->get_rids(), font_size, font->get_opentype_features(), language); + TS->shaped_text_add_string(text_rid, txt, font->get_rids(), font_size, font->get_opentype_features(), lang); } else { int spans = TS->shaped_get_span_count(text_rid); for (int i = 0; i < spans; i++) { diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 3f979f7c20aa..22f63d5b7714 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -34,7 +34,7 @@ #include "core/os/keyboard.h" #include "core/os/os.h" #include "core/string/print_string.h" -#include "core/string/translation.h" +#include "core/string/translation_server.h" #include "scene/gui/label.h" #include "scene/main/window.h" #include "scene/theme/theme_db.h" @@ -2569,7 +2569,8 @@ void LineEdit::_shape() { } TS->shaped_text_set_preserve_control(text_rid, draw_control_chars); - TS->shaped_text_add_string(text_rid, t, font->get_rids(), font_size, font->get_opentype_features(), language); + const String &lang = language.is_empty() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : language; + TS->shaped_text_add_string(text_rid, t, font->get_rids(), font_size, font->get_opentype_features(), lang); TS->shaped_text_set_bidi_override(text_rid, structured_text_parser(st_parser, st_args, t)); full_width = TS->shaped_text_get_size(text_rid).x; diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp index 1142ba37f564..066d284a465c 100644 --- a/scene/gui/link_button.cpp +++ b/scene/gui/link_button.cpp @@ -30,7 +30,7 @@ #include "link_button.h" -#include "core/string/translation.h" +#include "core/string/translation_server.h" #include "scene/theme/theme_db.h" void LinkButton::_shape() { @@ -44,7 +44,8 @@ void LinkButton::_shape() { text_buf->set_direction((TextServer::Direction)text_direction); } TS->shaped_text_set_bidi_override(text_buf->get_rid(), structured_text_parser(st_parser, st_args, xl_text)); - text_buf->add_string(xl_text, font, font_size, language); + const String &lang = language.is_empty() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : language; + text_buf->add_string(xl_text, font, font_size, lang); } void LinkButton::set_text(const String &p_text) { diff --git a/scene/gui/menu_bar.cpp b/scene/gui/menu_bar.cpp index 9853d699d40b..f36956f8e884 100644 --- a/scene/gui/menu_bar.cpp +++ b/scene/gui/menu_bar.cpp @@ -30,7 +30,7 @@ #include "menu_bar.h" -#include "core/os/keyboard.h" +#include "core/string/translation_server.h" #include "scene/main/window.h" #include "scene/theme/theme_db.h" @@ -491,13 +491,15 @@ void MenuBar::_draw_menu_item(int p_index) { } void MenuBar::shape(Menu &p_menu) { + const String &lang = language.is_empty() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : language; + p_menu.text_buf->clear(); if (text_direction == Control::TEXT_DIRECTION_INHERITED) { p_menu.text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); } else { p_menu.text_buf->set_direction((TextServer::Direction)text_direction); } - p_menu.text_buf->add_string(atr(p_menu.name), theme_cache.font, theme_cache.font_size, language); + p_menu.text_buf->add_string(atr(p_menu.name), theme_cache.font, theme_cache.font_size, lang); } void MenuBar::_refresh_menu_names() { diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 3c04094526df..48790da82c58 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -36,7 +36,7 @@ #include "core/os/keyboard.h" #include "core/os/os.h" #include "core/string/print_string.h" -#include "core/string/translation.h" +#include "core/string/translation_server.h" #include "scene/gui/menu_bar.h" #include "scene/theme/theme_db.h" @@ -952,17 +952,18 @@ void PopupMenu::_shape_item(int p_idx) { Ref font = items[p_idx].separator ? theme_cache.font_separator : theme_cache.font; int font_size = items[p_idx].separator ? theme_cache.font_separator_size : theme_cache.font_size; + const String &lang = TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale(); if (items[p_idx].text_direction == Control::TEXT_DIRECTION_INHERITED) { items.write[p_idx].text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); } else { items.write[p_idx].text_buf->set_direction((TextServer::Direction)items[p_idx].text_direction); } - items.write[p_idx].text_buf->add_string(items.write[p_idx].xl_text, font, font_size, items[p_idx].language); + items.write[p_idx].text_buf->add_string(items.write[p_idx].xl_text, font, font_size, items[p_idx].language.is_empty() ? lang : items[p_idx].language); items.write[p_idx].accel_text_buf->clear(); items.write[p_idx].accel_text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); - items.write[p_idx].accel_text_buf->add_string(_get_accel_text(items.write[p_idx]), font, font_size); + items.write[p_idx].accel_text_buf->add_string(_get_accel_text(items.write[p_idx]), font, font_size, lang); items.write[p_idx].dirty = false; } } diff --git a/scene/gui/progress_bar.cpp b/scene/gui/progress_bar.cpp index 90ce01e38377..e4fd34531c4d 100644 --- a/scene/gui/progress_bar.cpp +++ b/scene/gui/progress_bar.cpp @@ -30,6 +30,7 @@ #include "progress_bar.h" +#include "core/string/translation_server.h" #include "scene/resources/text_line.h" #include "scene/theme/theme_db.h" @@ -159,7 +160,8 @@ void ProgressBar::_notification(int p_what) { String txt = itos(int(ratio * 100)); if (is_localizing_numeral_system()) { - txt = TS->format_number(txt) + TS->percent_sign(); + const String &lang = TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale(); + txt = TS->format_number(txt, lang) + TS->percent_sign(lang); } else { txt += String("%"); } diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 26141663c1c5..5efcb5c66d71 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -35,7 +35,7 @@ #include "core/math/math_defs.h" #include "core/os/keyboard.h" #include "core/os/os.h" -#include "core/string/translation.h" +#include "core/string/translation_server.h" #include "scene/gui/label.h" #include "scene/gui/rich_text_effect.h" #include "scene/resources/atlas_texture.h" @@ -302,7 +302,7 @@ void RichTextLabel::_update_line_font(ItemFrame *p_frame, int p_line, const Ref< String prefix = _get_prefix(list_l.from, list_index, list_items); list_l.text_prefix.instantiate(); list_l.text_prefix->set_direction(_find_direction(list_l.from)); - list_l.text_prefix->add_string(prefix, font, font_size); + list_l.text_prefix->add_string(prefix, font, font_size, _find_language(list_l.from)); list_items.write[0]->max_width = MAX(list_items[0]->max_width, list_l.text_prefix->get_size().x); } } @@ -492,7 +492,7 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref String prefix = _get_prefix(list_l.from, list_index, list_items); list_l.text_prefix.instantiate(); list_l.text_prefix->set_direction(_find_direction(list_l.from)); - list_l.text_prefix->add_string(prefix, font, font_size); + list_l.text_prefix->add_string(prefix, font, font_size, _find_language(list_l.from)); list_items.write[0]->max_width = MAX(list_items[0]->max_width, list_l.text_prefix->get_size().x); } } @@ -527,7 +527,7 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref case ITEM_DROPCAP: { // Add dropcap. const ItemDropcap *dc = static_cast(it); - l.text_buf->set_dropcap(dc->text, dc->font, dc->font_size, dc->dropcap_margins); + l.text_buf->set_dropcap(dc->text, dc->font, dc->font_size, dc->dropcap_margins, _find_language(it)); l.dc_color = dc->color; l.dc_ol_size = dc->ol_size; l.dc_ol_color = dc->ol_color; @@ -549,7 +549,7 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref if (font_size_it && font_size_it->font_size > 0) { font_size = font_size_it->font_size; } - l.text_buf->add_string(String::chr(0x200B), font, font_size); + l.text_buf->add_string(String::chr(0x200B), font, font_size, _find_language(it)); txt += "\n"; l.char_count++; remaining_characters--; @@ -572,14 +572,13 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref if (font_size_it && font_size_it->font_size > 0) { font_size = font_size_it->font_size; } - String lang = _find_language(it); String tx = t->text; if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters >= 0) { tx = tx.substr(0, remaining_characters); } remaining_characters -= tx.length(); - l.text_buf->add_string(tx, font, font_size, lang, it->rid); + l.text_buf->add_string(tx, font, font_size, _find_language(it), it->rid); txt += tx; l.char_count += tx.length(); } break; @@ -2602,21 +2601,24 @@ TextServer::StructuredTextParser RichTextLabel::_find_stt(Item *p_item) { } String RichTextLabel::_find_language(Item *p_item) { - Item *item = p_item; + String lang = language; + Item *item = p_item; while (item) { if (item->type == ITEM_LANGUAGE) { ItemLanguage *p = static_cast(item); - return p->language; + lang = p->language; + break; } else if (item->type == ITEM_PARAGRAPH) { ItemParagraph *p = static_cast(item); - return p->language; + lang = p->language; + break; } item = item->parent; } - return language; + return lang.is_empty() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : lang; } Color RichTextLabel::_find_color(Item *p_item, const Color &p_default_color) { diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 01c2b9bffe18..be06fe4ab944 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -32,6 +32,7 @@ #include "core/input/input.h" #include "core/math/expression.h" +#include "core/string/translation_server.h" #include "scene/theme/theme_db.h" Size2 SpinBox::get_minimum_size() const { @@ -43,7 +44,8 @@ Size2 SpinBox::get_minimum_size() const { void SpinBox::_update_text(bool p_keep_line_edit) { String value = String::num(get_value(), Math::range_step_decimals(get_step())); if (is_localizing_numeral_system()) { - value = TS->format_number(value); + const String &lang = TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale(); + value = TS->format_number(value, lang); } if (!line_edit->is_editing()) { @@ -64,13 +66,15 @@ void SpinBox::_update_text(bool p_keep_line_edit) { } void SpinBox::_text_submitted(const String &p_string) { + const String &lang = TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale(); + Ref expr; expr.instantiate(); // Convert commas ',' to dots '.' for French/German etc. keyboard layouts. String text = p_string.replace(",", "."); text = text.replace(";", ","); - text = TS->parse_number(text); + text = TS->parse_number(text, lang); // Ignore the prefix and suffix in the expression. text = text.trim_prefix(prefix + " ").trim_suffix(" " + suffix); @@ -78,7 +82,7 @@ void SpinBox::_text_submitted(const String &p_string) { if (err != OK) { // If the expression failed try without converting commas to dots - they might have been for parameter separation. text = p_string; - text = TS->parse_number(text); + text = TS->parse_number(text, lang); text = text.trim_prefix(prefix + " ").trim_suffix(" " + suffix); err = expr->parse(text); diff --git a/scene/gui/tab_bar.cpp b/scene/gui/tab_bar.cpp index 6cc7ec3bd5ce..4614aa69c1ea 100644 --- a/scene/gui/tab_bar.cpp +++ b/scene/gui/tab_bar.cpp @@ -30,7 +30,7 @@ #include "tab_bar.h" -#include "core/string/translation.h" +#include "core/string/translation_server.h" #include "scene/gui/box_container.h" #include "scene/gui/label.h" #include "scene/gui/texture_rect.h" @@ -345,7 +345,8 @@ void TabBar::_shape(int p_tab) { tabs.write[p_tab].text_buf->set_direction((TextServer::Direction)tabs[p_tab].text_direction); } - tabs.write[p_tab].text_buf->add_string(atr(tabs[p_tab].text), theme_cache.font, theme_cache.font_size, tabs[p_tab].language); + const String &lang = tabs[p_tab].language.is_empty() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : tabs[p_tab].language; + tabs.write[p_tab].text_buf->add_string(atr(tabs[p_tab].text), theme_cache.font, theme_cache.font_size, lang); } void TabBar::_notification(int p_what) { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index b1918ff23fc4..e830a9a0817b 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1117,9 +1117,10 @@ void TextEdit::_notification(int p_what) { break; } + const String &lang = language.is_empty() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : language; Ref 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, lang); int yofs = ofs_y + (row_height - tl->get_size().y) / 2; if (theme_cache.outline_size > 0 && theme_cache.outline_color.a > 0) { @@ -2880,7 +2881,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() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->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()) { @@ -2934,7 +2936,8 @@ 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() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->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); @@ -3226,7 +3229,8 @@ 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()); + const String &lang = language.is_empty() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : language; + text.set_direction_and_language(dir, lang); text.invalidate_font(); _update_placeholder(); @@ -3253,7 +3257,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() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : language; + text.set_direction_and_language(dir, lang); text.invalidate_all(); _update_placeholder(); queue_redraw(); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index aab6f672f0e3..34c0afcfac1c 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -35,6 +35,7 @@ #include "core/math/math_funcs.h" #include "core/os/keyboard.h" #include "core/os/os.h" +#include "core/string/translation_server.h" #include "scene/gui/box_container.h" #include "scene/gui/text_edit.h" #include "scene/main/window.h" @@ -2101,7 +2102,8 @@ void Tree::update_item_cell(TreeItem *p_item, int p_col) { } else { font_size = theme_cache.font_size; } - p_item->cells.write[p_col].text_buf->add_string(valtext, font, font_size, p_item->cells[p_col].language); + const String &lang = p_item->cells[p_col].language.is_empty() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : p_item->cells[p_col].language; + p_item->cells.write[p_col].text_buf->add_string(valtext, font, font_size, lang); BitField break_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_TRIM_EDGE_SPACES; switch (p_item->cells.write[p_col].autowrap_mode) { diff --git a/scene/resources/3d/primitive_meshes.cpp b/scene/resources/3d/primitive_meshes.cpp index ceeb73d0ef2c..4f3de1ee4cc4 100644 --- a/scene/resources/3d/primitive_meshes.cpp +++ b/scene/resources/3d/primitive_meshes.cpp @@ -31,6 +31,7 @@ #include "primitive_meshes.h" #include "core/config/project_settings.h" +#include "core/string/translation_server.h" #include "scene/resources/theme.h" #include "scene/theme/theme_db.h" #include "servers/rendering_server.h" @@ -2917,8 +2918,9 @@ void TextMesh::_create_mesh_array(Array &p_arr) const { TS->shaped_text_clear(text_rid); TS->shaped_text_set_direction(text_rid, text_direction); - String txt = (uppercase) ? TS->string_to_upper(xl_text, language) : xl_text; - TS->shaped_text_add_string(text_rid, txt, font->get_rids(), font_size, font->get_opentype_features(), language); + const String &lang = language.is_empty() ? TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale() : language; + String txt = (uppercase) ? TS->string_to_upper(xl_text, lang) : xl_text; + TS->shaped_text_add_string(text_rid, txt, font->get_rids(), font_size, font->get_opentype_features(), lang); TypedArray stt; if (st_parser == TextServer::STRUCTURED_TEXT_CUSTOM) {