Skip to content

Commit

Permalink
Detect plurals when count is a CallExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
glsignal committed Jul 15, 2024
1 parent 7f78ad7 commit 80ea05f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lexers/javascript-lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ export default class JavascriptLexer extends BaseLexer {
const nestedEntries = this.expressionExtractor(p.initializer)
if (nestedEntries) {
entries.push(...nestedEntries)
} else {
entries[0][p.name.text] = p.initializer.text || ''
}
} else {
entries[0][p.name.text] = p.initializer.text || ''
Expand Down
24 changes: 24 additions & 0 deletions test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,30 @@ describe('parser', () => {
i18nextParser.end(fakeFile)
})

it('generates plurals when count is an expression', (done) => {
let result
const i18nextParser = new i18nTransform()
const fakeFile = new Vinyl({
contents: Buffer.from("t('test {{count}}', { count: expr() })"),
path: 'file.js',
})

i18nextParser.on('data', (file) => {
if (file.relative.endsWith(enLibraryPath)) {
result = JSON.parse(file.contents)
}
})
i18nextParser.once('end', () => {
assert.deepEqual(result, {
'test {{count}}_one': '',
'test {{count}}_other': '',
})
done()
})

i18nextParser.end(fakeFile)
})

it('generates plurals with custom plural separator', (done) => {
let result
const i18nextParser = new i18nTransform({
Expand Down

0 comments on commit 80ea05f

Please sign in to comment.