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

@wceozl/trans-kit

v1.0.0

Published

一个强大的中英文翻译和代码命名CLI工具

Readme

🚀 Trans-Kit

智能翻译 CLI 工具 - 让代码命名和文档翻译更简单 Trans-Kit 是一个强大的中英文翻译命令行工具,专为开发者设计。它不仅能将中文翻译为标准的编程命名,还能扫描代码中的命名问题、翻译注释和文档,让你的代码更加国际化和专业。

✨ 特性

  • 🎯 智能命名翻译 - 将中文快速转换为规范的编程命名
  • 🔍 代码扫描分析 - 自动发现项目中的命名问题
  • 💬 注释双向翻译 - 支持中英文注释互译
  • 📚 文档翻译 - Markdown 文档翻译,保留格式和代码块
  • 🎨 多种命名风格 - 支持驼峰、下划线、帕斯卡、短横线等风格
  • ⚙️ 灵活配置 - 个性化设置翻译偏好
  • 🚀 高性能 - 基于有道翻译 API,准确快速

📦 安装

全局安装(推荐)

npm install -g @wceozl/trans-kit

本地安装

npm install @wceozl/trans-kit
npx @wceozl/trans-kit help

🎯 快速开始

1. 配置翻译 API

首次使用需要配置有道翻译 API 密钥:

trans config youdao

💡 免费注册地址:https://ai.youdao.com/

2. 开始翻译

# 翻译中文为编程命名
trans name "用户信息"
# 输出: userInfo

# 生成不同风格的命名
trans name "用户信息" --snake     # user_info
trans name "用户信息" --pascal    # UserInfo
trans name "用户信息" --kebab     # user-info

3. 扫描项目

# 扫描代码中的命名问题
trans scan ./src

# 使用API翻译生成建议
trans scan ./src --translate

📖 详细使用

命名翻译 (name)

将中文翻译为标准的编程命名:

# 基础用法
trans name "获取用户数据"          # getUserData
trans name "页面组件"              # pageComponent
trans name "数据库连接"            # databaseConnection

# 指定命名风格
trans name "用户管理系统" --snake   # user_management_system
trans name "首页组件" --pascal      # HomePageComponent
trans name "菜单项" --kebab         # menu-item

# 批量翻译
trans names
# 进入交互式批量翻译模式

# 显示详细信息
trans name "用户信息" --verbose
# 显示翻译过程和使用建议

代码扫描 (scan)

扫描代码文件,发现命名问题:

# 扫描单个目录
trans scan ./src

# 扫描并提供翻译建议
trans scan ./src --translate

# 提供修复建议
trans scan ./src --fix

# 详细分析
trans scan ./src --verbose

# 指定建议的命名风格
trans scan ./src --style snake

扫描会发现的问题:

  • 中文变量名/函数名
  • 拼音命名
  • 不规范的命名格式
  • 命名风格不一致

注释翻译 (comment)

翻译代码文件中的注释:

# 中文→英文注释翻译
trans comment file.js

# 英文→中文注释翻译
trans comment file.js --zh

# 直接替换原注释(而不是追加)
trans comment file.js --replace

# 仅检查,不修改文件
trans comment file.js --check

# 批量翻译注释
trans comments "src/**/*.js"

文档翻译 (doc)

翻译 Markdown 文档:

# 翻译README文档
trans doc README.md                    # 生成 README.en.md

# 英文→中文翻译
trans doc README.md --zh               # 生成 README.zh.md

# 指定输出文件
trans doc README.md --output README-EN.md

# 递归翻译目录
trans doc docs/ --recursive

# 保留代码块不翻译
trans doc README.md --preserve-code

配置管理 (config)

# 进入配置菜单
trans config

# 配置有道翻译API
trans config youdao

# 查看当前配置
trans config show

# 重置配置
trans config reset

# 测试翻译配置
trans config test

⚙️ 配置选项

有道翻译 API 配置

trans config youdao

需要提供:

  • APP ID: 应用 ID
  • APP Secret: 应用密钥

命名风格偏好

支持的命名风格:

  • camel: 驼峰命名 (userInfo) - 默认
  • snake: 下划线命名 (user_info)
  • pascal: 帕斯卡命名 (UserInfo)
  • kebab: 短横线命名 (user-info)

配置文件位置

配置文件存储在:

  • Linux/macOS: ~/.config/trans-kit/config.json
  • Windows: %APPDATA%/trans-kit/config.json

🛠️ 高级用法

命令组合

# 扫描 → 翻译 → 修复工作流
trans scan ./src --translate --fix

# 批量处理注释
find . -name "*.js" -exec trans comment {} \;

# 项目国际化准备
trans scan ./src --translate > naming-issues.txt
trans comments "src/**/*.js" --check > comment-issues.txt

自定义脚本

package.json 中添加脚本:

{
  "scripts": {
    "trans:scan": "trans scan ./src --translate",
    "trans:comments": "trans comments 'src/**/*.js' --check",
    "trans:docs": "trans doc README.md && trans doc docs/ --recursive"
  }
}

🔧 开发者指南

项目结构

trans-kit/
├── src/
│   ├── commands/          # 命令处理器
│   │   ├── name.js       # 命名翻译
│   │   ├── scan.js       # 代码扫描
│   │   ├── comment.js    # 注释翻译
│   │   ├── doc.js        # 文档翻译
│   │   ├── config.js     # 配置管理
│   │   └── help.js       # 帮助信息
│   ├── services/          # 服务层
│   │   └── translator.js # 翻译服务
│   ├── utils/            # 工具函数
│   │   └── gradient.js   # 渐变色效果
│   ├── cli.js            # CLI解析器
│   └── index.js          # 主入口
├── config/               # 配置文件
├── test/                 # 测试文件
└── package.json

本地开发

# 克隆项目
git clone https://github.com/your-username/trans-kit.git
cd trans-kit

# 安装依赖
npm install

# 开发模式运行
npm run dev

# 运行测试
npm test

# 构建
npm run build

贡献代码

  1. Fork 项目
  2. 创建特性分支 (git checkout -b feature/new-feature)
  3. 提交更改 (git commit -am 'Add new feature')
  4. 推送到分支 (git push origin feature/new-feature)
  5. 创建 Pull Request

🐛 问题排查

常见问题

Q: 提示"配置错误"怎么办? A: 运行 trans config youdao 重新配置 API 密钥

Q: 翻译结果不准确? A: 有道翻译 API 有时会有限制,可以尝试:

  • 检查网络连接
  • 确认 API 密钥有效
  • 使用 trans config test 测试连接

Q: 终端显示乱码? A: 确保终端支持 UTF-8 编码:

export LANG=en_US.UTF-8

Q: 颜色显示异常? A: 使用 --no-color 选项禁用颜色:

trans name "测试" --no-color

调试模式

# 显示详细调试信息
DEBUG=trans-kit trans name "测试"

# 显示详细执行日志
trans name "测试" --verbose

📊 性能优化

  • ✅ API 请求缓存
  • ✅ 批量翻译优化
  • ✅ 文件扫描增量处理
  • ✅ 配置文件懒加载

🔮 未来计划

  • [ ] 支持更多翻译服务(Google Translate、百度翻译)
  • [ ] VSCode 扩展插件
  • [ ] 代码自动修复功能
  • [ ] 团队协作配置同步
  • [ ] 翻译质量评分
  • [ ] 自定义翻译词典

📄 许可证

MIT License