diff --git a/src/compilers/json.compiler.ts b/src/compilers/json.compiler.ts index 912ea39..08e72f1 100644 --- a/src/compilers/json.compiler.ts +++ b/src/compilers/json.compiler.ts @@ -1,7 +1,8 @@ import { CompilerInterface } from './compiler.interface'; import { TranslationCollection } from '../utils/translation.collection'; +import { stripBOM } from '../utils/utils'; -import * as flat from 'flat'; +import { flatten } from 'flat'; export class JsonCompiler implements CompilerInterface { @@ -20,9 +21,9 @@ export class JsonCompiler implements CompilerInterface { } public parse(contents: string): TranslationCollection { - let values: any = JSON.parse(contents); + let values: any = JSON.parse(stripBOM(contents)); if (this.isNamespacedJsonFormat(values)) { - values = flat.flatten(values); + values = flatten(values); } return new TranslationCollection(values); } diff --git a/src/compilers/namespaced-json.compiler.ts b/src/compilers/namespaced-json.compiler.ts index 39e5b11..c0e341b 100644 --- a/src/compilers/namespaced-json.compiler.ts +++ b/src/compilers/namespaced-json.compiler.ts @@ -1,7 +1,8 @@ import { CompilerInterface } from './compiler.interface'; import { TranslationCollection } from '../utils/translation.collection'; +import { stripBOM } from '../utils/utils'; -import * as flat from 'flat'; +import { flatten, unflatten } from 'flat'; export class NamespacedJsonCompiler implements CompilerInterface { @@ -16,14 +17,14 @@ export class NamespacedJsonCompiler implements CompilerInterface { } public compile(collection: TranslationCollection): string { - const values: {} = flat.unflatten(collection.values, { + const values: {} = unflatten(collection.values, { object: true }); return JSON.stringify(values, null, this.indentation); } public parse(contents: string): TranslationCollection { - const values: {} = flat.flatten(JSON.parse(contents)); + const values: {} = flatten(JSON.parse(stripBOM(contents))); return new TranslationCollection(values); }