Skip to content

Commit 4951467

Browse files
committed
Change ignoreEmptyKeys default to true
1 parent 21854bf commit 4951467

File tree

5 files changed

+36
-16
lines changed

5 files changed

+36
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Unreleased
44

5-
- Add `ignoreEmptyKeys` option to ignore empty keys when scanning source files #634
5+
- Add `ignoreEmptyKeys` option (default: true) to ignore empty keys when scanning source files #634
66

77
# 9.3.0
88

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ export default {
253253
// {
254254
// lineWidth: -1,
255255

256-
ignoreEmptyKeys: false,
257-
// Set to true to ignore empty keys when scanning source files.
256+
ignoreEmptyKeys: true,
257+
// When true (default), ignores empty keys when scanning source files.
258258
// This allows using t('') which is useful with i18next's "returnEmptyString: false" setting.
259-
// When false (default), empty keys are included in the translation files and will fail with --fail-on-update.
259+
// When false, empty keys are included in the translation files and will fail with --fail-on-update.
260260
}
261261
```
262262

src/transform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class i18nTransform extends Transform {
4040
customValueTemplate: null,
4141
failOnWarnings: false,
4242
yamlOptions: null,
43-
ignoreEmptyKeys: false,
43+
ignoreEmptyKeys: true,
4444
}
4545

4646
this.options = { ...this.defaults, ...options }

test/helpers/dotPathToHash.test.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,37 @@ describe('dotPathToHash helper function', () => {
3636
})
3737

3838
it('handles an empty namespace', (done) => {
39-
const { target, duplicate } = dotPathToHash({
40-
keyWithNamespace: 'ns.',
41-
namespace: 'ns',
42-
})
39+
const { target, duplicate } = dotPathToHash(
40+
{
41+
keyWithNamespace: 'ns.',
42+
namespace: 'ns',
43+
},
44+
{},
45+
{
46+
ignoreEmptyKeys: true,
47+
}
48+
)
4349
assert.deepEqual(target, { ns: {} })
4450
assert.equal(duplicate, false)
4551
done()
4652
})
4753

54+
it('handles an empty namespace when ignoreEmptyKeys is false', (done) => {
55+
const { target, duplicate } = dotPathToHash(
56+
{
57+
keyWithNamespace: 'ns.',
58+
namespace: 'ns',
59+
},
60+
{},
61+
{
62+
ignoreEmptyKeys: false,
63+
}
64+
)
65+
assert.deepEqual(target, { ns: { '': '' } })
66+
assert.equal(duplicate, false)
67+
done()
68+
})
69+
4870
it('handles a target hash', (done) => {
4971
const { target, duplicate } = dotPathToHash(
5072
{ keyWithNamespace: 'one.two.three' },

test/parser.test.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ describe('parser', () => {
308308
const i18nextParser = new i18nTransform({
309309
locales: ['en'],
310310
defaultNamespace: 'default',
311-
ignoreEmptyKeys: true,
312311
})
313312
const fakeFile = new Vinyl({
314313
contents: Buffer.from("t('empty:');"),
@@ -341,7 +340,6 @@ describe('parser', () => {
341340
const i18nextParser = new i18nTransform({
342341
locales: ['en'],
343342
defaultNamespace: 'test_empty',
344-
ignoreEmptyKeys: true,
345343
})
346344
const fakeFile = new Vinyl({
347345
contents: Buffer.from("t('key'); t('');"),
@@ -361,7 +359,7 @@ describe('parser', () => {
361359
i18nextParser.end(fakeFile)
362360
})
363361

364-
it('includes empty keys by default', (done) => {
362+
it('ignores empty keys by default', (done) => {
365363
let resultContent
366364
const i18nextParser = new i18nTransform({
367365
locales: ['en'],
@@ -378,19 +376,19 @@ describe('parser', () => {
378376
}
379377
})
380378
i18nextParser.on('end', () => {
381-
assert.deepEqual(resultContent, { key: '', '': '' })
379+
assert.deepEqual(resultContent, { key: '' })
382380
done()
383381
})
384382

385383
i18nextParser.end(fakeFile)
386384
})
387385

388-
it('ignores empty keys when scanning source files when ignoreEmptyKeys is true', (done) => {
386+
it('includes empty keys when ignoreEmptyKeys is false', (done) => {
389387
let resultContent
390388
const i18nextParser = new i18nTransform({
391389
locales: ['en'],
392390
defaultNamespace: 'test_ignore_empty',
393-
ignoreEmptyKeys: true,
391+
ignoreEmptyKeys: false,
394392
})
395393
const fakeFile = new Vinyl({
396394
contents: Buffer.from("t('key'); t('');"),
@@ -403,7 +401,7 @@ describe('parser', () => {
403401
}
404402
})
405403
i18nextParser.on('end', () => {
406-
assert.deepEqual(resultContent, { key: '' })
404+
assert.deepEqual(resultContent, { key: '', '': '' })
407405
done()
408406
})
409407

0 commit comments

Comments
 (0)