2022-01-08 15:02:56 +00:00
|
|
|
#!/usr/bin/env node
|
2023-02-26 19:42:31 +00:00
|
|
|
import sh from 'shelljs'
|
|
|
|
import fs from 'node:fs/promises'
|
|
|
|
import * as vars from './vars.mjs'
|
|
|
|
import log from 'npmlog'
|
|
|
|
import { GettextExtractor, JsExtractors, HtmlExtractors } from 'gettext-extractor'
|
2022-02-10 21:33:14 +00:00
|
|
|
|
|
|
|
let extractor = new GettextExtractor()
|
2022-01-08 15:02:56 +00:00
|
|
|
|
|
|
|
const tempOutput = 'locale/app.new.pot'
|
|
|
|
const pot = 'locale/app.pot'
|
|
|
|
const tempHtml = 'locale/tmp-html'
|
|
|
|
|
|
|
|
;(async () => {
|
|
|
|
sh.mkdir('-p', tempHtml)
|
|
|
|
for (const plugin of vars.builtinPlugins) {
|
2022-02-10 21:33:14 +00:00
|
|
|
log.info('compile-pug', plugin)
|
2022-01-08 15:02:56 +00:00
|
|
|
|
2022-01-16 18:41:01 +00:00
|
|
|
sh.exec(`yarn pug --doctype html -s --pretty -O '{require: function(){}}' -o ${tempHtml}/${plugin} ${plugin}`, { fatal: true })
|
2022-01-08 15:02:56 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 21:33:14 +00:00
|
|
|
log.info('extract-ts')
|
|
|
|
extractor.createJsParser([
|
|
|
|
JsExtractors.callExpression('this.translate.instant', {
|
|
|
|
arguments: { text: 0 },
|
|
|
|
}),
|
|
|
|
JsExtractors.callExpression('translate.instant', {
|
|
|
|
arguments: { text: 0 },
|
|
|
|
}),
|
|
|
|
JsExtractors.callExpression('_', {
|
|
|
|
arguments: { text: 0 },
|
|
|
|
}),
|
|
|
|
]).parseFilesGlob('./tabby-*/src/**/*.ts')
|
|
|
|
|
2022-01-08 15:02:56 +00:00
|
|
|
log.info('extract-pug')
|
2022-02-10 21:33:14 +00:00
|
|
|
const options = {
|
|
|
|
attributes: {
|
|
|
|
context: 'translatecontext',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
extractor.createHtmlParser([
|
|
|
|
HtmlExtractors.elementContent('translate, [translate=""]', options),
|
|
|
|
HtmlExtractors.elementAttribute('[translate*=" "]', 'translate', options),
|
|
|
|
]).parseFilesGlob(`${tempHtml}/**/*.html`)
|
|
|
|
|
|
|
|
extractor.savePotFile(tempOutput)
|
|
|
|
extractor.printStats()
|
2022-01-08 15:02:56 +00:00
|
|
|
|
|
|
|
sh.rm('-r', tempHtml)
|
2022-02-10 21:33:14 +00:00
|
|
|
sh.exec(`msgcat -s ${tempOutput} > ${pot}`, { fatal: true })
|
|
|
|
|
2022-01-08 15:02:56 +00:00
|
|
|
await fs.rename(tempOutput, pot)
|
|
|
|
})()
|