Skip to content

Commit a7b13cd

Browse files
committed
fix(i18n): fallback on missing plural translation
1 parent 72b0507 commit a7b13cd

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

config/i18n.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,23 @@ const locales: (LocaleObjectData | (Omit<LocaleObjectData, 'code'> & { code: str
206206
code: 'uk-UA',
207207
file: 'uk-UA.json',
208208
name: 'Українська',
209-
pluralRule: (choice: number) => {
209+
pluralRule: (choice: number, choicesLength: number) => {
210210
if (choice === 0) return 0
211211

212212
const name = new Intl.PluralRules('uk-UA').select(choice)
213-
return { zero: 0, one: 1, two: 0, few: 2, many: 3, other: 4 }[name]
213+
const plural = { zero: 0, one: 1, two: 0, few: 2, many: 3, other: 4 }[name]
214+
215+
// In case translation doesn't have all plural forms, use the last available form
216+
if (plural > choicesLength - 1) {
217+
if (import.meta.dev) {
218+
console.warn(
219+
`Plural form index ${plural} for choice ${choice} exceeds available forms ${choicesLength} for locale uk-UA.`,
220+
)
221+
}
222+
return choicesLength - 1
223+
}
224+
225+
return plural
214226
},
215227
},
216228
/*{

0 commit comments

Comments
 (0)