Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: 更新项目版本至 1.0.8 #8

Merged
merged 4 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 78 additions & 55 deletions README-zh.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
以下是 `ai-markdown-translator` 文档的修订和整合版本,结合了 `npx``./ai-markdown-translator` 的示例:
这是合并后的`ai-markdown-translator`文档的修订版本,包括了`npx``./ai-markdown-translator`的示例:

---

# ai-markdown-translator

<div>
<a href="https://www.npmjs.org/package/ai-markdown-translator"><img src="https://img.shields.io/npm/v/ai-markdown-translator.svg?style=flat" alt="NPM version"></a>
<a href="https://github.com/h7ml/ai-markdown-translator/actions/workflows/ci.yml"><img src="https://github.com/h7ml/ai-markdown-translator/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
<a href="https://github.com/h7ml/ai-markdown-translator/actions/workflows/release.yml"><img src="https://github.com/h7ml/ai-markdown-translator/actions/workflows/release.yml/badge.svg" alt="Release"></a>
<a href="https://www.npmjs.org/package/ai-markdown-translator"><img src="https://img.shields.io/npm/dw/ai-markdown-translator" alt="NPM Downloads"></a>
<a href="https://www.npmjs.org/package/ai-markdown-translator"><img src="https://img.shields.io/npm/l/ai-markdown-translator" alt="NPM License"></a>
<a href="https://www.npmjs.org/package/ai-markdown-translator"><img src="https://img.shields.io/npm/v/ai-markdown-translator.svg?style=flat" alt="NPM版"></a>
<a href="https://github.com/h7ml/ai-markdown-translator/actions/workflows/ci.yml"><img src="https://github.com/h7ml/ai-markdown-translator/actions/workflows/ci.yml/badge.svg" alt="持续集成"></a>
<a href="https://github.com/h7ml/ai-markdown-translator/actions/workflows/release.yml"><img src="https://github.com/h7ml/ai-markdown-translator/actions/workflows/release.yml/badge.svg" alt="发布"></a>
<a href="https://www.npmjs.org/package/ai-markdown-translator"><img src="https://img.shields.io/npm/dw/ai-markdown-translator" alt="NPM下载量"></a>
<a href="https://www.npmjs.org/package/ai-markdown-translator"><img src="https://img.shields.io/npm/l/ai-markdown-translator" alt="NPM许可证"></a>
<a href="https://github.com/h7ml/ai-markdown-translator/stargazers"><img src="https://img.shields.io/github/stars/h7ml/ai-markdown-translator.svg" alt="GitHub Stars"></a>
<a href="https://github.com/h7ml/ai-markdown-translator/issues"><img src="https://img.shields.io/github/issues/h7ml/ai-markdown-translator.svg" alt="GitHub Issues"></a>
<a href="https://github.com/h7ml/ai-markdown-translator/issues"><img src="https://img.shields.io/github/issues/h7ml/ai-markdown-translator.svg" alt="GitHub问题"></a>
<a href="https://github.com/h7ml/ai-markdown-translator/network/members"><img src="https://img.shields.io/github/forks/h7ml/ai-markdown-translator.svg" alt="GitHub Forks"></a>
<a href="https://github.com/h7ml/ai-markdown-translator/graphs/contributors"><img src="https://img.shields.io/github/contributors/h7ml/ai-markdown-translator.svg" alt="GitHub Contributors"></a>
<a href="https://github.com/h7ml/ai-markdown-translator/graphs/contributors"><img src="https://img.shields.io/github/contributors/h7ml/ai-markdown-translator.svg" alt="GitHub贡献者"></a>
</div>

[English](README.md) | [中文](README-zh.md)

`ai-markdown-translator` 是一个命令行工具,可以使用 OpenAI 的语言模型将 Markdown 文件从一种语言翻译成另一种语言。它在翻译内容的同时保持 Markdown 语法。
`ai-markdown-translator` 是一个命令行工具,使用 OpenAI 的语言模型将 Markdown 文件从一种语言翻译为另一种语言。它在翻译内容时保留 Markdown 语法。

## 特性

- 将 Markdown 文件翻译成 OpenAI 模型支持的任何语言。
- 在翻译过程中保持 Markdown 语法。
- 通过命令行参数或环境变量灵活配置
- 在翻译过程中保留 Markdown 语法。
- 通过命令行参数或环境变量进行灵活配置

## 先决条件

- Node.js (v14 或更高版本)
- npm (通常与 Node.js 一起提供)
- Node.jsv14 或更高版本
- npm(通常随 Node.js 一起安装)
- OpenAI API 密钥

## 安装

1. 克隆此代码库或下载源代码
1. 克隆此仓库或下载源代码
2. 在终端中导航到项目目录。
3. 安装依赖项:

Expand All @@ -50,20 +50,20 @@ npm run build

## 脚本

- `build`将 TypeScript 文件编译为 JavaScript。
- `start`使用 Node.js 运行编译生成的 JavaScript。
- `lint`运行 ESLint 检查 TypeScript 文件中的代码质量问题。
- `lint:fix`自动修复 TypeScript 文件中的 lint 问题。
- `format`使用 Prettier 格式化 `src` 目录中的各种文件类型的代码
- `format:check`:检查代码格式而不做更改,适用于 `src` 目录中的各种文件类型
- `postbuild`使编译后的 `index.js` 文件可执行。
- `changelog`:根据传统提交生成变更日志
- `version`:在进行版本控制时更新变更日志并为提交暂存
- `test`构建项目并运行测试。
- `build`: 将 TypeScript 文件编译为 JavaScript。
- `start`: 使用 Node.js 运行编译后的 JavaScript。
- `lint`: 运行 ESLint 检查 TypeScript 文件中的代码质量问题。
- `lint:fix`: 自动修复 TypeScript 文件中的 lint 问题。
- `format`: 使用 Prettier `src` 目录中的各种文件类型格式化代码
- `format:check`: 不做任何更改地检查 `src` 目录中各种文件类型的代码格式
- `postbuild`: 使编译后的 `index.js` 文件可执行。
- `changelog`: 根据常规提交生成变更日志
- `version`: 在版本更新时更新变更日志并将其暂存以供提交
- `test`: 构建项目并运行测试。

## 使用
## 用法

您可以使用 Node.js、`npx` 或作为独立可执行文件(如果您已将其打包)运行 CLI 工具。
您可以使用 Node.js、`npx` 或作为独立可执行文件(如果您已将其打包)来运行 CLI 工具。

### 使用 Node.js

Expand All @@ -80,7 +80,7 @@ npx ai-markdown-translator -i <input-file> -o <output-file> -l <target-language>
例如:

```bash
npx ai-markdown-translator -u https://gitee.com/h7ml/ai-markdown-translator/raw/main/README.md -o output.md -l "Italian"
npx ai-markdown-translator -u https://gitee.com/h7ml/ai-markdown-translator/raw/main/README.md -o output.md -l "意大利语"
```

### 使用独立可执行文件
Expand All @@ -91,52 +91,75 @@ npx ai-markdown-translator -u https://gitee.com/h7ml/ai-markdown-translator/raw/

## 选项

- `--input`, `-i`:输入的 Markdown 文件(替代 `--url`)。
- `--url`, `-u`:要翻译的 Markdown 文件的 URL(替代 `--input`)。
- `--output`, `-o`:输出的 Markdown 文件(如果未提供,默认为输入文件名)。
- `--language`, `-l`:翻译的目标语言(必需)。
- `--openai-url`:OpenAI API 的 URL(默认:使用 `OPENAI_URL` 环境变量)。
- `--api-key`:OpenAI API 密钥(默认:使用 `API_KEY` 环境变量)。
- `--model`:要使用的 OpenAI 模型(默认:使用 `MODEL` 环境变量或 `gpt-3.5-turbo`)。
- `--help`, `-h`:显示帮助信息。
- `--show-version`, `-v`:显示版本。
- `--input`, `-i`: 输入 Markdown 文件或目录(与 `--url` 替代)。此选项允许您指定要翻译的 Markdown 文件或目录的路径。
- `--url`, `-u`: 要翻译的 Markdown 文件的 URL(与 `--input` 替代)。使用此选项提供希望翻译的 Markdown 文件的直接链接。

> 注意:`--input` 和 `--url` 是互斥的;您必须提供其中一个。
- `--extension`, `-e`: 指定要翻译的文件扩展名(例如,`md`)。如果未提供,将处理所有文件。此选项允许您根据文件扩展名筛选要翻译的文件。

- `--rename`: 是否修改文件名。如果为真,输出文件将命名为 `<original-filename>-translated.<extension>`。此选项允许您指定是否希望在翻译后的文件名后附加后缀。

- `--output`, `-o`: 输出 Markdown 文件(如果未提供,则默认为输入文件名)。此选项允许您指定保存翻译内容的输出文件名。

- `--language`, `-l`: 目标语言(必需)。此选项指定希望将 Markdown 内容翻译成的语言。

- `--openai-url`: OpenAI API URL(默认值:使用 `OPENAI_URL` 环境变量)。此选项允许您在需要时指定 OpenAI API 的自定义 URL。

- `--api-key`: OpenAI API 密钥(默认值:使用 `API_KEY` 环境变量)。此选项用于提供您的 OpenAI API 密钥以进行身份验证。

- `--model`: 要使用的 OpenAI 模型(默认值:使用 `MODEL` 环境变量或 `gpt-3.5-turbo`)。此选项允许您指定要用于翻译的 OpenAI 模型。

- `--help`, `-h`: 显示帮助。此选项显示命令行工具的帮助信息。

- `--show-version`, `-v`: 显示版本。此选项显示该工具的当前版本。

> 注意:`--input` 和 `--url` 是互斥的;您必须提供其中之一。

## 环境变量

您可以设置以下环境变量,而不是作为命令行参数传递它们:

- `OPENAI_URL`OpenAI API 的 URL。
- `API_KEY`您的 OpenAI API 密钥。
- `MODEL`要使用的 OpenAI 模型(例如,`'gpt-3.5-turbo'`)。
- `OPENAI_URL`: OpenAI API 的 URL。
- `API_KEY`: 您的 OpenAI API 密钥。
- `MODEL`: 要使用的 OpenAI 模型(例如,`'gpt-3.5-turbo'`)。

您可以将这些设置在项目根目录的 `.env` 文件中,或在您的 shell 中导出它们。
您可以在项目根目录中的 `.env` 文件中设置这些变量或在您的 shell 中导出它们。

## 示例

1. **将 Markdown 文件从英语翻译成西班牙语:**

```bash
npx ai-markdown-translator -i english.md -o spanish.md -l "Spanish"
npx ai-markdown-translator -i english.md -o spanish.md -l "西班牙语"
```

2. **使用特定的 OpenAI 模型进行翻译:**

```bash
npx ai-markdown-translator -i input.md -o output.md -l "French" --model "gpt-4"
npx ai-markdown-translator -i input.md -o output.md -l "法语" --model "gpt-4"
```

3. **使用自定义 OpenAI URL 和 API 密钥进行翻译:**

```bash
npx ai-markdown-translator -i input.md -o output.md -l "German" --openai-url "https://api.302.ai/v1/chat/completions" --api-key "sk-302-api-key"
npx ai-markdown-translator -i input.md -o output.md -l "德语" --openai-url "https://api.302.ai/v1/chat/completions" --api-key "sk-302-api-key"
```

4. **翻译 URL 的 Markdown 内容:**

```bash
npx ai-markdown-translator -u https://gitee.com/h7ml/ai-markdown-translator/raw/main/README.md -o output.md -l "Italian"
npx ai-markdown-translator -u https://gitee.com/h7ml/ai-markdown-translator/raw/main/README.md -o output.md -l "意大利语"
```

5. **翻译目录中的所有 Markdown 文件并重命名:**

```bash
npx ai-markdown-translator -i ./markdown-files -l "中文" --rename
```

6. **翻译 Markdown 文件并指定输出文件名:**

```bash
npx ai-markdown-translator -i example.md -o translated_example.md -l "日语"
```

## 许可证
Expand All @@ -145,31 +168,31 @@ npx ai-markdown-translator -u https://gitee.com/h7ml/ai-markdown-translator/raw/

## Git 信息

- **代码库**:[h7ml/ai-markdown-translator](https://github.com/h7ml/ai-markdown-translator)
- **问题**[报告问题](https://github.com/h7ml/ai-markdown-translator/issues)
- **仓库**: [h7ml/ai-markdown-translator](https://github.com/h7ml/ai-markdown-translator)
- **问题**: [报告问题](https://github.com/h7ml/ai-markdown-translator/issues)

## 版本信息

- **当前版本**1.0.7
- **NPM 包**[ai-markdown-translator](https://www.npmjs.com/package/ai-markdown-translator)
- **当前版本**: 1.0.8
- **NPM 包**: [ai-markdown-translator](https://www.npmjs.com/package/ai-markdown-translator)

## CI 信息

该项目使用 GitHub Actions 进行持续集成。CI 工作流包括
该项目使用 GitHub Actions 进行持续集成。CI 工作流程包括

- 使用 ESLint 检查代码
- 运行测试(如果适用
- 使用 ESLint 对代码进行 lint
- 运行测试(如适用
- 构建项目
- 缓存依赖项以加快构建速度

## 贡献

欢迎贡献!请随时提交请求合并
欢迎贡献!请随时提交 Pull Request

## 支持

如果您遇到任何问题或有任何疑问,请在此代码库中打开一个问题
如果您遇到任何问题或有任何疑问,请在此仓库中打开一个问题

---

这个版本将 `npx` 和独立可执行文件 (`./ai-markdown-translator`) 的使用示例结合成一个统一的部分。如果您希望进行进一步的调整,请告诉我!
此版本将`npx`和独立可执行文件(`./ai-markdown-translator`)的使用示例合并为一个统一的部分。如果您需要进一步调整,请告诉我!
43 changes: 33 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,26 @@ npx ai-markdown-translator -u https://gitee.com/h7ml/ai-markdown-translator/raw/

## Options

- `--input`, `-i`: Input Markdown file (alternative to `--url`).
- `--url`, `-u`: URL of a Markdown file to translate (alternative to `--input`).
- `--output`, `-o`: Output Markdown file (if not provided, defaults to the input file name).
- `--language`, `-l`: Target language for translation (required).
- `--openai-url`: OpenAI API URL (default: uses `OPENAI_URL` environment variable).
- `--api-key`: OpenAI API Key (default: uses `API_KEY` environment variable).
- `--model`: OpenAI Model to use (default: uses `MODEL` environment variable or `gpt-3.5-turbo`).
- `--help`, `-h`: Show help.
- `--show-version`, `-v`: Show version.
- `--input`, `-i`: Input Markdown file or directory (alternative to `--url`). This option allows you to specify the path to the Markdown file or directory you want to translate.
- `--url`, `-u`: URL of a Markdown file to translate (alternative to `--input`). Use this option to provide a direct link to a Markdown file that you want to translate.

- `--extension`, `-e`: Specify the file extension to translate (e.g., `md`). If not provided, all files will be processed. This option allows you to filter which files to translate based on their extension.

- `--rename`: Whether to modify the file name. If true, the output file will be named `<original-filename>-translated.<extension>`. This option allows you to specify if you want to append a suffix to the translated file name.

- `--output`, `-o`: Output Markdown file (if not provided, defaults to the input file name). This option allows you to specify the name of the output file where the translated content will be saved.

- `--language`, `-l`: Target language for translation (required). This option specifies the language into which you want the Markdown content to be translated.

- `--openai-url`: OpenAI API URL (default: uses `OPENAI_URL` environment variable). This option allows you to specify a custom URL for the OpenAI API if needed.

- `--api-key`: OpenAI API Key (default: uses `API_KEY` environment variable). This option is used to provide your OpenAI API key for authentication.

- `--model`: OpenAI Model to use (default: uses `MODEL` environment variable or `gpt-3.5-turbo`). This option allows you to specify which OpenAI model to use for translation.

- `--help`, `-h`: Show help. This option displays the help information for the command-line tool.

- `--show-version`, `-v`: Show version. This option displays the current version of the tool.

> Note: `--input` and `--url` are mutually exclusive; you must provide one or the other.

Expand Down Expand Up @@ -139,6 +150,18 @@ npx ai-markdown-translator -i input.md -o output.md -l "German" --openai-url "ht
npx ai-markdown-translator -u https://gitee.com/h7ml/ai-markdown-translator/raw/main/README.md -o output.md -l "Italian"
```

5. **Translate all Markdown files in a directory and rename them:**

```bash
npx ai-markdown-translator -i ./markdown-files -l "Chinese" --rename
```

6. **Translate a Markdown file and specify the output file name:**

```bash
npx ai-markdown-translator -i example.md -o translated_example.md -l "Japanese"
```

## License

[MIT License](LICENSE)
Expand All @@ -150,7 +173,7 @@ npx ai-markdown-translator -u https://gitee.com/h7ml/ai-markdown-translator/raw/

## Version Information

- **Current Version**: 1.0.7
- **Current Version**: 1.0.8
- **NPM Package**: [ai-markdown-translator](https://www.npmjs.com/package/ai-markdown-translator)

## CI Information
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ai-markdown-translator",
"version": "1.0.7",
"version": "1.0.8",
"description": "CLI tool to translate Markdown files using OpenAI's language models while preserving the original formatting.",
"main": "dist/index.js",
"type": "module",
Expand Down Expand Up @@ -28,8 +28,10 @@
"CHANGELOG.md"
],
"dependencies": {
"@types/glob": "^8.1.0",
"axios": "^1.4.0",
"dotenv": "^16.0.3",
"glob": "^11.0.0",
"yargs": "^17.7.2"
},
"devDependencies": {
Expand Down
Loading
Loading