diff --git a/src/compilers/json.compiler.ts b/src/compilers/json.compiler.ts index 5d92244..665d302 100644 --- a/src/compilers/json.compiler.ts +++ b/src/compilers/json.compiler.ts @@ -1,6 +1,8 @@ import { CompilerInterface } from './compiler.interface'; import { TranslationCollection } from '../utils/translation.collection'; +import * as flat from 'flat'; + export class JsonCompiler implements CompilerInterface { public indentation: string = '\t'; @@ -18,7 +20,15 @@ export class JsonCompiler implements CompilerInterface { } public parse(contents: string): TranslationCollection { - return new TranslationCollection(JSON.parse(contents)); + let values: any = JSON.parse(contents); + if (this._isNamespacedJsonFormat(values)) { + values = flat.flatten(values); + } + return new TranslationCollection(values); + } + + protected _isNamespacedJsonFormat(values: any): boolean { + return Object.keys(values).some(key => typeof values[key] === 'object'); } }