Skip to content

Commit

Permalink
✨ feat: I18n support specify the configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Nov 22, 2023
1 parent 0dc7094 commit f1d87c2
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 98 deletions.
8 changes: 4 additions & 4 deletions packages/lobe-commit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ To install Lobe Commit, run the following command:
npm install -g @lobehub/commit-cli
```

> \[!NOTE]\
> Make sure your node version >= 18
> \[!IMPORTANT]\
> Please make sure you have `Node.js` version **>= 18**
<div align="right">

Expand Down Expand Up @@ -153,7 +153,7 @@ $ lobe-commit --remove # or use short flag -r
To configure Lobe Commit, run the following command:

```shell
$ lobe-commit --config # or use short flag -o
$ lobe-commit --option # or use short flag -o
```

- To use AI auto-generation, you need to fill in your [OpenAI token](<(https://platform.openai.com/account/api-keys)>) in the settings.
Expand All @@ -171,7 +171,7 @@ Lobe Commit supports the following options:

```shell
--commit -c Interactively commit using the prompts
--config -o Setup lobe-commit preferences
--option -o Setup lobe-commit preferences
--help -h Print basic options
--init -i Initialize lobe-commit as a commit hook
--remove -r Remove a previously initialized commit hook
Expand Down
8 changes: 4 additions & 4 deletions packages/lobe-commit/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ Lobe Commit 是一款使用 ChatGPT 生成基于 Gitmoji 的 CLI 提交工具
npm install -g @lobehub/commit-cli
```

> \[!NOTE]\
> 请确保 Node.js 版本 >= 18
> \[!IMPORTANT]\
> 请确保环境中 `Node.js` 版本 **>= 18**
<div align="right">

Expand Down Expand Up @@ -153,7 +153,7 @@ $ lobe-commit --remove # 或使用短标志 -r
要配置 Lobe Commit,请运行以下命令:

```shell
$ lobe-commit --config # 或使用短标志 -o
$ lobe-commit --option # 或使用短标志 -o
```

- 要使用 AI 自动生成,需要在设置中填写 [OpenAI 令牌](https://platform.openai.com/account/api-keys)
Expand All @@ -171,7 +171,7 @@ Lobe Commit 支持以下选项:

```shell
--commit -c 使用提示交互式提交
--config -o 设置lobe-commit首选项
--option -o 设置lobe-commit首选项
--help -h 打印基本选项
--init -i 将lobe-commit初始化为提交钩子
--remove -r 删除先前初始化的提交钩子
Expand Down
6 changes: 3 additions & 3 deletions packages/lobe-commit/src/cli.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ program
.version(packageJson.version)
.addOption(new Option('--hook', 'Interactively commit using the prompts'))
.addOption(new Option('-a, --ai', 'Generate prompts by ChatGPT'))
.addOption(new Option('-o, --config', 'Setup lobe-commit preferences'))
.addOption(new Option('-o, --option', 'Setup lobe-commit preferences'))
.addOption(new Option('-i, --init', 'Initialize lobe-commit as a commit hook'))
.addOption(new Option('-r, --remove', 'Remove a previously initialized commit hook'))
.addOption(new Option('-l, --list', 'List all commit types supported'))
.parse();

interface Flags {
ai?: boolean;
config?: boolean;
hook?: boolean;
init?: boolean;
list?: boolean;
option?: boolean;
remove?: boolean;
}

const options: Flags = program.opts();

if (options.ai) {
render(<Ai />);
} else if (options.config) {
} else if (options.option) {
render(<Config />);
} else if (options.init) {
render(<HookCreate />);
Expand Down
2 changes: 1 addition & 1 deletion packages/lobe-i18n/.i18nrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
jsonMode: true,
},
markdown: {
entry: ['./README.zh-CN.md'],
entry: ['./examples'],
entryLocale: 'zh-CN',
entryExtension: '.zh-CN.md',
outputLocales: ['en-US'],
Expand Down
64 changes: 34 additions & 30 deletions packages/lobe-i18n/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ To install Lobe i18n, run the following command:
npm install -g @lobehub/i18n-cli
```

> \[!NOTE]\
> Please make sure you have _Node.js_ version _>= 18_.
> \[!IMPORTANT]\
> Please make sure you have `Node.js` version **>= 18**.
<div align="right">

Expand All @@ -90,20 +90,24 @@ npm install -g @lobehub/i18n-cli
To initialize the Lobe i18n configuration, run the following command:

```shell
$ lobe-i18n --config # or use the short flag -o
$ lobe-i18n -o # or use the full flag --option
```

> \[!IMPORTANT]\
> To use AI auto-generation, you need to fill in the [OpenAI Token](https://platform.openai.com/account/api-keys) in the settings.
```shell
# Translate Locale files
$ lobe-i18n
## or
$ lobe-i18n locale
$ lobe-i18n # or $ lobe-i18n locale

# Translate Markdown files
$ lobe-i18n md

# Run i18n translation and markdown translation simultaneously
$ lobe-i18n --with-md

# Specify the configuration file
$ lobe-i18n -c './custom-config.js' # or use the full flag --config
```

<br/>
Expand Down Expand Up @@ -142,23 +146,23 @@ This project provides some additional configuration items set with environment v

| Property Name | Required | Type | Default Value | Description |
| ------------- | -------- | -------------- | --------------- | ---------------------------------------------------------------------------- |
| entry | Yes | `string` | - | Entry file or folder |
| entryLocale | Yes | `string` | - | Language to use as translation reference |
| modelName | No | `string` | `gpt-3.5-turbo` | Model to use |
| output | Yes | `string` | - | Location to store localized files |
| outputLocales | Yes | `string[] ` | - | All the languages to be translated |
| reference | No | `string` | - | Provide some context for more accurate translations |
| splitToken | No | `number` | - | Split the localized JSON file by tokens, automatically calculated by default |
| temperature | No | `number` | `0` | Sampling temperature to use |
| concurrency | No | `number` | `5` | Number of concurrently pending promises returned |
| experimental | No | `experimental` | | Experimental features, see below |
| markdown | No | `markdown` | | See `markdown` configuration below |
| entry | `*` | `string` | - | Entry file or folder |
| entryLocale | `*` | `string` | - | Language to use as translation reference |
| modelName | | `string` | `gpt-3.5-turbo` | Model to use |
| output | `*` | `string` | - | Location to store localized files |
| outputLocales | `*` | `string[] ` | `[]` | All the languages to be translated |
| reference | | `string` | - | Provide some context for more accurate translations |
| splitToken | | `number` | - | Split the localized JSON file by tokens, automatically calculated by default |
| temperature | | `number` | `0` | Sampling temperature to use |
| concurrency | | `number` | `5` | Number of concurrently pending promises returned |
| experimental | | `experimental` | `{}` | Experimental features, see below |
| markdown | | `markdown` | `{}` | See `markdown` configuration below |

#### `experimental`

| Property Name | Required | Type | Default Value | Description |
| ------------- | -------- | ------- | ------------- | --------------------------------------------------------------------------------------------- |
| jsonMode | No | boolean | false | Enable gpt force JSON output for stability (only supported by new models after November 2023) |
| Property Name | Required | Type | Default Value | Description |
| ------------- | -------- | --------- | ------------- | --------------------------------------------------------------------------------------------- |
| jsonMode | | `boolean` | `false` | Enable gpt force JSON output for stability (only supported by new models after November 2023) |

<br/>

Expand Down Expand Up @@ -287,16 +291,16 @@ $ lobe-i18n

## 📝 Markdown Configuration

| Property Name | Required | Type | Default | Description |
| ---------------- | -------- | ------------------------- | ---------------------------- | ----------------------------------------------------------------------- |
| entry | Yes | `string[]` | - | Entry file or folder, supports `glob` |
| entryLocale | No | `string` | Parent locale | Reference language for translation |
| entryExtension | No | `string` | `.md` | Entry file extension |
| exclude | No | `string[]` | - | Files to be filtered, supports `glob` |
| outputLocales | No | `string[]` | Parent locale | All languages to be translated |
| outputExtensions | No | `function` | `(locale) => '.{locale}.md'` | Output file extension generation |
| mode | No | `string``mdast``function` | `string` | Translation mode selection, explained below |
| translateCode | No | `boolean` | `false` | Whether to translate code blocks under `mdast`, other modes are invalid |
| Property Name | Required | Type | Default | Description |
| ---------------- | -------- | --------------------------- | ---------------------------- | ----------------------------------------------------------------------- |
| entry | `*` | `string[]` | `[]` | Entry file or folder, supports `glob` |
| entryLocale | | `string` | _Inherit parent locale_ | Reference language for translation |
| entryExtension | | `string` | `.md` | Entry file extension |
| exclude | | `string[]` | `[]` | Files to be filtered, supports `glob` |
| outputLocales | | `string[]` | _Inherit parent locale_ | All languages to be translated |
| outputExtensions | | `function` | `(locale) => '.{locale}.md'` | Output file extension generation |
| mode | | `string`,`mdast`,`function` | `string` | Translation mode selection, explained below |
| translateCode | | `boolean` | `false` | Whether to translate code blocks under `mdast`, other modes are invalid |

#### `outputExtensions`

Expand Down
56 changes: 31 additions & 25 deletions packages/lobe-i18n/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ Lobe i18n 是一款使用 ChatGPT 自动化 i18n 的 CLI 流程工具
npm install -g @lobehub/i18n-cli
```

> \[!NOTE]\
> 请确保 \* _Node.js_ _版本_ _>= 18_
> \[!IMPORTANT]\
> 请确保环境中 `Node.js` 版本 **>= 18**
<div align="right">

Expand All @@ -90,7 +90,7 @@ npm install -g @lobehub/i18n-cli
要初始化配置 Lobe i8n,请运行以下命令:

```shell
$ lobe-i18n --config # 或使用短标志 -o
$ lobe-i18n -o # 或使用完整标志 --option
```

> \[!IMPORTANT]\
Expand All @@ -104,6 +104,12 @@ $ lobe-i18n locale

# 翻译 Markdown 文件
$ lobe-i18n md

# 同时运行 i18n 翻译和 markdown 翻译
$ lobe-i18n --with-md

# 指定配置文件
$ lobe-i18n -c './custom-config.js' # or use the full flag --config
```

<br/>
Expand Down Expand Up @@ -141,23 +147,23 @@ $ lobe-i18n md

| 属性名称 | 必填 | 类型 | 默认值 | 描述 |
| ------------- | ---- | -------------- | --------------- | ---------------------------------------- |
| entry | | `string` | - | 入口文件或文件夹 |
| entryLocale | | `string` | - | 作为翻译参考的语言 |
| modelName | | `string` | `gpt-3.5-turbo` | 使用的模型 |
| output | | `string` | - | 存储本地化文件的位置 |
| outputLocales | | `string[] ` | - | 需要进行翻译的所有语言 |
| reference | | `string` | - | 提供一些上下文以获得更准确的翻译 |
| splitToken | | `number` | - | 按令牌分割本地化 JSON 文件,默认自动计算 |
| temperature | | `number` | `0` | 使用的采样温度 |
| concurrency | | `number` | `5` | 同时并发的队列请求数量 |
| experimental | | `experimental` | | 实验性功能,见下文 |
| markdown | | `markdown` | |`markdown` 配置说明 |
| entry | `*` | `string` | - | 入口文件或文件夹 |
| entryLocale | `*` | `string` | - | 作为翻译参考的语言 |
| modelName | | `string` | `gpt-3.5-turbo` | 使用的模型 |
| output | `*` | `string` | - | 存储本地化文件的位置 |
| outputLocales | `*` | `string[] ` | `[]` | 需要进行翻译的所有语言 |
| reference | | `string` | - | 提供一些上下文以获得更准确的翻译 |
| splitToken | | `number` | - | 按令牌分割本地化 JSON 文件,默认自动计算 |
| temperature | | `number` | `0` | 使用的采样温度 |
| concurrency | | `number` | `5` | 同时并发的队列请求数量 |
| experimental | | `experimental` | `{}` | 实验性功能,见下文 |
| markdown | | `markdown` | `{}` |`markdown` 配置说明 |

#### `experimental`

| 属性名称 | 必填 | 类型 | 默认值 | 描述 |
| -------- | ---- | ------- | ------ | -------------------------------------------------------------- |
| jsonMode | | boolean | false | 开启 gpt 强制 json 输出提升稳定性 (只支持 23 年 11 月后新模型) |
| 属性名称 | 必填 | 类型 | 默认值 | 描述 |
| -------- | ---- | --------- | ------- | -------------------------------------------------------------- |
| jsonMode | | `boolean` | `false` | 开启 gpt 强制 json 输出提升稳定性 (只支持 23 年 11 月后新模型) |

<br/>

Expand Down Expand Up @@ -288,14 +294,14 @@ $ lobe-i18n

| 属性名称 | 必填 | 类型 | 默认值 | 描述 |
| ---------------- | ---- | --------------------------- | ---------------------------- | ----------------------------------------- |
| entry | | `string[]` | - | 入口文件或文件夹,支持 `glob` |
| entryLocale | | `string` | 同父级 | 作为翻译参考的语言 |
| entryExtension | | `string` | `.md` | 入口文件扩展名 |
| exclude | | `string[]` | - | 需要过滤的文件,支持 `glob` |
| outputLocales | | `string[]` | 同父级 | 需要进行翻译的所有语言 |
| outputExtensions | | `function` | `(locale) => '.{locale}.md'` | 输出文件的扩展名生成 |
| mode | | `string`,`mdast`,`function` | `string` | 翻译的模式选择,解释见下文 |
| translateCode | | `boolean` | `false` |`mdast` 下是否翻译代码块,其他模式无效 |
| entry | `*` | `string[]` | `[]` | 入口文件或文件夹,支持 `glob` |
| entryLocale | | `string` | _继承同父级_ | 作为翻译参考的语言 |
| entryExtension | | `string` | `.md` | 入口文件扩展名 |
| exclude | | `string[]` | `[]` | 需要过滤的文件,支持 `glob` |
| outputLocales | | `string[]` | _继承同父级_ | 需要进行翻译的所有语言 |
| outputExtensions | | `function` | `(locale) => '.{locale}.md'` | 输出文件的扩展名生成 |
| mode | | `string`,`mdast`,`function` | `string` | 翻译的模式选择,解释见下文 |
| translateCode | | `boolean` | `false` |`mdast` 下是否翻译代码块,其他模式无效 |

#### `outputExtensions`

Expand Down
1 change: 0 additions & 1 deletion packages/lobe-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"ink": "^4.2",
"langchain": "latest",
"lodash-es": "^4",
"multimatch": "^7",
"p-map": "^6",
"pangu": "^4",
"react": "^18",
Expand Down
Loading

0 comments on commit f1d87c2

Please sign in to comment.