fix fallback for pluralized strings (#7480)

* fix fallback for pluralized cases

Signed-off-by: Kerry Archibald <kerrya@element.io>

* add test case for no pluralizer

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry 2022-01-07 16:20:24 +01:00 committed by GitHub
parent 309f7bb235
commit d4250918cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View file

@ -85,7 +85,7 @@ export function _td(s: string): string { // eslint-disable-line @typescript-esli
const translateWithFallback = (text: string, options?: object): { translated?: string, isFallback?: boolean } => {
const translated = counterpart.translate(text, options);
if (/^missing translation:/.test(translated)) {
const fallbackTranslated = counterpart.translate(text, { ...options, fallbackLocale: FALLBACK_LOCALE });
const fallbackTranslated = counterpart.translate(text, { ...options, locale: FALLBACK_LOCALE });
return { translated: fallbackTranslated, isFallback: true };
}
return { translated };
@ -168,7 +168,6 @@ export function _t(text: string, variables: IVariables, tags: Tags): React.React
export function _t(text: string, variables?: IVariables, tags?: Tags): TranslatedString {
// The translation returns text so there's no XSS vector here (no unsafe HTML, no code execution)
const { translated } = safeCounterpartTranslate(text, variables);
const substituted = substitute(translated, variables, tags);
return annotateStrings(substituted, text);