Add function ApplySafeSubstitution for translation strings with parameters

This commit is contained in:
Henrik Rydgård committed 2023-07-16 16:26:49 +02:00
1 parent 755269c90d
commit 8a59ed0062
10 files changed
+64 -23

No files matched your search

+9 -9
View File
@@ -531,7 +531,7 @@ void Choice::Draw(UIContext &dc) {
std::string Choice::DescribeText() const {
auto u = GetI18NCategory(I18NCat::UI_ELEMENTS);
return ReplaceAll(u->T("%1 choice"), "%1", text_);
return ApplySafeSubstitutions(u->T("%1 choice"), text_);
}
InfoItem::InfoItem(const std::string &text, const std::string &rightText, LayoutParams *layoutParams)
@@ -579,7 +579,7 @@ void InfoItem::Draw(UIContext &dc) {
std::string InfoItem::DescribeText() const {
auto u = GetI18NCategory(I18NCat::UI_ELEMENTS);
return ReplaceAll(ReplaceAll(u->T("%1: %2"), "%1", text_), "%2", rightText_);
return ApplySafeSubstitutions(u->T("%1: %2"), text_, rightText_);
}
ItemHeader::ItemHeader(const std::string &text, LayoutParams *layoutParams)
@@ -609,7 +609,7 @@ void ItemHeader::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec hor
std::string ItemHeader::DescribeText() const {
auto u = GetI18NCategory(I18NCat::UI_ELEMENTS);
return ReplaceAll(u->T("%1 heading"), "%1", text_);
return ApplySafeSubstitutions(u->T("%1 heading"), text_);
}
void BorderView::Draw(UIContext &dc) {
@@ -674,7 +674,7 @@ void PopupHeader::Draw(UIContext &dc) {
std::string PopupHeader::DescribeText() const {
auto u = GetI18NCategory(I18NCat::UI_ELEMENTS);
return ReplaceAll(u->T("%1 heading"), "%1", text_);
return ApplySafeSubstitutions(u->T("%1 heading"), text_);
}
void CheckBox::Toggle() {
@@ -755,7 +755,7 @@ void CheckBox::Draw(UIContext &dc) {
std::string CheckBox::DescribeText() const {
auto u = GetI18NCategory(I18NCat::UI_ELEMENTS);
std::string text = ReplaceAll(u->T("%1 checkbox"), "%1", text_);
std::string text = ApplySafeSubstitutions(u->T("%1 checkbox"), text_);
if (!smallText_.empty()) {
text += "\n" + smallText_;
}
@@ -858,7 +858,7 @@ void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const
std::string Button::DescribeText() const {
auto u = GetI18NCategory(I18NCat::UI_ELEMENTS);
return ReplaceAll(u->T("%1 button"), "%1", GetText());
return ApplySafeSubstitutions(u->T("%1 button"), GetText());
}
void Button::Click() {
@@ -920,7 +920,7 @@ void RadioButton::GetContentDimensions(const UIContext &dc, float &w, float &h)
std::string RadioButton::DescribeText() const {
auto u = GetI18NCategory(I18NCat::UI_ELEMENTS);
return ReplaceAll(u->T("%1 radio button"), "%1", text_);
return ApplySafeSubstitutions(u->T("%1 radio button"), text_);
}
void RadioButton::Click() {
@@ -1108,7 +1108,7 @@ void TextEdit::GetContentDimensions(const UIContext &dc, float &w, float &h) con
std::string TextEdit::DescribeText() const {
auto u = GetI18NCategory(I18NCat::UI_ELEMENTS);
return ReplaceAll(u->T("%1 text field"), "%1", GetText());
return ApplySafeSubstitutions(u->T("%1 text field"), GetText());
}
// Handles both windows and unix line endings.
@@ -1299,7 +1299,7 @@ void ProgressBar::Draw(UIContext &dc) {
std::string ProgressBar::DescribeText() const {
auto u = GetI18NCategory(I18NCat::UI_ELEMENTS);
float percent = progress_ * 100.0f;
return ReplaceAll(u->T("Progress: %1%"), "%1", StringFromInt((int)percent));
return ApplySafeSubstitutions(u->T("Progress: %1%"), StringFromInt((int)percent));
}
void Spinner::GetContentDimensions(const UIContext &dc, float &w, float &h) const {