Skip to content

Commit

Permalink
fix: show error when plurals aren't loaded (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
semoal authored Nov 5, 2020
1 parent d58dc09 commit 296b6a1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ const defaultFormats = (
}
}

if (!plurals) {
console.error(`Plurals for locale ${locale} aren't loaded. Use i18n.loadLocaleData method to load plurals for specific locale. Using other plural rule as a fallback.`)
}

return {
plural: (value, { offset = 0, ...rules }) => {
const message = rules[value] || rules[plurals(value - offset)]
const message = rules[value] || rules[plurals?.(value - offset)] || rules.other
return replaceOctothorpe(value - offset, message)
},

selectordinal: (value, { offset = 0, ...rules }) => {
const message = rules[value] || rules[plurals(value - offset, true)]
const message = rules[value] || rules[plurals?.(value - offset, true)] || rules.other
return replaceOctothorpe(value - offset, message)
},

Expand Down

1 comment on commit 296b6a1

@vercel
Copy link

@vercel vercel bot commented on 296b6a1 Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.