fix: objects counted as plural incorrectly
This commit is contained in:
parent
cc7675eccb
commit
e55c6f99e2
|
@ -105,7 +105,8 @@ export function t(key: string, variables?: Record<string, any>): string {
|
|||
const translation = _t(key, loadedLocale);
|
||||
|
||||
if (typeof translation !== "string") {
|
||||
if (!variables || !variables.count) throw new Error(`translation key ${key} is an object (requires plurality?)`);
|
||||
if (!variables || !variables.count)
|
||||
throw new Error(`translation key ${key} is an object (is it a plural?)`);
|
||||
|
||||
if (variables.count) {
|
||||
const pluralTag: Intl.LDMLPluralRule = variables.count === 0 ? "zero" :
|
||||
|
@ -113,8 +114,10 @@ export function t(key: string, variables?: Record<string, any>): string {
|
|||
|
||||
if (translation[pluralTag]) {
|
||||
return format(translation[pluralTag]!, variables);
|
||||
} else {
|
||||
} else if (translation.other) {
|
||||
return format(translation.other, variables);
|
||||
} else {
|
||||
throw new Error(`translation key ${key} is an object and doesn't seem to be plural`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue