Add NamespacedJsonCompiler
This commit is contained in:
18
src/compilers/namespaced-json.compiler.ts
Normal file
18
src/compilers/namespaced-json.compiler.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { CompilerInterface } from './compiler.interface';
|
||||
import { TranslationCollection } from '../utils/translation.collection';
|
||||
|
||||
import * as flat from 'flat';
|
||||
|
||||
export class NamespacedJsonCompiler implements CompilerInterface {
|
||||
|
||||
public compile(collection: TranslationCollection): string {
|
||||
const values = flat.unflatten(collection.values);
|
||||
return JSON.stringify(values, null, '\t');
|
||||
}
|
||||
|
||||
public parse(contents: string): TranslationCollection {
|
||||
const values = flat.flatten(JSON.parse(contents));
|
||||
return new TranslationCollection(values);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user