diff --git a/src/loader.ts b/src/loader.ts index 09e88d9..f957c5a 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -77,6 +77,10 @@ const parseItem = (expr) => { return expr.value } + if (expr.kind === 'nullkeyword') { + return null; + } + if (expr.kind === 'array') { let items = expr.items.map((item) => parseItem(item)) @@ -102,6 +106,10 @@ const convertToDotsSyntax = (list) => { const flatten = (items, context = '') => { const data = {} + if (items === null) { + return data; + } + Object.entries(items).forEach(([key, value]) => { if (typeof value === 'string') { data[context + key] = value diff --git a/test/fixtures/lang/en/ignore.php b/test/fixtures/lang/en/ignore.php new file mode 100644 index 0000000..5eb6b8c --- /dev/null +++ b/test/fixtures/lang/en/ignore.php @@ -0,0 +1,6 @@ + [], + 'null' => null, +]; diff --git a/test/loader.test.ts b/test/loader.test.ts index 59a9eac..55e722b 100644 --- a/test/loader.test.ts +++ b/test/loader.test.ts @@ -98,6 +98,13 @@ it('transforms simple index array to .json', () => { expect(lang['arr.1']).toBe('bar'); }); +it('ignores empty `array` or `null` translations', () => { + const lang = parse(fs.readFileSync(__dirname + '/fixtures/lang/en/ignore.php').toString()); + + expect(lang['empty_array']).toBe(undefined); + expect(lang['null']).toBe(undefined); +}); + it('checks if there is .php translations', () => { expect(hasPhpTranslations(__dirname + '/fixtures/lang/')).toBe(true); expect(hasPhpTranslations(__dirname + '/fixtures/wronglangfolder/')).toBe(false);