1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-09 08:45:55 +02:00
joplin/packages/tools/website/buildTranslations.ts
2022-11-28 17:18:15 +01:00

33 lines
1004 B
TypeScript

import { rootDir } from '../tool-utils';
import { mergePotToPo } from '../utils/translation';
const { GettextExtractor, HtmlExtractors } = require('gettext-extractor');
const websiteAssetsDir = `${rootDir}/Assets/WebsiteAssets`;
const localesDir = `${websiteAssetsDir}/locales`;
const createPotFile = async (potFilePath: string) => {
const extractor = new GettextExtractor();
const htmlParser = extractor
.createHtmlParser([
HtmlExtractors.elementContent('[translate]'),
]);
htmlParser.parseFile(`${websiteAssetsDir}/templates/front.mustache`);
htmlParser.parseFile(`${websiteAssetsDir}/templates/plans.mustache`);
htmlParser.parseFile(`${websiteAssetsDir}/templates/partials/plan.mustache`);
extractor.savePotFile(potFilePath);
};
const main = async () => {
const potFilePath = `${websiteAssetsDir}/website.pot`;
await createPotFile(potFilePath);
await mergePotToPo(potFilePath, `${localesDir}/zh_CN.po`);
};
main().catch((error) => {
console.error(error);
process.exit(1);
});