1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-22 18:11:43 +03:00
tabby/scripts/i18n-extract.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-01-08 18:02:56 +03:00
#!/usr/bin/env node
const sh = require('shelljs')
const fs = require('fs/promises')
const vars = require('./vars')
const log = require('npmlog')
2022-02-11 00:33:14 +03:00
const { GettextExtractor, JsExtractors, HtmlExtractors } = require('gettext-extractor')
let extractor = new GettextExtractor()
2022-01-08 18:02:56 +03: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-11 00:33:14 +03:00
log.info('compile-pug', plugin)
2022-01-08 18:02:56 +03:00
2022-01-16 21:41:01 +03:00
sh.exec(`yarn pug --doctype html -s --pretty -O '{require: function(){}}' -o ${tempHtml}/${plugin} ${plugin}`, { fatal: true })
2022-01-08 18:02:56 +03:00
}
2022-02-11 00:33:14 +03: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 18:02:56 +03:00
log.info('extract-pug')
2022-02-11 00:33:14 +03: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 18:02:56 +03:00
sh.rm('-r', tempHtml)
2022-02-11 00:33:14 +03:00
sh.exec(`msgcat -s ${tempOutput} > ${pot}`, { fatal: true })
2022-01-08 18:02:56 +03:00
await fs.rename(tempOutput, pot)
})()