diff --git a/package.json b/package.json index adcfc69..66e96d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@biesbjerg/ngx-translate-extract", - "version": "2.0.0", + "version": "2.0.1", "description": "Extract strings from projects using ngx-translate", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/src/compilers/namespaced-json.compiler.ts b/src/compilers/namespaced-json.compiler.ts index 4b48c98..2a32157 100644 --- a/src/compilers/namespaced-json.compiler.ts +++ b/src/compilers/namespaced-json.compiler.ts @@ -8,7 +8,9 @@ export class NamespacedJsonCompiler implements CompilerInterface { public extension = 'json'; public compile(collection: TranslationCollection): string { - const values: {} = flat.unflatten(collection.values); + const values: {} = flat.unflatten(collection.values, { + object: true + }); return JSON.stringify(values, null, '\t'); } diff --git a/tests/compilers/namespaced-compiler.spec.ts b/tests/compilers/namespaced-compiler.spec.ts index 6801215..8d352f1 100644 --- a/tests/compilers/namespaced-compiler.spec.ts +++ b/tests/compilers/namespaced-compiler.spec.ts @@ -35,4 +35,14 @@ describe('NamespacedJsonCompiler', () => { expect(result).to.equal('{\n\t"NAMESPACE": {\n\t\t"KEY": {\n\t\t\t"FIRST_KEY": "",\n\t\t\t"SECOND_KEY": "VALUE"\n\t\t}\n\t}\n}'); }); + it('should preserve numeric values on compile', () => { + const collection = new TranslationCollection({ + "option.0": '', + "option.1": '', + "option.2": '' + }); + const result: string = compiler.compile(collection); + expect(result).to.equal('{\n\t"option": {\n\t\t"0": "",\n\t\t"1": "",\n\t\t"2": ""\n\t}\n}'); + }); + });