Fix namespaced-json compiler not preserving numeric values. Fixes #28

This commit is contained in:
Kim Biesbjerg 2017-03-29 12:52:14 +02:00
parent 7654397bb3
commit ff1c91010e
3 changed files with 14 additions and 2 deletions

View File

@ -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",

View File

@ -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');
}

View File

@ -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}');
});
});