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

lrk-trans-cn-cli

v1.0.1

Published

CLI 帮助文档翻译工具 - 将英文命令帮助信息翻译为简体中文

Downloads

247

Readme

lrk-trans-cn-cli

CLI 帮助文档翻译工具 - 将英文命令帮助信息翻译为简体中文

安装

本地使用

# 克隆仓库后
npm link

# 或直接在项目目录使用
node bin/trans-cn.js

全局安装

npm install -g .

卸载

npm uninstall -g lrk-trans-cn-cli

使用方法

基本用法

通过管道将 CLI 帮助文档传递给 trans-cn

# 翻译任何命令的帮助文档
xxx --help | trans-cn

# 示例
docker --help | trans-cn
git --help | trans-cn
npm --help | trans-cn
kubectl --help | trans-cn

显示翻译统计

使用 --info 参数可在翻译完成后显示统计信息:

xxx --help | trans-cn --info

输出示例:

playwright-cli - 从终端运行 playwright mcp 命令

用法: playwright-cli <命令> [参数] [选项]
...

┌─────────────────────────────────────────┐
│           翻译完成统计                  │
├─────────────────────────────────────────┤
│  翻译耗时: 2.34s                        │
│  输入 Token: 245                        │
│  输出 Token: 189                        │
│  总 Token: 434                          │
└─────────────────────────────────────────┘

初始化配置

首次使用需要先配置 API 信息:

trans-cn --init

执行后会进入交互式配置流程:

  1. 选择模型服务商(输入序号):

    请选择模型服务商:
      1. 阿里云百炼
      2. DeepSeek
      3. Kimi (Moonshot)
      4. MiniMax
      5. 火山引擎
      6. Anthropic (Claude)
      7. OpenAI
      8. 自定义配置
  2. 选择模型:从预设列表选择或自定义输入

    可用模型:
      1. qwen-turbo
      2. qwen-plus
      3. qwen-max
      4. qwen-coder-plus
      5. 自定义输入
  3. 输入 API Key(输入时显示为 *

配置完成后,会在 ~/.trans-cn/config.json 创建配置文件。

配置

支持两种方式配置 LLM 参数,环境变量优先级高于配置文件

1. 环境变量(优先级最高)

export TRANS_CN_MODEL=claude-sonnet-4-6
export TRANS_CN_BASE_URL=https://api.anthropic.com
export TRANS_CN_API_KEY=your-api-key
export TRANS_CN_TARGET_LANG=zh-CN

2. 配置文件

配置文件位置:~/.trans-cn/config.json

示例配置:

{
  "model": "claude-sonnet-4-6",
  "baseUrl": "https://api.anthropic.com",
  "apiKey": "your-api-key",
  "targetLanguage": "zh-CN"
}

配置不同服务商示例

阿里云百炼

{
  "model": "qwen-plus",
  "baseUrl": "https://dashscope.aliyuncs.com",
  "apiKey": "sk-xxxxx",
  "apiPath": "/compatible-mode/v1/chat/completions"
}

DeepSeek

{
  "model": "deepseek-chat",
  "baseUrl": "https://api.deepseek.com",
  "apiKey": "sk-xxxxx",
  "apiPath": "/chat/completions"
}

Kimi (Moonshot)

{
  "model": "moonshot-v1-32k",
  "baseUrl": "https://api.moonshot.cn",
  "apiKey": "sk-xxxxx"
}

火山引擎

{
  "model": "doubao-1.5-pro-32k",
  "baseUrl": "https://ark.cn-beijing.volces.com",
  "apiKey": "xxxxx",
  "apiPath": "/api/v3/chat/completions"
}

Anthropic Claude

{
  "model": "claude-sonnet-4-6",
  "baseUrl": "https://api.anthropic.com",
  "apiKey": "sk-ant-xxxxx"
}

OpenAI

{
  "model": "gpt-4o",
  "baseUrl": "https://api.openai.com",
  "apiKey": "sk-xxxxx"
}

Ollama(本地模型)

{
  "model": "llama2",
  "baseUrl": "http://localhost:11434",
  "apiKey": "ollama"
}

支持的模型服务商

| 服务商 | 预设模型 | API 格式 | 输出方式 | |--------|----------|----------|----------| | 阿里云百炼 | qwen-turbo, qwen-plus, qwen-max, qwen-coder-plus | OpenAI 兼容 | 流式输出 | | DeepSeek | deepseek-chat, deepseek-reasoner | OpenAI 兼容 | 流式输出 | | Kimi (Moonshot) | moonshot-v1-8k, moonshot-v1-32k, moonshot-v1-128k | OpenAI 兼容 | 流式输出 | | MiniMax | abab6.5s-chat, abab6.5-chat, abab7-chat-preview | OpenAI 兼容 | 流式输出 | | 火山引擎 | doubao-1.5-pro-32k, doubao-1.5-lite-32k, doubao-pro-4k | OpenAI 兼容 | 流式输出 | | Anthropic (Claude) | claude-sonnet-4-6, claude-opus-4-6, claude-haiku-4-5 | Anthropic Messages | 进度条 | | OpenAI | gpt-4o, gpt-4o-mini, gpt-4-turbo | OpenAI 兼容 | 流式输出 |

特性

流式输出

支持 SSE 流式输出的服务商(阿里云百炼、DeepSeek、Kimi、MiniMax、火山引擎、OpenAI)会实时逐字显示翻译结果,体验更流畅。

进度条

Anthropic 使用非流式输出,显示进度条:

[████████████████████░░░░░░░░] 85%

自定义模型

初始化配置时支持选择"自定义输入",可手动输入任意模型名称,适配最新模型或私有部署模型。

统计信息

使用 --info 参数可显示:

  • 翻译耗时(秒)
  • 输入 Token 数
  • 输出 Token 数
  • 总 Token 数

Token 估算规则:中文约 1 字 ≈ 1 token,英文约 1 词 ≈ 1.3 tokens

示例效果

输入:

$ docker --help | trans-cn

输出:

docker - 用于管理容器的自包含运行时环境

用法: docker [选项] 命令 [参数...]

选项:
      --config string      客户端配置文件位置 (默认 "/Users/user/.docker")
  -c, --context string     使用连接到指定守护进程的上下文 (覆盖 DOCKER_HOST 环境变量)
  -D, --debug              启用调试模式
  -H, --host list          要连接的守护进程套接字

管理命令:
  builder     管理 builds
  container   管理容器
  image       管理镜像
  network     管理网络
  volume      管理卷

运行命令:
  attach      将本地标准输入、输出和错误流附加到正在运行的容器
  build       从 Dockerfile 构建镜像
  exec        在运行中的容器中执行命令
  logs        获取容器的日志
  run         在新容器中运行命令

对比原英文:

docker - A self-sufficient runtime for containers

Usage: docker [OPTIONS] COMMAND [ARG...]

Options:
      --config string      Location of client config files (default "/Users/user/.docker")

Management Commands:
  builder     Manage builds
  container   Manage containers

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile

工作原理

  1. 接收输入:从 stdin 读取英文 CLI 帮助文本
  2. 智能翻译:通过 LLM API 进行翻译,使用优化的 Prompt 确保:
    • 保留所有命令、参数、选项的原始英文形式
    • 仅翻译描述性文字
    • 保持原有的格式和缩进
    • 使用专业、简洁的技术中文表达
  3. 输出结果
    • 流式输出:逐字显示翻译结果(SSE 支持的服务商)
    • 进度条:显示翻译进度(Anthropic)
  4. 统计信息(可选):计算并显示翻译耗时和 Token 消耗

注意事项

  • 需要配置有效的 LLM API Key:请先完成初始化配置
  • 网络访问:确保可以访问配置的 API endpoint
  • 翻译质量:取决于所选 LLM 的质量,建议使用较强的模型(如 GPT-4、Claude、qwen-max 等)
  • Token 限制:超大文档可能被截断,建议分段翻译

故障排除

错误:没有输入内容

原因:没有通过管道传递输入 解决:使用 xxx --help | trans-cn 格式

错误:未配置 API Key

原因:未设置环境变量或配置文件 解决

  1. 运行 trans-cn --init 进行配置,或
  2. 手动设置环境变量:export TRANS_CN_API_KEY=your-key

翻译结果不完整

原因:超出模型最大 Token 限制 解决:尝试使用支持更大上下文的模型(如 moonshot-v1-128k)

中文显示乱码

原因:终端编码问题 解决:确保终端使用 UTF-8 编码

License

MIT