Godot Engine – Multi-platform 2D and 3D game engine
Add warning for %s mismatch in SpinBox
AegisTTNfbee3a4e52df
diff --git a/doc/classes/SpinBox.xml b/doc/classes/SpinBox.xmlindex ef94c5106a9..f6dae912b55 100644--- a/doc/classes/SpinBox.xml+++ b/doc/classes/SpinBox.xml@@ -70,7 +70,7 @@Auto-translation mode for the [member format]. Useful when the format has a word that can be translated.</member><member name="plural_format" type="String" setter="set_plural_format" getter="get_plural_format">- Plural version of [member format]. Used only if [member format] is not empty and [member format_auto_translate_mode] is not disabled. See also [method Object.tr_n].+ Plural version of [member format]. Used only if [member format] is not empty and [member format_auto_translate_mode] is not disabled. If either [member format] or this contain [code]%s[/code] the other must also use it. See also [method Object.tr_n].</member><member name="prefix" type="String" setter="set_prefix" getter="get_prefix" default="""" deprecated="Use [member format] instead.">Adds the specified prefix string before the numerical value of the [SpinBox]. This is used only if [member format] is empty.diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cppindex b5ad333d883..af371195a53 100644--- a/scene/gui/spin_box.cpp+++ b/scene/gui/spin_box.cpp@@ -125,6 +125,9 @@ void SpinBox::_update_text(bool p_only_update_if_value_changed) {const Variant current_value = value;bool error = false;value = _get_xl_format().sprintf(Span(¤t_value, 1), &error);+ if (!error && !plural_format.is_empty() && (plural_format.contains("%s") != use_default_format)) {+ error = true;+ }if (error) {line_edit->set_text_with_selection(RTR("<Invalid>"));return;@@ -779,6 +782,8 @@ PackedStringArray SpinBox::get_configuration_warnings() const {}if (format.is_empty()) {warnings.push_back(RTR("The format property is empty, while plural_format was specified. It will have no effect."));+ } else if (use_default_format != plural_format.contains("%s")) {+ warnings.push_back(RTR("The format and plural_format properties have inconsistent %s placeholder usage."));}}return warnings;