1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-25 19:17:39 +03:00
tabby/scripts/i18n-extract.mjs

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-01-08 18:02:56 +03:00
#!/usr/bin/env node
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-11 00:33:14 +03:00
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)
})()