Skip to content

Commit

Permalink
_one works (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin authored Mar 7, 2021
1 parent 0d8d49a commit 4853bec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
18 changes: 18 additions & 0 deletions __tests__/useTranslation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,24 @@ describe('useTranslation', () => {
expect(container.textContent).toContain(expected)
})

test('should work with singular | count=1', () => {
const i18nKey = 'ns:withsingular'
const expected = 'The number is NOT ZERO'
const withSingular = {
withsingular_one: 'The number is NOT ZERO',
withsingular_0: 'The number is ZERO!',
withsingular_other: 'Oops!',
}
const { container } = render(
<TestEnglish
namespaces={{ ns: withSingular }}
i18nKey={i18nKey}
query={{ count: 1 }}
/>
)
expect(container.textContent).toContain(expected)
})

test('should work with singular | count=0', () => {
const i18nKey = 'ns:withsingular'
const expected = 'The number is NOT ONE'
Expand Down
4 changes: 3 additions & 1 deletion __tests__/withTranslation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ describe('withTranslation', () => {
query={{ count: 1 }}
/>
)
expect(r5.container.textContent).toContain('The cart has only 1 product')
expect(r5.container.textContent).toContain(
'The cart number ends with one'
)

const r6 = render(
<TestRussian
Expand Down
2 changes: 1 addition & 1 deletion src/transCore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function plural(
if (getDicValue(dic, numKey) !== undefined) return numKey

const pluralKey = `${key}_${pluralRules.select(query.count)}`
if (query.count > 1 && getDicValue(dic, pluralKey) !== undefined) {
if (query.count > 0 && getDicValue(dic, pluralKey) !== undefined) {
return pluralKey
}

Expand Down

0 comments on commit 4853bec

Please sign in to comment.