@vendure/ngx-translate-extract
Version:
Extract strings from projects using ngx-translate
28 lines • 1.05 kB
JavaScript
import { TranslationCollection } from '../utils/translation.collection.js';
import { stripBOM } from '../utils/utils.js';
import { flatten } from 'flat';
export class JsonCompiler {
indentation = '\t';
extension = 'json';
constructor(options) {
if (options && typeof options.indentation !== 'undefined') {
this.indentation = options.indentation;
}
}
compile(collection) {
return JSON.stringify(collection.toKeyValueObject(), null, this.indentation);
}
parse(contents) {
let values = JSON.parse(stripBOM(contents));
if (this.isNamespacedJsonFormat(values)) {
values = flatten(values);
}
const newValues = {};
Object.entries(values).forEach(([key, value]) => newValues[key] = { value: value, sourceFiles: [] });
return new TranslationCollection(newValues);
}
isNamespacedJsonFormat(values) {
return Object.keys(values).some((key) => typeof values[key] === 'object');
}
}
//# sourceMappingURL=json.compiler.js.map