File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 11import { CompilerInterface } from './compiler.interface' ;
22import { TranslationCollection } from '../utils/translation.collection' ;
33
4+ import * as flat from 'flat' ;
5+
46export class JsonCompiler implements CompilerInterface {
57
68 public indentation : string = '\t' ;
@@ -18,7 +20,15 @@ export class JsonCompiler implements CompilerInterface {
1820 }
1921
2022 public parse ( contents : string ) : TranslationCollection {
21- return new TranslationCollection ( JSON . parse ( contents ) ) ;
23+ let values : any = JSON . parse ( contents ) ;
24+ if ( this . _isNamespacedJsonFormat ( values ) ) {
25+ values = flat . flatten ( values ) ;
26+ }
27+ return new TranslationCollection ( values ) ;
28+ }
29+
30+ protected _isNamespacedJsonFormat ( values : any ) : boolean {
31+ return Object . keys ( values ) . some ( key => typeof values [ key ] === 'object' ) ;
2232 }
2333
2434}
You can’t perform that action at this time.
0 commit comments