UNPKG

@vendure/ngx-translate-extract

Version:
23 lines 932 B
import { TranslationCollection } from '../utils/translation.collection.js'; import { stripBOM } from '../utils/utils.js'; import { flatten, unflatten } from 'flat'; export class NamespacedJsonCompiler { indentation = '\t'; extension = 'json'; constructor(options) { if (options && typeof options.indentation !== 'undefined') { this.indentation = options.indentation; } } compile(collection) { const values = unflatten(collection.toKeyValueObject(), { object: true }); return JSON.stringify(values, null, this.indentation); } parse(contents) { const values = flatten(JSON.parse(stripBOM(contents))); const newValues = {}; Object.entries(values).forEach(([key, value]) => newValues[key] = { value: value, sourceFiles: [] }); return new TranslationCollection(newValues); } } //# sourceMappingURL=namespaced-json.compiler.js.map