mirror of
https://github.com/Eugeny/tabby.git
synced 2025-07-20 02:18:01 +00:00
new translation extractor
This commit is contained in:
@@ -3,6 +3,9 @@ const sh = require('shelljs')
|
||||
const fs = require('fs/promises')
|
||||
const vars = require('./vars')
|
||||
const log = require('npmlog')
|
||||
const { GettextExtractor, JsExtractors, HtmlExtractors } = require('gettext-extractor')
|
||||
|
||||
let extractor = new GettextExtractor()
|
||||
|
||||
const tempOutput = 'locale/app.new.pot'
|
||||
const pot = 'locale/app.pot'
|
||||
@@ -11,17 +14,40 @@ const tempHtml = 'locale/tmp-html'
|
||||
;(async () => {
|
||||
sh.mkdir('-p', tempHtml)
|
||||
for (const plugin of vars.builtinPlugins) {
|
||||
log.info('extract-pug', plugin)
|
||||
log.info('compile-pug', plugin)
|
||||
|
||||
sh.exec(`yarn pug --doctype html -s --pretty -O '{require: function(){}}' -o ${tempHtml}/${plugin} ${plugin}`, { fatal: true })
|
||||
|
||||
log.info('extract-ts', plugin)
|
||||
sh.exec(`node node_modules/.bin/ngx-translate-extract -i ${plugin}/src -m -s -f pot -o ${tempOutput}`, { fatal: true })
|
||||
}
|
||||
|
||||
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')
|
||||
|
||||
log.info('extract-pug')
|
||||
sh.exec(`node node_modules/.bin/ngx-translate-extract -i ${tempHtml} -f pot -s -o ${tempOutput}`, { fatal: true })
|
||||
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()
|
||||
|
||||
sh.rm('-r', tempHtml)
|
||||
sh.exec(`msgcat -s ${tempOutput} > ${pot}`, { fatal: true })
|
||||
|
||||
await fs.rename(tempOutput, pot)
|
||||
})()
|
||||
|
Reference in New Issue
Block a user