
Product
Socket MCP Adds Org Alerts, Threat Feed Review, and Package Inspection
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.
@wakeadmin/bbt
Advanced tools
一个自动化的语言包管理和翻译工具,受启发于《圣经》中的巴别塔故事,旨在解决多语言之间的沟通障碍。
bbt 是 Tower of Babel 即巴别塔的拼音首字母,巴别塔是出自《圣经》的一则故事,其中人们为显示自己的力量而建塔,最终由于语言的障碍而失败。我们的bbt工具旨在解决类似的多语言沟通问题。
作为中文开发者,我们更习惯在中文环境下编程,并且也少有程序员能够掌握多门语言,尤其是比如日语、泰语、法语这类小语种。
因此,我们的程序主要以中文为第一公民。但是,如果我们的程序需要支持多语言,那么我们就需要将中文的内容翻译成其他语言,这就是bbt的初衷。
bbt的工作流程如下:
npx bbt collect)npx bbt translate)npx bbt write)$ npm install @wakeadmin/bbt // or
$ yarn add @wakeadmin/bbt // or
$ pnpm add @wakeadmin/bbt
$ npx bbt [command] <options>
初始化,将生成配置文件
$ npx bbt init
执行 init 命令之后, 会生成 bbt.config.js 配置文件。默认配置如下:
module.exports = {
langs: ['zh', 'en'],
test: '.*\\.tr$',
exclude: ['node_modules'],
};
langs 是我们需要支持的语言,这是一个字符串数组,其中数组的第一项为基准语言,也就是我们会通过基准语言来:
收集所有的符合要求的语言包,并将信息提取到 bbt.csv 中,方便翻译人员进行翻译和校准。当然你也可以使用 bbt translate 自动翻译
| name | shortName | type | description | default | required |
|---|---|---|---|---|---|
| --config | -c | string | 配置文件地址 | ./bbt.config.js | false |
| --strict | boolean | 是否使用strict模式进行对比 | false | false |
$ npx bbt collect
$ npx bbt translate
使用翻译 API 对excel(bbt.csv)文件进行翻译
| name | shortName | type | description | default | required |
|---|---|---|---|---|---|
| --translator | -t | 'google' | 'deepl' | 'chatgpt' | 使用哪个翻译 API, 如果 bbt.config.js 自定义了 translator,则以配置为准 | 'google' | false |
| --proxy | -p | string | 正向代理地址 , 如果为空的话,会通过环境变量进行获取 | - | false |
| --force | -f | boolean | 是否强制进行翻译, 默认情况下只会翻按需翻译(即无翻译内容时翻译), 请谨慎开启 | false | false |
| --model | 'gpt-4' | 'gpt-3.5-turbo' | 使用chatgpt进行翻译时所使用的模型 | 'gpt-3.5-turbo' | false | |
| --api-key | -k | string | 翻译服务的API Key , 如果为空的话,会通过环境变量进行获取 | - | false |
| --base-url | string | 反向代理地址, 如果为空的话,会通过环境变量进行获取 | - | false |
bbt 支持通过 Google、DeepL、ChatGPT 等方案进行初步的机器翻译。如果你想使用其他的翻译服务,可以通过自定义插件的方式进行扩展.
默认使用的就是 Google 翻译
npx bbt translate -t google --api-key GOOGLE_TRANSLATION_API_KEY
可以通过 --api-key 选项或者 BBT_GOOGLE_API_KEY 环境变量来配置 Google 翻译的 API KEY。
我们也建议你将环境变量配置在用户目录下的 .profile 或者 .bashrc 这类文件中,这样可以避免每次都需要输入 API KEY。
Google 翻译需要依赖科学上网,需要自行解决。有两种代理配置方式:
export http_proxy=YOU_PROXY_ADDRESS和 Google 翻译类似,需要通过 --api-key 选项或者 BBT_DEEPL_API_KEY 环境变量来配置 DeepL 翻译的 API KEY。
--model 确定使用的 ChatGPT 模型版本。默认为 gpt-3.5-turbo--base-url 或 BBT_OPEN_AI_BASE_URL 环境变量。如果你自己搭建了 ChatGPT 的代理服务,可以通过这个选项来配置--api-key 或 BBT_OPEN_AI_API_KEY 配置 OPEN AI 的 API KEY$ npx bbt write
将 bbt.csv 的翻译结果回填到对应的语言包中,如果对应的语言包不存在,则会自动创建
| name | shortName | type | description | default | required |
|---|---|---|---|---|---|
| --config | -c | string | 配置文件地址 | ./bbt.config.js | false |
bbt 依赖于以下环境变量
| name | description |
|---|---|
| BBT_OPEN_AI_API_KEY | chatGPT(openAI)服务所依赖的API Key |
| BBT_OPEN_AI_BASE_URL | chatGPT(openAI)服务的反向代理地址 |
| BBT_DEEPL_API_KEY | DeepL服务所依赖的API Key |
| BBT_DEEPL_BASE_URL | DeepL服务的反向代理地址 |
| BBT_GOOGLE_API_KEY | Google服务所依赖的API Key |
| BBT_GOOGLE_BASE_URL | Google服务的反向代理地址 |
| BBT_PROXY | 使用translate命令时的正向代理地址 |
有时候国际化资源并不是使用JSON格式, 因此可以通过plugins.parser来自定义文件的解析方式
export interface FileParser<T = any> {
parse(str: string): Record<string, T>;
stringify(record: Record<string, T>): string;
}
zh.tr
hello 你好
world 世界
bbt.config.js
module.exports = {
// ...other
plugins: {
parser: {
parse(content) {
return Object.fromEntries(content.split(/\n/).map(str => str.split(/\s/)));
},
stringify(record) {
return Object.entries(record)
.map(arr => arr.join(' '))
.join('\n');
},
},
},
};
/**
*
* @param record - 需要翻译的数据源
* @param target - 翻译的目标语言
* @param sourceLanguage - 数据源原本的语言
* @returns Observable<TranslatedList<string>> | Promise<TranslatedList<string>>;
*/
translator: (record: Record<string, string>, target: string, sourceLanguage: string) =>
Observable<TranslatedList<string>> | Promise<TranslatedList<string>>;
// bbt.config.js
module.exports = {
// other
plugins: {
translator: (textMap, target, sourceLanguage) => {
return Promise.resolve(
Object.entries(textMap).map(([key, value]) => ({
target,
key,
translatedText: `${value} - ${target}`,
}))
);
},
},
};
FAQs
The npm package @wakeadmin/bbt receives a total of 33 weekly downloads. As such, @wakeadmin/bbt popularity was classified as not popular.
We found that @wakeadmin/bbt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.

Research
More than 140 Mastra npm packages were compromised in a supply chain attack that used a typosquatted dependency to deliver a cross-platform infostealer during installation.