npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bdtrans/trans-cli

v1.0.5

Published

Baidu AI translation CLI — text, doc, image, audio.

Readme

trans-cli

百度翻译 AI 命令行工具 — 支持 200+ 语种,终端、管道、JSON 输出开箱即用。

$ trans text "你好世界"
Hello World

目录


安装

前置条件:百度翻译 AI API Key

  1. 注册并开通免费额度
  2. 控制台获取 API Key

安装 CLI

npm install -g @bdtrans/trans-cli

要求 Node.js 18+


快速开始

# 1. 设置 API Key(环境变量方式)
export TRANS_API_KEY=your_api_key_here

# 2. 验证配置
trans doctor

# 3. 翻译
trans text "你好世界"

也可以通过配置文件持久化:

trans config init
trans config set api_key your_api_key_here

功能

| 子命令 | 描述 | 状态 | |--------|------|------| | trans text | 文本翻译,支持 200+ 语种互译 | 可用 | | trans config | 初始化和管理配置 | 可用 | | trans doctor | 自检:API Key、网络连通性、账户状态 | 可用 | | trans doc | 文档翻译 | 即将支持 | | trans image | 图片翻译 / OCR | 即将支持 | | trans audio | 语音翻译 | 即将支持 |

使用示例

# 基本翻译(自动检测源语言)
trans text "你好世界"

# 指定目标语言
trans text "Hello World" --to zh

# 管道用法
echo "今天天气真好" | trans text

# JSON 输出(适合脚本集成)
trans text "你好" --json

配置

优先级(由高到低):--api-key flag > TRANS_API_KEY 环境变量 > ~/.trans-cli/config.json

{
  "api_key": "your_api_key"
}

错误处理

成功结果写入 stdout,所有错误写入 stderr,适合管道和脚本集成。

退出码

| 退出码 | 含义 | |--------|------| | 0 | 成功 | | 1 | 参数错误、输入为空 | | 2 | 鉴权或配置问题 | | 3 | API 业务错误(余额不足、频率超限等) | | 4 | 网络错误 |

--json 模式错误码

| code | 含义 | 解决方法 | |--------|------|---------| | CONFIG_MISSING | API Key 未配置 | 设置 TRANS_API_KEY 环境变量 | | AUTH_FAILED | Key 无效或未开通服务 | 检查 Key 及服务开通状态 | | QUOTA_EXCEEDED | 账户余额不足 | 前往充值 | | RATE_LIMITED | 请求过于频繁 | 降低调用频率或升级套餐 | | NETWORK_ERROR | 网络不可达 | 检查网络连接 | | INVALID_INPUT | 输入为空或非法 | 检查输入内容 | | INVALID_LANGUAGE | 不支持的语言代码 | 查阅支持语种列表 | | API_ERROR | 其他 API 错误 | 重试,或联系支持 |


支持语种

支持 200+ 语种互译,覆盖 4 万多个语言方向,源语言支持自动检测。

完整语种列表:fanyi-api.baidu.com/doc/21


许可证

MIT


联系我们

问题反馈或商务合作:[email protected]