@lingui/cli
Version:
Lingui CLI to extract messages, compile catalogs, and manage translation workflows
34 lines (33 loc) • 1.24 kB
JavaScript
import { compileLocale } from "../api/compile/compileLocale.js";
import { getConfig } from "@lingui/conf";
import { WorkerLogger } from "../api/workerLogger.js";
import { ProgramExit } from "../api/ProgramExit.js";
import { getCatalogs } from "../api/catalog/getCatalogs.js";
let linguiConfig;
let catalogs;
export const compileWorker = async (locale, options, doMerge, linguiConfigPath) => {
if (!linguiConfig) {
// initialize config once per worker, speed up workers follow execution
linguiConfig = getConfig({
configPath: linguiConfigPath,
skipValidation: true,
});
}
if (!catalogs) {
// catalogs holds path to the files and message catalogs, so it's kinda configuration object
// it depends only on the config, so we can initialize it once per program execution
catalogs = await getCatalogs(linguiConfig);
}
const logger = new WorkerLogger();
try {
await compileLocale(catalogs, locale, options, linguiConfig, doMerge, logger);
}
catch (error) {
return {
logs: logger.flush(),
error,
exitProgram: error instanceof ProgramExit,
};
}
return { logs: logger.flush() };
};