Skip to content

Commit

Permalink
Merge pull request #800 from vinissimus/canary
Browse files Browse the repository at this point in the history
Release 1.3.5
  • Loading branch information
aralroca authored Mar 4, 2022
2 parents 7531ff2 + 926423f commit 3615aa3
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@
"contributions": [
"code"
]
},
{
"login": "groomain",
"name": "Romain",
"avatar_url": "https://avatars.githubusercontent.com/u/3601848?v=4",
"profile": "https://github.com/groomain",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="http://www.dan-needham.com"><img src="https://avatars.githubusercontent.com/u/1122983?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dan Needham</b></sub></a><br /><a href="https://github.com/vinissimus/next-translate/commits?author=dndhm" title="Code">💻</a> <a href="https://github.com/vinissimus/next-translate/commits?author=dndhm" title="Tests">⚠️</a> <a href="https://github.com/vinissimus/next-translate/commits?author=dndhm" title="Documentation">📖</a></td>
<td align="center"><a href="https://www.youtube.com/BrunoAntunesPT"><img src="https://avatars.githubusercontent.com/u/9042965?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Bruno Antunes</b></sub></a><br /><a href="https://github.com/vinissimus/next-translate/commits?author=bmvantunes" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/kaan-atakan"><img src="https://avatars.githubusercontent.com/u/56063979?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kaan Atakan</b></sub></a><br /><a href="https://github.com/vinissimus/next-translate/commits?author=kaan-atakan" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/groomain"><img src="https://avatars.githubusercontent.com/u/3601848?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Romain</b></sub></a><br /><a href="https://github.com/vinissimus/next-translate/commits?author=groomain" title="Code">💻</a></td>
</tr>
</table>
Expand Down
61 changes: 59 additions & 2 deletions __tests__/useTranslation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,23 @@ describe('useTranslation', () => {
const withSingular = {
withsingular: 'The number is NOT ONE',
withsingular_1: 'The number is ONE!',
withsingular_other: 'Oops!',
}
const { container } = render(
<TestEnglish
namespaces={{ ns: withSingular }}
i18nKey={i18nKey}
query={{ count: 0 }}
/>
)
expect(container.textContent).toContain(expected)
})

test('should work with plural | count=0', () => {
const i18nKey = 'ns:withsingular'
const expected = 'The number is ZERO'
const withSingular = {
withsingular_one: 'The number is NOT ZERO',
withsingular_other: 'The number is ZERO!',
}
const { container } = render(
<TestEnglish
Expand Down Expand Up @@ -438,7 +454,6 @@ describe('useTranslation', () => {
const with_0 = {
withsingular: 'The number is NOT ZERO',
withsingular_0: 'The number is ZERO!',
withsingular_other: 'Oops!',
}
const { container } = render(
<TestEnglish
Expand Down Expand Up @@ -486,6 +501,48 @@ describe('useTranslation', () => {
expect(container.textContent).toContain(expected)
})

test('should work with _zero for ar language | count=0', () => {
const Inner = () => {
const { t } = useTranslation()
return t('ns:withplural', { count: 0 })
}

const expected = 'The number is zero'
const templateString = {
withplural_zero: 'The number is zero',
withplural_2: 'The number is TWO!',
withplural_other: 'Number is bigger than one!',
}

const { container } = render(
<I18nProvider lang="ar" namespaces={{ ns: templateString }}>
<Inner />
</I18nProvider>
)
expect(container.textContent).toContain(expected)
})

test('should work with _one for fr language | count=0', () => {
const Inner = () => {
const { t } = useTranslation()
return t('ns:withplural', { count: 0 })
}

const expected = 'The number is zero'
const templateString = {
withplural_one: 'The number is zero',
withplural_2: 'The number is TWO!',
withplural_other: 'Number is bigger than one!',
}

const { container } = render(
<I18nProvider lang="fr" namespaces={{ ns: templateString }}>
<Inner />
</I18nProvider>
)
expect(container.textContent).toContain(expected)
})

test('should work as a template string', () => {
const Inner = () => {
const { t } = useTranslation()
Expand Down
1 change: 0 additions & 1 deletion __tests__/withTranslation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ describe('withTranslation', () => {
const withSingular = {
withsingular: 'The number is NOT ONE',
withsingular_1: 'The number is ONE!',
withsingular_other: 'Oops!',
}
const { container } = render(
<TestEnglish
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-translate",
"version": "1.3.4",
"version": "1.3.5",
"description": "Tiny and powerful i18n tools (Next plugin + API) to translate your Next.js pages.",
"license": "MIT",
"keywords": [
Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface I18nConfig {
pages?: Record<string, PageValue>
logger?: I18nLogger
staticsHoc?: Function
extensionsRgx?: string
loader?: boolean
logBuild?: boolean
revalidate?: number
Expand Down
2 changes: 1 addition & 1 deletion src/transCore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function plural(
if (getDicValue(dic, numKey, config) !== undefined) return numKey

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

Expand Down

0 comments on commit 3615aa3

Please sign in to comment.