ButtonLabel::Expanded ButtonLabel::Expand(const TCHAR *text, TCHAR *buffer, size_t size) { Expanded expanded; const TCHAR *dollar; if (text == nullptr || *text == _T('\0') || *text == _T(' ')) { expanded.visible = false; return expanded; } else if ((dollar = StringFind(text, '$')) == nullptr) { /* no macro, we can just translate the text */ expanded.visible = true; expanded.enabled = true; const TCHAR *nl = StringFind(text, '\n'); if (nl != nullptr && LacksAlphaASCII(nl + 1)) { /* Quick hack for skipping the translation for second line of a two line label with only digits and punctuation in the second line, e.g. for menu labels like "Config\n2/3" */ /* copy the text up to the '\n' to a new buffer and translate it */ TCHAR translatable[256]; const TCHAR *translated = GetTextN(text, nl, translatable, ARRAY_SIZE(translatable)); if (translated == nullptr) { /* buffer too small: keep it untranslated */ expanded.text = text; return expanded; } /* concatenate the translated text and the part starting with '\n' */ expanded.text = BuildString(buffer, size, translated, nl); } else expanded.text = gettext(text); return expanded; } else { const TCHAR *macros = dollar; /* backtrack until the first non-whitespace character, because we don't want to translate whitespace between the text and the macro */ macros = StripRight(text, macros); TCHAR s[100]; expanded.enabled = !ExpandMacros(text, s, ARRAY_SIZE(s)); if (s[0] == _T('\0') || s[0] == _T(' ')) { expanded.visible = false; return expanded; } /* copy the text (without trailing whitespace) to a new buffer and translate it */ TCHAR translatable[256]; const TCHAR *translated = GetTextN(text, macros, translatable, ARRAY_SIZE(translatable)); if (translated == nullptr) { /* buffer too small: fail */ // TODO: find a more clever fallback expanded.visible = false; return expanded; } /* concatenate the translated text and the macro output */ expanded.visible = true; expanded.text = BuildString(buffer, size, translated, s + (macros - text)); return expanded; } }
ButtonLabel::Expanded ButtonLabel::Expand(const TCHAR *text, TCHAR *buffer, size_t size) { Expanded expanded; const TCHAR *dollar; if ((text == NULL) || (*text == _T('\0')) || (*text == _T(' '))) { expanded.visible = false; return expanded; } else if ((dollar = _tcschr(text, '$')) == NULL) { /* no macro, we can just translate the text */ expanded.visible = true; expanded.enabled = true; const TCHAR *nl; if (((nl = _tcschr(text, '\n')) != NULL) && LacksAlphaASCII(nl + 1)) { /* Quick hack for skipping the translation for second line of a two line label with only digits and punctuation in the second line, e.g. for menu labels like "Config\n2/3" */ /* copy the text up to the '\n' to a new buffer and translate it */ TCHAR translatable[256]; std::copy(text, nl, translatable); translatable[nl - text] = _T('\0'); const TCHAR *translated = StringIsEmpty(translatable) ? _T("") : gettext(translatable); /* concatenate the translated text and the part starting with '\n' */ _tcscpy(buffer, translated); _tcscat(buffer, nl); expanded.text = buffer; } else expanded.text = gettext(text); return expanded; } else { const TCHAR *macros = dollar; /* backtrack until the first non-whitespace character, because we don't want to translate whitespace between the text and the macro */ while (macros > text && IsWhitespaceOrNull(macros[-1])) --macros; TCHAR s[100]; expanded.enabled = !ExpandMacros(text, s, ARRAY_SIZE(s)); if (s[0] == _T('\0') || s[0] == _T(' ')) { expanded.visible = false; return expanded; } /* copy the text (without trailing whitespace) to a new buffer and translate it */ TCHAR translatable[256]; std::copy(text, macros, translatable); translatable[macros - text] = _T('\0'); const TCHAR *translated = StringIsEmpty(translatable) ? _T("") : gettext(translatable); /* concatenate the translated text and the macro output */ _tcscpy(buffer, translated); _tcscat(buffer, s + (macros - text)); expanded.visible = true; expanded.text = buffer; return expanded; } }