update cli

This commit is contained in:
wxzhang 2023-01-29 21:58:53 +08:00
parent 144136632f
commit 9171396a89
14 changed files with 752 additions and 247 deletions

1
.gitignore vendored
View File

@ -18,3 +18,4 @@ dist
/.yalc
/versions.md
autopub.log
/versions.test.md

View File

@ -1,3 +1,4 @@
#!/usr/bin/env node
/**
* 将extract插件扫描的文件编译为语言文件
*
@ -21,19 +22,21 @@
*
* @param {*} opts
*/
const { Command } = require('commander');
const glob = require("glob")
const createLogger = require("logsets")
const path = require("path")
const { t } = require("./i18nProxy")
const { i18nScope,t } = require("./i18nProxy")
const fs = require("fs-extra")
const logger = createLogger()
const artTemplate = require("art-template")
const semver = require("semver")
const {
findModuleType,
getProjectSourceFolder,
getCurrentPackageJson,
getInstalledPackageInfo,
isTypeScriptProject,
getPackageReleaseInfo,
upgradePackage
} = require("@voerkai18n/utils")
@ -79,10 +82,10 @@ async function updateRuntime(){
try{
const packageName = "@voerkai18n/runtime"
const curVersion = getInstalledPackageInfo(packageName).version
const latestVersion = (await getPackageReleaseInfo(packageName)).lastVersion
const latestVersion = (await getPackageReleaseInfo(packageName)).latestVersion
if(semver.gt(latestVersion, curVersion)){
await upgradePackage(packageName)
task.complete(t("Updated:{}",latestVersion))
task.complete(t("Updated:{}",[latestVersion]))
return
}
task.complete(t("已经是最新的"))
@ -92,9 +95,14 @@ async function updateRuntime(){
}
}
module.exports =async function compile(langFolder,opts={}){
async function compile(langFolder,opts={}){
const options = normalizeCompileOptions(opts);
let { moduleType,isTypeScript } = options;
let { moduleType,isTypeScript,updateRuntime:isUpdateRuntime } = options;
if(isUpdateRuntime){
await updateRuntime()
}
// 如果自动则会从当前项目读取如果没有指定则会是esm
if(moduleType==="auto"){
moduleType = findModuleType(langFolder)
@ -196,3 +204,30 @@ module.exports =async function compile(langFolder,opts={}){
logger.log(t("加载多语言配置文件<{}>失败: {} "),settingsFile,e.stack)
}
}
const program = new Command();
program
.description(t('编译指定项目的语言包'))
.option('-D, --debug', t('输出调试信息'))
.option('-t, --typescript',t("输出typescript代码"))
.option('-u, --update-runtime',t("自动更新runtime"))
.option('-m, --moduleType [types]', t('输出模块类型,取值auto,esm,cjs'), 'auto')
.argument('[location]', t('工程项目所在目录'),"./")
.hook("preAction",async function(location){
const lang= process.env.LANGUAGE || "zh"
await i18nScope.change(lang)
})
.action(async (location,options) => {
location = getProjectSourceFolder(location)
options.isTypeScript = options.typescript==undefined ? isTypeScriptProject() : options.typescript
const langFolder = path.join(location,"languages")
if(!fs.existsSync(langFolder)){
logger.error(t("语言包文件夹<{}>不存在",langFolder))
return
}
compile(langFolder,options)
});
program.parseAsync(process.argv);

View File

@ -1,14 +1,16 @@
const { findModuleType } = require("@voerkai18n/utils")
const { t } = require("./i18nProxy")
#!/usr/bin/env node
const { Command } = require('commander');
const { i18nScope,t } = require("./i18nProxy")
const path = require("path")
const fs = require("fs")
const fs = require("fs-extra")
const gulp = require("gulp")
const extractor = require("./extract.plugin")
const createLogger = require("logsets")
const { getProjectSourceFolder } = require("@voerkai18n/utils")
const logger = createLogger()
module.exports = function(srcPath,options={}){
function extract(srcPath,options={}){
let { filetypes,exclude} = options
if(!filetypes) filetypes = ["*.js","*.jsx","*.ts","*.tsx","*.vue","*.html"]
if(!Array.isArray(filetypes)) filetypes = filetypes.split(",")
@ -49,3 +51,43 @@ module.exports = function(srcPath,options={}){
.pipe(extractor(options))
.pipe(gulp.dest(options.outputPath))
}
const program = new Command();
program
.description(t('扫描并提取所有待翻译的字符串到<languages/translates>文件夹中'))
.option('-D, --debug', t('输出调试信息'))
.option('-lngs, --languages <languages...>', t('支持的语言'), ['zh','en'])
.option('-d, --defaultLanguage', t('默认语言'), 'zh')
.option('-a, --activeLanguage', t('激活语言'), 'zh')
.option('-ns, --namespaces', t('翻译名称空间'))
.option('-e, --exclude <folders>', t('排除要扫描的文件夹,多个用逗号分隔'))
.option('-u, --updateMode', t('本次提取内容与已存在内容的数据合并策略,默认取值sync=同步,overwrite=覆盖,merge=合并'), 'sync')
.option('-f, --filetypes', t('要扫描的文件类型'), 'js,vue,html,jsx,ts,mjs,cjs')
.argument('[location]', t('工程项目所在目录'),"./")
.hook("preAction",async function(location){
const lang= process.env.LANGUAGE || "zh"
await i18nScope.change(lang)
})
.action(async (location,options) => {
location = getProjectSourceFolder(location)
if(options.languages){
options.languages = options.languages.map(l=>({name:l,title:l}))
}
logger.log(t("工程目录:{}"),location)
const langSettingsFile = path.join(location,"languages","settings.json")
if(fs.existsSync(langSettingsFile)){
logger.log(t("语言配置文件<{}>已存在,将优先使用此配置文件中参数来提取文本"),"./languages/settings.json")
let lngOptions = fs.readJSONSync(langSettingsFile)
options.languages = lngOptions.languages
options.defaultLanguage = lngOptions.defaultLanguage
options.activeLanguage = lngOptions.activeLanguage
options.namespaces = lngOptions.namespaces
}
extract(location,options)
});
program.parseAsync(process.argv);

View File

@ -387,7 +387,7 @@ function updateLanguageFile(newTexts,toLangFile,options){
module.exports = function(options={}){
options = normalizeLanguageOptions(options)
let {debug,outputPath, updateMode,languages} = options
let {debug,outputPath} = options
logger.log(t("支持的语言\t: {}"),options.languages.map(item=>`${item.title}(${item.name})`).join(","))
logger.log(t("默认语言\t: {}"),options.defaultLanguage)
@ -464,7 +464,7 @@ module.exports = function(options={}){
logger.log("下一步:")
logger.log(" - 运行<{}>编译语言包","voerkai18n compile")
logger.log(" - 在源码中导入编译后的语言包[{}]","import './languages'")
logger.log(" - 在源码中从[{}]导入编译后的语言包","./languages")
callback()

View File

@ -1,20 +1,20 @@
let VoerkaI18nScope,t
let i18nScope,t
try{
// @voerkai18n/cli工程本身使用了voerkai18n,即@voerkai18n/cli的extract和compile依赖于其自己生成的languages运行时
// 而@voerkai18n/cli又用来编译多语言包这样产生了鸡生蛋问题
// extract与compile调试阶段如果t函数无法使用(即编译的languages无法正常使用)则需要提供t函数
const language = require('./languages');
t = language.t
VoerkaI18nScope = language.VoerkaI18nScope
i18nScope = language.i18nScope
}catch{
t=v=>v
VoerkaI18nScope={change:()=>{} }
i18nScope={change:()=>{} }
}
module.exports = {
VoerkaI18nScope,
i18nScope,
t
}

View File

@ -2,11 +2,9 @@
const { Command } = require('commander');
const createLogger = require("logsets")
const semver = require('semver')
const path = require("path")
const fs = require("fs-extra")
const logger = createLogger()
const { VoerkaI18nScope ,t } = require("./i18nProxy")
const { getProjectSourceFolder,isTypeScriptProject, getPackageReleaseInfo,getInstalledPackageInfo } = require("@voerkai18n/utils");
const { t } = require("./i18nProxy")
const { getPackageReleaseInfo } = require("@voerkai18n/utils");
const program = new Command();
@ -27,113 +25,12 @@ program
}
banner.render()
})
program
.command('init')
.argument('[location]', t('工程项目所在目录'))
.description(t('初始化项目国际化配置'))
.option('-D, --debug', t('输出调试信息'))
.option('-m, --moduleType [types]', t('输出模块类型,取值auto,esm,cjs'), 'auto')
.option('-r, --reset', t('重新生成当前项目的语言配置'))
.option('-t, --typescript',t("输出typescript代码"))
.option('-lngs, --languages <languages...>', t('支持的语言列表'), ['zh','en'])
.option('-d, --defaultLanguage <name>', t('默认语言'), 'zh')
.option('-a, --activeLanguage <name>', t('激活语言'), 'zh')
.hook("preAction",async function(location){
const lang= process.env.LANGUAGE || "zh"
await VoerkaI18nScope.change(lang)
})
.action((location,options) => {
options.isTypeScript = options.typescript==undefined ? isTypeScriptProject() : options.typescript
location = getProjectSourceFolder(location)
logger.log(t("工程目录:{}"),location)
//
if(options.debug){
logger.format(options,{compact:true})
}
const initializer = require("./init.command")
initializer(location,options)
});
program
.command('extract')
.description(t('扫描并提取所有待翻译的字符串到<languages/translates>文件夹中'))
.option('-D, --debug', t('输出调试信息'))
.option('-lngs, --languages <languages...>', t('支持的语言'), ['zh','en'])
.option('-d, --defaultLanguage', t('默认语言'), 'zh')
.option('-a, --activeLanguage', t('激活语言'), 'zh')
.option('-ns, --namespaces', t('翻译名称空间'))
.option('-e, --exclude <folders>', t('排除要扫描的文件夹,多个用逗号分隔'))
.option('-u, --updateMode', t('本次提取内容与已存在内容的数据合并策略,默认取值sync=同步,overwrite=覆盖,merge=合并'), 'sync')
.option('-f, --filetypes', t('要扫描的文件类型'), 'js,vue,html,jsx,ts,mjs,cjs')
.argument('[location]', t('工程项目所在目录'),"./")
.hook("preAction",async function(location){
const lang= process.env.LANGUAGE || "zh"
await VoerkaI18nScope.change(lang)
})
.action(async (location,options) => {
location = getProjectSourceFolder(location)
if(options.languages){
options.languages = options.languages.map(l=>({name:l,title:l}))
}
logger.log(t("工程目录:{}"),location)
const langSettingsFile = path.join(location,"languages","settings.json")
if(fs.existsSync(langSettingsFile)){
logger.log(t("语言配置文件<{}>已存在,将优先使用此配置文件中参数来提取文本"),"./languages/settings.json")
let lngOptions = fs.readJSONSync(langSettingsFile)
options.languages = lngOptions.languages
options.defaultLanguage = lngOptions.defaultLanguage
options.activeLanguage = lngOptions.activeLanguage
options.namespaces = lngOptions.namespaces
}
const extractor = require('./extract.command');
extractor(location,options)
});
program
.command('compile')
.description(t('编译指定项目的语言包'))
.option('-D, --debug', t('输出调试信息'))
.option('-t, --typescript',t("输出typescript代码"))
.option('-m, --moduleType [types]', t('输出模块类型,取值auto,esm,cjs'), 'esm')
.argument('[location]', t('工程项目所在目录'),"./")
.hook("preAction",async function(location){
const lang= process.env.LANGUAGE || "zh"
await VoerkaI18nScope.change(lang)
})
.action(async (location,options) => {
location = getProjectSourceFolder(location)
options.isTypeScript = options.typescript==undefined ? isTypeScriptProject() : options.typescript
const langFolder = path.join(location,"languages")
if(!fs.existsSync(langFolder)){
logger.error(t("语言包文件夹<{}>不存在",langFolder))
return
}
let compile = require("./compile.command")
compile(langFolder,options)
});
program
.command('translate')
.argument('[location]', t('工程项目所在目录'))
.description(t('调用在线翻译服务商的API翻译译指定项目的语言包,如使用百度云翻译服务'))
.option('--no-backup', t('备份原始文件'))
.option('--mode', t('翻译模式取值auto=仅翻译未翻译的,full=全部翻译'), 'auto')
.option('-p, --provider <value>', t('在线翻译服务提供者名称或翻译脚本文件'), 'baidu')
.option('-m, --max-package-size <value>', t('将多个文本合并提交的最大包字节数'), 200)
.option('--appkey [key]', t('API密钥'))
.option('--appid [id]', t('API ID'))
.option('-q, --qps <value>', t('翻译速度限制,即每秒可调用的API次数'), 1)
.hook("preAction",async function(location){
const lang= process.env.LANGUAGE || "zh"
await VoerkaI18nScope.change(lang)
})
.action((location,options) => {
location = getProjectSourceFolder(location)
const translate = require("./translate.command")
translate(location,options)
});
.command('init',t('初始化项目国际化配置'),{executableFile:"./init.command.js"})
.command('extract',t('扫描并提取待翻译的文本到<languages/translates>'),{executableFile:"./extract.command.js"})
.command('compile',t('编译指定项目的语言包'),{executableFile:"./compile.command.js"})
.command('translate',t('在线翻译语言包,如使用百度云翻译服务'),{executableFile:"./translate.command.js"})
program.parseAsync(process.argv);

View File

@ -1,4 +1,4 @@
#!/usr/bin/env node
/**
* 初始化指定项目的语言包
*/
@ -9,8 +9,9 @@ const fs = require("fs")
const { t } = require("./i18nProxy")
const createLogger = require("logsets")
const logger = createLogger()
const { installPackage,getCurrentPackageJson } = require("@voerkai18n/utils")
const { installPackage,getCurrentPackageJson,getProjectSourceFolder } = require("@voerkai18n/utils")
const artTemplate = require("art-template")
const { Command } = require('commander');
function getLanguageList(langs,defaultLanguage){
try{
@ -76,14 +77,14 @@ function getProjectModuleType(srcPath,isTypeScript){
return isTypeScript ? 'esm' : 'cjs'
}
module.exports = function(srcPath,{moduleType,isTypeScript,debug = true,languages=["zh","en"],defaultLanguage="zh",activeLanguage="zh",reset=false}={}){
async function initializer(srcPath,{moduleType,isTypeScript,debug = true,languages=["zh","en"],defaultLanguage="zh",activeLanguage="zh",reset=false}={}){
let settings = {}
// 检查当前项目的模块类型
if(!['esm',"cjs"].includes(moduleType)){
moduleType = getProjectModuleType(srcPath)
}
let tasks = logger.tasklist("初始化VoerkaI18n工程")
let tasks = logger.tasklist("初始化VoerkaI18n多语言支持")
const langFolderName = "languages"
// 查找当前项目的语言包类型路径
const lngPath = path.join(srcPath,langFolderName)
@ -137,7 +138,7 @@ module.exports = function(srcPath,{moduleType,isTypeScript,debug = true,language
}
try{
tasks.add("生成IdMap文件")
tasks.add(t("生成IdMap文件"))
const entryContent = isTypeScript ? "export default {}" : (moduleType=='cjs' ? "module.exports={}" :"export default {}")
fs.writeFileSync(path.join(lngPath,`idMap.${isTypeScript ? 'ts' : 'js'}`),entryContent)
tasks.complete()
@ -146,21 +147,50 @@ module.exports = function(srcPath,{moduleType,isTypeScript,debug = true,language
}
try{
tasks.add(t("安装运行时依赖@voerkai18n/runtime"))
installPackage('@voerkai18n/runtime')
tasks.add(t("安装@voerkai18n/runtime"))
await installPackage.call(this,'@voerkai18n/runtime')
tasks.complete()
}catch(e){
tasks.error(e.message)
console.error(e.stack)
}
if(debug) {
logger.log(t("生成语言配置文件:{}"),"./languages/settings.json")
logger.log(t("拟支持的语言:{}"),settings.languages.map(l=>l.name).join(","))
logger.log(t("已安装运行时:{}"),'@voerkai18n/runtime')
logger.log(t("初始化成功,下一步:"))
logger.log(t(" - 编辑{}确定拟支持的语言种类等参数"),"languages/settings.json")
logger.log(t(" - 运行<{}>扫描提取要翻译的文本"),"voerkai18n extract")
logger.log(t(" - 运行<{}>编译语言包"),"voerkai18n compile")
}
logger.log(t("生成语言配置文件:{}"),"./languages/settings.json")
logger.log(t("拟支持的语言:{}"),settings.languages.map(l=>l.name).join(","))
logger.log(t("已安装运行时:{}"),'@voerkai18n/runtime')
logger.log(t("初始化成功,下一步:"))
logger.log(t(" - 编辑{}确定拟支持的语言种类等参数"),"languages/settings.json")
logger.log(t(" - 运行<{}>扫描提取要翻译的文本"),"voerkai18n extract")
logger.log(t(" - 运行<{}>编译语言包"),"voerkai18n compile")
}
const program = new Command();
program
.argument('[location]', t('工程项目所在目录'))
.description(t('初始化项目国际化配置'))
.option('-D, --debug', t('输出调试信息'))
.option('-m, --moduleType [types]', t('输出模块类型,取值auto,esm,cjs'), 'auto')
.option('-r, --reset', t('重新生成当前项目的语言配置'))
.option('-t, --typescript',t("输出typescript代码"))
.option('-lngs, --languages <languages...>', t('支持的语言列表'), ['zh','en'])
.option('-d, --defaultLanguage <name>', t('默认语言'), 'zh')
.option('-a, --activeLanguage <name>', t('激活语言'), 'zh')
.hook("preAction",async function(location){
const lang= process.env.LANGUAGE || "zh"
await VoerkaI18nScope.change(lang)
})
.action(async (location,options) => {
options.isTypeScript = options.typescript==undefined ? isTypeScriptProject() : options.typescript
location = getProjectSourceFolder(location)
logger.log(t("工程目录:{}"),location)
//
if(options.debug){
logger.format(options,{compact:true})
}
await initializer.call(options,location,options)
});
program.parseAsync(process.argv);

View File

@ -3,8 +3,8 @@
*/
const messageIds = require("./idMap")
const { translate,i18nScope } = require("@voerkai18n/runtime")
const defaultFormatters = require("@voerkai18n/runtime/formatters/zh.js")
const { translate,VoerkaI18nScope } = require("@voerkai18n/runtime")
const defaultFormatters = require("./formatters/zh.js")
const activeFormatters = defaultFormatters
const defaultMessages = require("./zh.js") // 默认语言包
const activeMessages = defaultMessages

View File

@ -0,0 +1,454 @@
{
" - 更新格式化器:{}": {
"en": " - Update formatters:{}",
"$file": [
"compile.command.js"
],
"de": " - 更新格式化器:{}"
},
" - 访问入口文件: {}": {
"en": " - Entry of language: {}",
"$file": [
"compile.command.js"
],
"de": " - 访问入口文件: {}"
},
"加载多语言配置文件<{}>失败: {} ": {
"en": "Failed to load multilingual configuration file <{}>: {}",
"$file": [
"compile.command.js"
],
"de": "加载多语言配置文件<{}>失败: {} "
},
"目标文件夹<{}>不存在": {
"en": "The destination folder < {} > does not exist",
"$file": [
"extract.command.js"
],
"de": "目标文件夹<{}>不存在"
},
"扫描提取范围:": {
"en": "Scan for",
"$file": [
"extract.command.js"
],
"de": "扫描提取范围:"
},
"工程项目所在目录": {
"en": "Project directory",
"$file": [
"index.js"
],
"de": "工程项目所在目录"
},
"初始化项目国际化配置": {
"en": "Initialize project i18n configuration",
"$file": [
"index.js"
],
"de": "初始化项目国际化配置"
},
"输出调试信息": {
"en": "Output debug information",
"$file": [
"index.js"
],
"de": "输出调试信息"
},
"重新生成当前项目的语言配置": {
"en": "Regenerate the language configuration of the current project",
"$file": [
"index.js"
],
"de": "重新生成当前项目的语言配置"
},
"支持的语言列表": {
"en": "Supported languages",
"$file": [
"index.js"
],
"de": "支持的语言列表"
},
"工程目录:{}": {
"en": "Folder of project{}",
"$file": [
"index.js"
],
"de": "工程目录:{}"
},
"扫描并提取所有待翻译的字符串到<languages/translates>文件夹中": {
"en": "Scan and extract all strings to be translated into the <languages/translations> folder",
"$file": [
"index.js"
],
"de": "扫描并提取所有待翻译的字符串到<languages/translates>文件夹中"
},
"支持的语言": {
"en": "Supported languages",
"$file": [
"index.js"
],
"de": "支持的语言"
},
"默认语言": {
"en": "Default language",
"$file": [
"index.js"
],
"de": "默认语言"
},
"激活语言": {
"en": "Active language",
"$file": [
"index.js"
],
"de": "激活语言"
},
"翻译名称空间": {
"en": "Namespaces",
"$file": [
"index.js"
],
"de": "翻译名称空间"
},
"排除要扫描的文件夹,多个用逗号分隔": {
"en": "Exclude folders to scan, multiple separated by commas",
"$file": [
"index.js"
],
"de": "排除要扫描的文件夹,多个用逗号分隔"
},
"本次提取内容与已存在内容的数据合并策略,默认取值sync=同步,overwrite=覆盖,merge=合并": {
"en": " strategy of messages merge,with value of sync(default),overwrite,merge",
"$file": [
"index.js"
],
"de": "本次提取内容与已存在内容的数据合并策略,默认取值sync=同步,overwrite=覆盖,merge=合并"
},
"要扫描的文件类型": {
"en": "Type of file to scan",
"$file": [
"index.js"
],
"de": "要扫描的文件类型"
},
"语言配置文件<{}>已存在,将优先使用此配置文件中参数来提取文本": {
"en": "The language configuration file <{}> already exists. It will be used preferentially to extract messages",
"$file": [
"index.js"
],
"de": "语言配置文件<{}>已存在,将优先使用此配置文件中参数来提取文本"
},
"编译指定项目的语言包": {
"en": "Compiles the language messages for project",
"$file": [
"index.js"
],
"de": "编译指定项目的语言包"
},
"输出模块类型,取值auto,esm,cjs": {
"en": "Output module type, values auto, esm, cjs",
"$file": [
"index.js"
],
"de": "输出模块类型,取值auto,esm,cjs"
},
"语言包文件夹<{}>不存在": {
"en": "The language messages folder <{}> does not exist",
"$file": [
"index.js"
],
"de": "语言包文件夹<{}>不存在"
},
"生成语言配置文件:{}": {
"en": "Generate language configuration: {}",
"$file": [
"init.command.js"
],
"de": "生成语言配置文件:{}"
},
"拟支持的语言:{}": {
"en": "Languages to be supported{}",
"$file": [
"init.command.js"
],
"de": "拟支持的语言:{}"
},
"初始化成功,下一步:": {
"en": "Initialization succeeded, next step",
"$file": [
"init.command.js"
],
"de": "初始化成功,下一步:"
},
" - 编辑{}确定拟支持的语言种类等参数": {
"en": " - Edit language parameters in {}",
"$file": [
"init.command.js"
],
"de": " - 编辑{}确定拟支持的语言种类等参数"
},
" - 运行<{}>扫描提取要翻译的文本": {
"en": " - Run <{}> scan to extract the messages to be translated",
"$file": [
"init.command.js"
],
"de": " - 运行<{}>扫描提取要翻译的文本"
},
" - 运行<{}>编译语言包": {
"en": " - Run <{}> compile language messages",
"$file": [
"init.command.js"
],
"de": " - 运行<{}>编译语言包"
},
"创建语言包文件夹: {}": {
"en": "Create <languages> folder: {}",
"$file": [
"init.command.js"
],
"de": "创建语言包文件夹: {}"
},
"编译结果输出至:{}": {
"en": "Compile to{}",
"$file": [
"compile.command.js"
],
"de": "编译结果输出至:{}"
},
"读取语言文件{}失败:{}": {
"en": "Error while read language file{}: {}",
"$file": [
"compile.command.js"
],
"de": "读取语言文件{}失败:{}"
},
" - 语言包文件: {}": {
"en": " - Language file: {}",
"$file": [
"compile.command.js"
],
"de": " - 语言包文件: {}"
},
" - idMap文件: {}": {
"en": " - idMap file: {}",
"$file": [
"compile.command.js"
],
"de": " - idMap文件: {}"
},
" - 格式化器:{}": {
"en": " - Formatters: {}",
"$file": [
"compile.command.js"
],
"de": " - 格式化器:{}"
},
" - 共合成{}条文本": {
"en": " - Total{} messages",
"$file": [
"compile.command.js"
],
"de": " - 共合成{}条文本"
},
"调用在线翻译服务商的API翻译译指定项目的语言包,如使用百度云翻译服务": {
"en": "Call the API translation language package of the online translation service provider, eg:baidu translation service",
"$file": [
"index.js"
],
"de": "调用在线翻译服务商的API翻译译指定项目的语言包,如使用百度云翻译服务"
},
"API密钥": {
"en": "API密钥",
"$file": [
"index.js"
],
"de": "API密钥"
},
"API ID": {
"en": "API ID",
"$file": [
"index.js"
],
"de": "API ID"
},
"翻译速度限制,即每秒可调用的API次数": {
"en": "Translation speed limit. API calls per second",
"de": "翻译速度限制,即每秒可调用的API次数",
"$file": [
"index.js"
]
},
"在线翻译服务提供者名称或翻译脚本文件": {
"en": "在线翻译服务提供者名称或翻译脚本文件",
"de": "在线翻译服务提供者名称或翻译脚本文件",
"$file": [
"index.js"
]
},
"将多个文本合并提交的最大包字节数": {
"en": "将多个文本合并提交的最大包字节数",
"de": "将多个文本合并提交的最大包字节数",
"$file": [
"index.js"
]
},
"正在翻译文件:{}": {
"en": "正在翻译文件:{}",
"de": "正在翻译文件:{}",
"$file": [
"translate.command.js"
]
},
"需要指定翻译脚本或者appkey和appid": {
"en": "需要指定翻译脚本或者appkey和appid",
"de": "需要指定翻译脚本或者appkey和appid",
"$file": [
"translate.command.js"
]
},
" - 翻译 -> {}": {
"en": " - 翻译 -> {}",
"de": " - 翻译 -> {}",
"$file": [
"translate.command.js"
]
},
"更新@voerkai18n/runtime运行时": {
"en": "更新@voerkai18n/runtime运行时",
"de": "更新@voerkai18n/runtime运行时",
"$file": [
"compile.command.js"
]
},
"Updated:{}": {
"en": "Updated:{}",
"de": "Updated:{}",
"$file": [
"compile.command.js"
]
},
"已经是最新的": {
"en": "已经是最新的",
"de": "已经是最新的",
"$file": [
"compile.command.js"
]
},
"更新@voerkai18n/runtime失败,请手动更新!": {
"en": "更新@voerkai18n/runtime失败,请手动更新!",
"de": "更新@voerkai18n/runtime失败,请手动更新!",
"$file": [
"compile.command.js"
]
},
"支持的语言\\t: {}": {
"en": "支持的语言\\t: {}",
"de": "支持的语言\\t: {}",
"$file": [
"compile.command.js",
"extract.plugin.js"
]
},
"默认语言\\t: {}": {
"en": "默认语言\\t: {}",
"de": "默认语言\\t: {}",
"$file": [
"compile.command.js",
"extract.plugin.js"
]
},
"激活语言\\t: {}": {
"en": "激活语言\\t: {}",
"de": "激活语言\\t: {}",
"$file": [
"compile.command.js",
"extract.plugin.js"
]
},
"名称空间\\t: {}": {
"en": "名称空间\\t: {}",
"de": "名称空间\\t: {}",
"$file": [
"compile.command.js",
"extract.plugin.js"
]
},
"模块类型\\t: {}": {
"en": "模块类型\\t: {}",
"de": "模块类型\\t: {}",
"$file": [
"compile.command.js"
]
},
"TypeScript\\t: {}": {
"en": "TypeScript\\t: {}",
"de": "TypeScript\\t: {}",
"$file": [
"compile.command.js"
]
},
"输出typescript代码": {
"en": "输出typescript代码",
"de": "输出typescript代码",
"$file": [
"index.js"
]
},
"备份原始文件": {
"en": "备份原始文件",
"de": "备份原始文件",
"$file": [
"index.js"
]
},
"翻译模式取值auto=仅翻译未翻译的,full=全部翻译": {
"en": "翻译模式取值auto=仅翻译未翻译的,full=全部翻译",
"de": "翻译模式取值auto=仅翻译未翻译的,full=全部翻译",
"$file": [
"index.js"
]
},
"语言配置文件{}文件已存在,跳过创建。\\n使用{}可以重新覆盖创建": {
"en": "语言配置文件{}文件已存在,跳过创建。\\n使用{}可以重新覆盖创建",
"de": "语言配置文件{}文件已存在,跳过创建。\\n使用{}可以重新覆盖创建",
"$file": [
"init.command.js"
]
},
"安装运行时依赖@voerkai18n/runtime": {
"en": "安装运行时依赖@voerkai18n/runtime",
"de": "安装运行时依赖@voerkai18n/runtime",
"$file": [
"init.command.js"
]
},
"已安装运行时:{}": {
"en": "已安装运行时:{}",
"de": "已安装运行时:{}",
"$file": [
"init.command.js"
]
},
"自动更新runtime": {
"en": "自动更新runtime",
"de": "自动更新runtime",
"$file": [
"compile.command.js"
]
},
"扫描并提取待翻译的文本到<languages/translates>": {
"en": "扫描并提取待翻译的文本到<languages/translates>",
"de": "扫描并提取待翻译的文本到<languages/translates>",
"$file": [
"index.js"
]
},
"在线翻译语言包,如使用百度云翻译服务": {
"en": "在线翻译语言包,如使用百度云翻译服务",
"de": "在线翻译语言包,如使用百度云翻译服务",
"$file": [
"index.js"
]
}
}

View File

@ -4,379 +4,379 @@
"$file": [
"compile.command.js"
],
"de": " - 更新格式化器:{}"
"de": "-Formatierer aktualisieren: {}"
},
" - 访问入口文件: {}": {
"en": " - Entry of language: {}",
"$file": [
"compile.command.js"
],
"de": " - 访问入口文件: {}"
"de": "-Zugriffsdatei: {}"
},
"加载多语言配置文件<{}>失败: {} ": {
"en": "Failed to load multilingual configuration file <{}>: {}",
"$file": [
"compile.command.js"
],
"de": "加载多语言配置文件<{}>失败: {} "
"de": "Laden der mehrsprachigen Konfigurationsdatei fehlgeschlagen<{}>: {}"
},
"目标文件夹<{}>不存在": {
"en": "The destination folder < {} > does not exist",
"$file": [
"extract.command.js"
],
"de": "目标文件夹<{}>不存在"
"de": "Der Zielordner<{}>existiert nicht"
},
"扫描提取范围:": {
"en": "Scan for",
"$file": [
"extract.command.js"
],
"de": "扫描提取范围:"
"de": "Scanextraktionsbereich:"
},
"工程项目所在目录": {
"en": "Project directory",
"$file": [
"index.js"
],
"de": "工程项目所在目录"
"de": "Projektverzeichnis"
},
"初始化项目国际化配置": {
"en": "Initialize project i18n configuration",
"$file": [
"index.js"
],
"de": "初始化项目国际化配置"
"de": "Konfiguration der Projektinternationalisierung initialisieren"
},
"输出调试信息": {
"en": "Output debug information",
"$file": [
"index.js"
],
"de": "输出调试信息"
"de": "Debugging-Informationen ausgeben"
},
"重新生成当前项目的语言配置": {
"en": "Regenerate the language configuration of the current project",
"$file": [
"index.js"
],
"de": "重新生成当前项目的语言配置"
"de": "Die Sprachkonfiguration des aktuellen Projekts neu erstellen"
},
"支持的语言列表": {
"en": "Supported languages",
"$file": [
"index.js"
],
"de": "支持的语言列表"
"de": "Liste der unterstützten Sprachen"
},
"工程目录:{}": {
"en": "Folder of project{}",
"$file": [
"index.js"
],
"de": "工程目录:{}"
"de": "Projektverzeichnis: {}"
},
"扫描并提取所有待翻译的字符串到<languages/translates>文件夹中": {
"en": "Scan and extract all strings to be translated into the <languages/translations> folder",
"$file": [
"index.js"
],
"de": "扫描并提取所有待翻译的字符串到<languages/translates>文件夹中"
"de": "Scannen und extrahieren Sie alle zu übersetzenden Zeichenfolgen in den Ordner <languages/translations>"
},
"支持的语言": {
"en": "Supported languages",
"$file": [
"index.js"
],
"de": "支持的语言"
"de": "Unterstützte Sprachen"
},
"默认语言": {
"en": "Default language",
"$file": [
"index.js"
],
"de": "默认语言"
"de": "Standardsprache"
},
"激活语言": {
"en": "Active language",
"$file": [
"index.js"
],
"de": "激活语言"
"de": "Sprache aktivieren"
},
"翻译名称空间": {
"en": "Namespaces",
"$file": [
"index.js"
],
"de": "翻译名称空间"
"de": "Übersetzungsnamensraum"
},
"排除要扫描的文件夹,多个用逗号分隔": {
"en": "Exclude folders to scan, multiple separated by commas",
"$file": [
"index.js"
],
"de": "排除要扫描的文件夹,多个用逗号分隔"
"de": "Zu scannende Ordner ausschließen, mehrere werden durch Kommas getrennt"
},
"本次提取内容与已存在内容的数据合并策略,默认取值sync=同步,overwrite=覆盖,merge=合并": {
"en": " strategy of messages merge,with value of sync(default),overwrite,merge",
"$file": [
"index.js"
],
"de": "本次提取内容与已存在内容的数据合并策略,默认取值sync=同步,overwrite=覆盖,merge=合并"
"de": "Die Datenzusammenführungsrichtlinie des extrahierten Inhalts und des vorhandenen Inhalts. Standardwerte sind sync=synchronization, overwrite=überschreiben, merge=merge"
},
"要扫描的文件类型": {
"en": "Type of file to scan",
"$file": [
"index.js"
],
"de": "要扫描的文件类型"
"de": "Zu scannender Dateityp"
},
"语言配置文件<{}>已存在,将优先使用此配置文件中参数来提取文本": {
"en": "The language configuration file <{}> already exists. It will be used preferentially to extract messages",
"$file": [
"index.js"
],
"de": "语言配置文件<{}>已存在,将优先使用此配置文件中参数来提取文本"
"de": "Die Sprachkonfigurationsdatei<{}>existiert bereits. Die Parameter in dieser Konfigurationsdatei werden zuerst zum Extrahieren von Text verwendet."
},
"编译指定项目的语言包": {
"en": "Compiles the language messages for project",
"$file": [
"index.js"
],
"de": "编译指定项目的语言包"
"de": "Kompilieren des Sprachpakets für das angegebene Projekt"
},
"输出模块类型,取值auto,esm,cjs": {
"en": "Output module type, values auto, esm, cjs",
"$file": [
"index.js"
],
"de": "输出模块类型,取值auto,esm,cjs"
"de": "Ausgabemodultyp, Wert auto, esm, cjs"
},
"语言包文件夹<{}>不存在": {
"en": "The language messages folder <{}> does not exist",
"$file": [
"index.js"
],
"de": "语言包文件夹<{}>不存在"
"de": "Der Language Pack Ordner<{}>existiert nicht"
},
"生成语言配置文件:{}": {
"en": "Generate language configuration: {}",
"$file": [
"init.command.js"
],
"de": "生成语言配置文件:{}"
"de": "Sprachprofil generieren: {}"
},
"拟支持的语言:{}": {
"en": "Languages to be supported{}",
"$file": [
"init.command.js"
],
"de": "拟支持的语言:{}"
"de": "Zu unterstützende Sprache: {}"
},
"初始化成功,下一步:": {
"en": "Initialization succeeded, next step",
"$file": [
"init.command.js"
],
"de": "初始化成功,下一步:"
"de": "Initialisierung erfolgreich, nächster Schritt:"
},
" - 编辑{}确定拟支持的语言种类等参数": {
"en": " - Edit language parameters in {}",
"$file": [
"init.command.js"
],
"de": " - 编辑{}确定拟支持的语言种类等参数"
"de": "-Edit {} um den Sprachtyp und andere Parameter zu bestimmen, die unterstützt werden sollen"
},
" - 运行<{}>扫描提取要翻译的文本": {
"en": " - Run <{}> scan to extract the messages to be translated",
"$file": [
"init.command.js"
],
"de": " - 运行<{}>扫描提取要翻译的文本"
"de": "Führen Sie den<{}>Scan aus, um den zu übersetzenden Text zu extrahieren"
},
" - 运行<{}>编译语言包": {
"en": " - Run <{}> compile language messages",
"$file": [
"init.command.js"
],
"de": " - 运行<{}>编译语言包"
"de": "-Führen Sie das<{}>Compile Language Pack aus"
},
"创建语言包文件夹: {}": {
"en": "Create <languages> folder: {}",
"$file": [
"init.command.js"
],
"de": "创建语言包文件夹: {}"
"de": "Sprachpaket-Ordner erstellen: {}"
},
"编译结果输出至:{}": {
"en": "Compile to{}",
"$file": [
"compile.command.js"
],
"de": "编译结果输出至:{}"
"de": "Die Ergebnisse der Zusammenstellung werden ausgegeben an: {}"
},
"读取语言文件{}失败:{}": {
"en": "Error while read language file{}: {}",
"$file": [
"compile.command.js"
],
"de": "读取语言文件{}失败:{}"
"de": "Sprachdatei konnte nicht gelesen werden {}: {}"
},
" - 语言包文件: {}": {
"en": " - Language file: {}",
"$file": [
"compile.command.js"
],
"de": " - 语言包文件: {}"
"de": "Sprachpaket-Datei: {}"
},
" - idMap文件: {}": {
"en": " - idMap file: {}",
"$file": [
"compile.command.js"
],
"de": " - idMap文件: {}"
"de": "-IdMap-Datei: {}"
},
" - 格式化器:{}": {
"en": " - Formatters: {}",
"$file": [
"compile.command.js"
],
"de": " - 格式化器:{}"
"de": "-Formatierer: {}"
},
" - 共合成{}条文本": {
"en": " - Total{} messages",
"$file": [
"compile.command.js"
],
"de": " - 共合成{}条文本"
"de": "-{} Text insgesamt"
},
"调用在线翻译服务商的API翻译译指定项目的语言包,如使用百度云翻译服务": {
"en": "Call the API translation language package of the online translation service provider, eg:baidu translation service",
"$file": [
"index.js"
],
"de": "调用在线翻译服务商的API翻译译指定项目的语言包,如使用百度云翻译服务"
"de": "Rufen Sie die API des Online-Übersetzungsdienstleisters an, um das Sprachpaket des angegebenen Projekts zu übersetzen, z. B. Baidu Cloud Translation Service"
},
"API密钥": {
"en": "API密钥",
"en": "API Key",
"$file": [
"index.js"
],
"de": "API密钥"
"de": "API-Schlüssel"
},
"API ID": {
"en": "API ID",
"$file": [
"index.js"
],
"de": "API ID"
"de": "API-ID"
},
"翻译速度限制,即每秒可调用的API次数": {
"en": "Translation speed limit. API calls per second",
"de": "翻译速度限制,即每秒可调用的API次数",
"de": "Übersetzungsgeschwindigkeitsbegrenzung, d. h. die Anzahl der API-Aufrufe pro Sekunde",
"$file": [
"index.js"
]
},
"在线翻译服务提供者名称或翻译脚本文件": {
"en": "在线翻译服务提供者名称或翻译脚本文件",
"de": "在线翻译服务提供者名称或翻译脚本文件",
"en": "Online translation service provider name or translation script file",
"de": "Name des Online-Übersetzungsdienstleisters oder der Übersetzungsskriptdatei",
"$file": [
"index.js"
]
},
"将多个文本合并提交的最大包字节数": {
"en": "将多个文本合并提交的最大包字节数",
"de": "将多个文本合并提交的最大包字节数",
"en": "The maximum number of packet bytes submitted by merging multiple texts",
"de": "Die maximale Anzahl an Paketbytes, die durch Zusammenführen mehrerer Texte gesendet werden",
"$file": [
"index.js"
]
},
"正在翻译文件:{}": {
"en": "正在翻译文件:{}",
"de": "正在翻译文件:{}",
"en": "Translating file: {}",
"de": "Datei übersetzen: {}",
"$file": [
"translate.command.js"
]
},
"需要指定翻译脚本或者appkey和appid": {
"en": "需要指定翻译脚本或者appkey和appid",
"de": "需要指定翻译脚本或者appkey和appid",
"en": "You need to specify the translation script or appkey and appid",
"de": "Sie müssen das Übersetzungsskript oder appkey und appid angeben",
"$file": [
"translate.command.js"
]
},
" - 翻译 -> {}": {
"en": " - 翻译 -> {}",
"de": " - 翻译 -> {}",
"en": "-Translation ->{}",
"de": "-Übersetzung ->{}",
"$file": [
"translate.command.js"
]
},
"更新@voerkai18n/runtime运行时": {
"en": "更新@voerkai18n/runtime运行时",
"de": "更新@voerkai18n/runtime运行时",
"en": "Update @ voerkai18n/runtime runtime",
"de": "Update von voerkai18n/runtime runtime",
"$file": [
"compile.command.js"
]
},
"Updated:{}": {
"en": "Updated:{}",
"de": "Updated:{}",
"de": "Aktualisiert:{}",
"$file": [
"compile.command.js"
]
},
"已经是最新的": {
"en": "已经是最新的",
"de": "已经是最新的",
"en": "It is the latest",
"de": "Es ist die neueste",
"$file": [
"compile.command.js"
]
},
"更新@voerkai18n/runtime失败,请手动更新!": {
"en": "更新@voerkai18n/runtime失败,请手动更新!",
"de": "更新@voerkai18n/runtime失败,请手动更新!",
"en": "Failed to update @ voerkai18n/runtime, please update manually!",
"de": "Fehler beim Update von voerkai18n/runtime, bitte manuell aktualisieren!",
"$file": [
"compile.command.js"
]
},
"支持的语言\\t: {}": {
"en": "支持的语言\\t: {}",
"de": "支持的语言\\t: {}",
"en": "Supported languages t: {}",
"de": "Unterstützte Sprachen t: {}",
"$file": [
"compile.command.js",
"extract.plugin.js"
]
},
"默认语言\\t: {}": {
"en": "默认语言\\t: {}",
"de": "默认语言\\t: {}",
"en": "Default language t: {}",
"de": "Standardsprache t: {}",
"$file": [
"compile.command.js",
"extract.plugin.js"
]
},
"激活语言\\t: {}": {
"en": "激活语言\\t: {}",
"de": "激活语言\\t: {}",
"en": "Activation language t: {}",
"de": "Aktivierungssprache t: {}",
"$file": [
"compile.command.js",
"extract.plugin.js"
]
},
"名称空间\\t: {}": {
"en": "名称空间\\t: {}",
"de": "名称空间\\t: {}",
"en": "Namespace t: {}",
"de": "Namensraum t: {}",
"$file": [
"compile.command.js",
"extract.plugin.js"
]
},
"模块类型\\t: {}": {
"en": "模块类型\\t: {}",
"de": "模块类型\\t: {}",
"en": "Module type t: {}",
"de": "Modultyp t: {}",
"$file": [
"compile.command.js"
]
@ -389,45 +389,66 @@
]
},
"输出typescript代码": {
"en": "输出typescript代码",
"de": "输出typescript代码",
"en": "Output typescript code",
"de": "Ausgabetypscript code",
"$file": [
"index.js"
]
},
"备份原始文件": {
"en": "备份原始文件",
"de": "备份原始文件",
"en": "Back up original files",
"de": "Originaldateien sichern",
"$file": [
"index.js"
]
},
"翻译模式取值auto=仅翻译未翻译的,full=全部翻译": {
"en": "翻译模式取值auto=仅翻译未翻译的,full=全部翻译",
"de": "翻译模式取值auto=仅翻译未翻译的,full=全部翻译",
"en": "Translation mode, value auto=translate only untranslated, full=translate all",
"de": "Übersetzungsmodus, Wert auto=translate nur unübersetzt, full=translate all",
"$file": [
"index.js"
]
},
"语言配置文件{}文件已存在,跳过创建。\\n使用{}可以重新覆盖创建": {
"en": "语言配置文件{}文件已存在,跳过创建。\\n使用{}可以重新覆盖创建",
"de": "语言配置文件{}文件已存在,跳过创建。\\n使用{}可以重新覆盖创建",
"en": "The language configuration file {} already exists, skipping creation. \\N Use {} to overwrite the creation",
"de": "Die Sprachkonfigurationsdatei {} existiert bereits, die Erstellung wird übersprungen. \\N Verwenden Sie {} um die Erstellung zu überschreiben",
"$file": [
"init.command.js"
]
},
"安装运行时依赖@voerkai18n/runtime": {
"en": "安装运行时依赖@voerkai18n/runtime",
"de": "安装运行时依赖@voerkai18n/runtime",
"en": "Install runtime dependency @ voerkai18n/runtime",
"de": "Runtime dependency=voerkai18n/runtime installieren",
"$file": [
"init.command.js"
]
},
"已安装运行时:{}": {
"en": "已安装运行时:{}",
"de": "已安装运行时:{}",
"en": "Runtime installed: {}",
"de": "Laufzeit installiert: {}",
"$file": [
"init.command.js"
]
},
"自动更新runtime": {
"en": "Automatically update runtime",
"de": "Laufzeit automatisch aktualisieren",
"$file": [
"compile.command.js"
]
},
"扫描并提取待翻译的文本到<languages/translates>": {
"en": "Scan and extract the text to be translated to<languages/translations>",
"de": "Scannen und extrahieren Sie den zu übersetzenden Text in<languages/translations>",
"$file": [
"index.js"
]
},
"在线翻译语言包,如使用百度云翻译服务": {
"en": "Online translation language packs, such as Baidu Cloud Translation Service",
"de": "Sprachpakete für Online-Übersetzungen wie Baidu Cloud Translation Service",
"$file": [
"index.js"
]
}
}

View File

@ -11,8 +11,8 @@ import defaultMessages from "./{{defaultLanguage}}.js"
{{if defaultLanguage === activeLanguage}}const activeMessages = defaultMessages{{else}}import activeMessages from "./{{activeLanguage}}.js"{{/if}}
{{else}}
const messageIds = require("./idMap")
const { translate,i18nScope } = require("@voerkai18n/runtime")
const defaultFormatters = require("@voerkai18n/runtime/formatters/{{defaultLanguage}}.js")
const { translate,VoerkaI18nScope } = require("@voerkai18n/runtime")
const defaultFormatters = require("./formatters/{{defaultLanguage}}.js")
{{if defaultLanguage === activeLanguage}}const activeFormatters = defaultFormatters{{else}}const activeFormatters = require("@voerkai18n/runtime/formatters/{{activeLanguage}}.js"){{/if}}
const defaultMessages = require("./{{defaultLanguage}}.js") // 默认语言包
{{if defaultLanguage === activeLanguage}}const activeMessages = defaultMessages{{else}}const activeMessages = require("./{{activeLanguage}}.js"){{/if}}

View File

@ -36,5 +36,5 @@ const scope = new VoerkaI18nScope({
const scopedTtranslate = translate.bind(scope)
export {
scopedTtranslate as t,
scope as i18nScope
scope as VoerkaI18nScope
}

View File

@ -1,3 +1,4 @@
#!/usr/bin/env node
/**
* 将extract插件扫描的文件编译为语言文件
@ -25,12 +26,12 @@
const createLogger = require("logsets")
const path = require("path")
const { t } = require("./i18nProxy")
const { i18nScope,t } = require("./i18nProxy")
const fs = require("fs-extra")
const { glob } = require("glob")
const { default: axios } = require("axios")
const logger = createLogger()
const { deepMerge } = require("@voerkai18n/utils")
const { deepMerge,getProjectSourceFolder } = require("@voerkai18n/utils")
const { Command } = require('commander');
const delay = async (t) => new Promise(resolve=>setTimeout(resolve,t))
@ -162,7 +163,7 @@ async function translateMessageFile(file,langSettings,options={}){
module.exports =async function translate(srcFolder,opts={}){
async function translate(srcFolder,opts={}){
const options = normalizeTranslateOptions(opts);
let { backup, appkey,appid,provider="baidu",qps=1 } = options;
if(!provider && !(appkey && appid) ) throw new Error(t("需要指定翻译脚本或者appkey和appid"))
@ -185,7 +186,30 @@ module.exports =async function translate(srcFolder,opts={}){
fs.copyFileSync(file,backupFile)
}
// 翻译文件
let results = await translateMessageFile.call(context,file,langSettings,options)
await translateMessageFile.call(context,file,langSettings,options)
}
}
const program = new Command();
program
.argument('[location]', t('工程项目所在目录'))
.description(t('调用在线翻译服务商的API翻译译指定项目的语言包,如使用百度云翻译服务'))
.option('--no-backup', t('备份原始文件'))
.option('--mode', t('翻译模式取值auto=仅翻译未翻译的,full=全部翻译'), 'auto')
.option('-p, --provider <value>', t('在线翻译服务提供者名称或翻译脚本文件'), 'baidu')
.option('-m, --max-package-size <value>', t('将多个文本合并提交的最大包字节数'), 200)
.option('--appid [id]', t('API ID'))
.option('--appkey [key]', t('API密钥'))
.option('-q, --qps <value>', t('翻译速度限制,即每秒可调用的API次数'), 1)
.hook("preAction",async function(location){
const lang= process.env.LANGUAGE || "zh"
await i18nScope.change(lang)
})
.action((location,options) => {
location = getProjectSourceFolder(location)
translate(location,options)
});
program.parseAsync(process.argv);

View File

@ -521,20 +521,21 @@ function createPackageJsonFile(targetPath,moduleType="auto"){
}
function installPackage(packageName){
async function installPackage(packageName,{silent}={silent:true}){
const packageTool = getPackageTool()
try{
if(packageTool=='pnpm'){
shelljs.exec(`pnpm add ${packageName}`)
await asyncExecShellScript(`pnpm add ${packageName}`,{silent})
}else if(packageTool=='yarn'){
shelljs.exec(`yarn add ${packageName}`)
await asyncExecShellScript(`yarn add ${packageName}`,{silent})
}else{
shelljs.exec(`npm install ${packageName}`)
await asyncExecShellScript(`npm install ${packageName}`,{silent})
}
}catch{
shelljs.exec(`npm install ${packageName}`)
await asyncExecShellScript(`npm install ${packageName}`,{silent})
}
}
function upgradePackage(packageName){
const packageTool = getPackageTool()
try{
@ -679,7 +680,7 @@ function importTranslateFunction(code,sourceFile,langPath){
*/
function getInstalledPackageInfo(packageName,fields=[]){
try{
const packagePath = path.dirname(require.resolve(packageName))
const packagePath = getProjectRootFolder(path.dirname(require.resolve(packageName)))
const pkgInfo = fs.readJSONSync(path.join(packagePath,"package.json"))
let results = {
version: pkgInfo.version,