chore: remove unnecessary if

This commit is contained in:
Lewis Crichton 2024-06-24 19:00:26 +01:00
parent e55c6f99e2
commit faea1c8224
No known key found for this signature in database

View file

@ -108,17 +108,15 @@ export function t(key: string, variables?: Record<string, any>): string {
if (!variables || !variables.count) if (!variables || !variables.count)
throw new Error(`translation key ${key} is an object (is it a plural?)`); throw new Error(`translation key ${key} is an object (is it a plural?)`);
if (variables.count) { const pluralTag: Intl.LDMLPluralRule = variables.count === 0 ? "zero" :
const pluralTag: Intl.LDMLPluralRule = variables.count === 0 ? "zero" : new Intl.PluralRules(bestLocale).select(variables.count);
new Intl.PluralRules(bestLocale).select(variables.count);
if (translation[pluralTag]) { if (translation[pluralTag]) {
return format(translation[pluralTag]!, variables); return format(translation[pluralTag]!, variables);
} else if (translation.other) { } else if (translation.other) {
return format(translation.other, variables); return format(translation.other, variables);
} else { } else {
throw new Error(`translation key ${key} is an object and doesn't seem to be plural`); throw new Error(`translation key ${key} is an object and doesn't seem to be plural`);
}
} }
} }