1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-30 10:36:35 +02:00
joplin/packages/tools/website/buildTranslations.ts

33 lines
1004 B
TypeScript
Raw Normal View History

2022-11-22 20:16:57 +02:00
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();
2022-11-28 18:16:32 +02:00
const htmlParser = extractor
2022-11-22 20:16:57 +02:00
.createHtmlParser([
HtmlExtractors.elementContent('[translate]'),
2022-11-28 18:16:32 +02:00
]);
htmlParser.parseFile(`${websiteAssetsDir}/templates/front.mustache`);
htmlParser.parseFile(`${websiteAssetsDir}/templates/plans.mustache`);
htmlParser.parseFile(`${websiteAssetsDir}/templates/partials/plan.mustache`);
2022-11-22 20:16:57 +02:00
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);
});