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 🙏

© 2025 – Pkg Stats / Ryan Hefner

aitrans

v1.1.2

Published

AI-powered command line translation tool

Readme

AITrans - AI 驱动的命令行翻译工具

Version License Node

一个基于 AI 大模型的命令行翻译工具,支持多种输入方式和多语言翻译。

🏠 项目主页 | 📖 文档 | 🐛 问题反馈

安装

从 npm 安装(推荐)

npm install -g aitrans

从源码安装

git clone https://github.com/fengyucn/aitrans.git
cd aitrans
npm install
npm link

快速开始

🚀 一键配置(推荐)

首次使用或需要重新配置时,运行:

aitrans --setup

这将显示详细的配置指南,包括 API 密钥获取方法和配置步骤。

配置

🔧 环境配置

AITrans 需要配置 OpenAI API 密钥才能正常工作。支持两种配置方式:

方式一:运行配置向导(推荐)

aitrans --setup

按照提示完成配置即可。

方式二:手动配置

全局安装用户

# 创建配置目录
mkdir -p ~/.aitrans

# 创建配置文件
cat > ~/.aitrans/.env << EOF
# 必需配置
AI_API_KEY=sk-your-openai-api-key-here

# 可选配置
AI_MODEL=gpt-3.5-turbo
AI_TEMPERATURE=0.3
AI_API_ENDPOINT=https://api.openai.com/v1/chat/completions
# AI_API_PROXY=http://your-proxy:port  # 如需代理
EOF

本地开发用户

# 复制模板文件
cp .env.example .env

# 编辑配置文件
nano .env

🔑 获取 API 密钥

  1. 访问 OpenAI Platform
  2. 登录或创建账户
  3. 在 API Keys 页面创建新的 API 密钥
  4. 将密钥添加到配置文件中

⚙️ 配置参数说明

| 参数 | 必需 | 默认值 | 说明 | |------|------|--------|------| | AI_API_KEY | ✅ | - | OpenAI API 密钥 | | AI_MODEL | ❌ | gpt-3.5-turbo | 使用的 AI 模型 | | AI_TEMPERATURE | ❌ | 0.3 | 模型温度参数 (0-1) | | AI_API_ENDPOINT | ❌ | OpenAI API | API 端点 | | AI_API_PROXY | ❌ | - | 代理服务器地址 |

✅ 验证配置

# 查看支持的语言列表
aitrans --list-languages

# 测试翻译功能
aitrans "Hello World" --lang zh

使用方法

📝 基本用法

直接翻译

# 直接翻译文本(默认翻译成中文)
aitrans "Hello World"

# 指定目标语言
aitrans -l ja "Hello World"    # 翻译成日语
aitrans --lang fr "Hello World" # 翻译成法语

使用参数

aitrans -t "Hello World"       # 使用 -t 参数
aitrans --text "Hello World"   # 使用 --text 参数

管道输入

echo "Hello World" | aitrans           # 单行文本
cat file.txt | aitrans                  # 文件内容
pbpaste | aitrans                       # 剪贴板内容(macOS)

🛠️ 命令行选项

| 选项 | 简写 | 说明 | 示例 | |------|------|------|------| | --text | -t | 指定要翻译的文本 | aitrans -t "Hello" | | --lang | -l | 目标语言(默认:zh) | aitrans -l en "你好" | | --list-languages | - | 显示支持的语言列表 | aitrans --list-languages | | --setup | - | 显示环境配置指南 | aitrans --setup | | --version | -v | 显示版本信息 | aitrans --version | | --help | -h | 显示帮助信息 | aitrans --help |

🌍 支持的语言

| 代码 | 语言 | 代码 | 语言 | |------|------|------|------| | zh | 中文 | fr | 法语 | | en | 英语 | de | 德语 | | ja | 日语 | es | 西班牙语 | | ko | 韩语 | it | 意大利语 | | ru | 俄语 | pt | 葡萄牙语 | | nl | 荷兰语 | pl | 波兰语 | | ar | 阿拉伯语 | tr | 土耳其语 | | th | 泰语 | vi | 越南语 | | hi | 印地语 | | |

💡 使用技巧

# 翻译命令输出
ls -la | aitrans -l en

# 翻译环境变量
echo $PATH | aitrans -l en

# 组合使用
echo "Bonjour le monde" | aitrans -l zh  # 法语转中文

🔑 常见问题与解决方案

问题 1:错误:未设置 AI_API_KEY 环境变量

原因:API 密钥未配置或配置文件不存在

解决方案

# 方法 1:运行配置向导
aitrans --setup

# 方法 2:手动创建配置文件
mkdir -p ~/.aitrans
cat > ~/.aitrans/.env << EOF
AI_API_KEY=sk-your-actual-openai-api-key-here
AI_MODEL=gpt-3.5-turbo
AI_TEMPERATURE=0.3
EOF

问题 2:API 密钥无效认证失败

解决方案

  1. 检查 API 密钥是否正确(确保以 sk- 开头)
  2. 访问 OpenAI Platform 验证密钥状态
  3. 确认账户有足够的配额

问题 3:网络连接超时

解决方案

  1. 检查网络连接是否正常
  2. 如果在国内网络环境,配置代理:
    echo "AI_API_PROXY=http://your-proxy:port" >> ~/.aitrans/.env
  3. 尝试更换网络环境

问题 4:不支持的语言代码

解决方案

# 查看所有支持的语言
aitrans --list-languages

# 常用语言代码
# zh: 中文, en: 英语, ja: 日语, ko: 韩语
# fr: 法语, de: 德语, es: 西班牙语, ru: 俄语

问题 5:输入文本过长

限制:单次翻译文本最大 4000 字符

解决方案

  • 将长文本分段翻译
  • 考虑使用其他工具处理文档翻译

🔧 诊断工具

# 检查版本
aitrans --version

# 查看配置向导
aitrans --setup

# 查看支持的语言
aitrans --list-languages

# 测试基本功能
aitrans "Hello" --lang zh

📞 获取帮助

如果遇到其他问题:

  1. 查看帮助aitrans --help
  2. 检查配置aitrans --setup
  3. 提交问题GitHub Issues
  4. 查看项目文档项目主页

📄 许可证

ISC License


🙏 致谢

感谢所有为 AITrans 做出贡献的开发者和用户!


⭐ 如果这个项目对你有帮助,请考虑给个 Star!

Made with ❤️ by fengyucn