Add support for parsing NamespacedJson in Json compiler. Closes #44
This commit is contained in:
parent
3b9561916b
commit
39a335638b
@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user