Skip to content

Commit

Permalink
Merge pull request #1022 from glsignal/issue-1015-fix-plural-detection
Browse files Browse the repository at this point in the history
Fix plurals not being detected when count is a CallExpression
  • Loading branch information
karellm authored Jul 27, 2024
2 parents 7f78ad7 + 80ea05f commit 2e78fa5
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 2e78fa5

Please sign in to comment.