@lingui/cli
Version:
Lingui CLI to extract messages, compile catalogs, and manage translation workflows
42 lines (41 loc) • 1.2 kB
JavaScript
import { readFile, writeFileIfChanged } from "../utils.js";
import { RethrownError } from "../rethrownError.js";
export class FormatterWrapper {
f;
sourceLocale;
constructor(f, sourceLocale) {
this.f = f;
this.sourceLocale = sourceLocale;
}
getCatalogExtension() {
return this.f.catalogExtension;
}
getTemplateExtension() {
return this.f.templateExtension || this.f.catalogExtension;
}
async write(filename, catalog, locale) {
const content = await this.f.serialize(catalog, {
locale,
sourceLocale: this.sourceLocale,
existing: await readFile(filename),
filename,
});
await writeFileIfChanged(filename, content);
}
async read(filename, locale) {
const content = await readFile(filename);
if (!content) {
return undefined;
}
try {
return this.f.parse(content, {
locale,
sourceLocale: this.sourceLocale,
filename,
});
}
catch (e) {
throw new RethrownError(`Cannot read ${filename}`, e);
}
}
}