Skip to content

Commit

Permalink
feat(bin): add support for i18nrc.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelly-wu committed Apr 2, 2024
1 parent f231eac commit 813ac0a
Show file tree
Hide file tree
Showing 22 changed files with 2,701 additions and 3,747 deletions.
12 changes: 12 additions & 0 deletions docs/dist/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ English | [简体中文](https://github.com/i18n-pro/core/blob/v2.1.0/docs/dist/
<details >
<summary>Table of Contents</summary>

&emsp;&emsp;[[2.2.0] - 2024-04-xx](#220---2024-04-xx)<br/>
&emsp;&emsp;&emsp;&emsp;[Command Line Tool](#220-command-line-tool)<br/>
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;[Added](#220-command-line-tool-added)<br/>
&emsp;&emsp;[[2.1.0] - 2023-10-12](#210---2023-10-12)<br/>
&emsp;&emsp;&emsp;&emsp;[Command Line Tool](#210-command-line-tool)<br/>
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;[Added](#210-command-line-tool-added)<br/>
Expand Down Expand Up @@ -68,6 +71,15 @@ English | [简体中文](https://github.com/i18n-pro/core/blob/v2.1.0/docs/dist/

</details>

## [2.2.0] - 2024-04-xx

<h3 id="220-command-line-tool">Command Line Tool</h3>

<h4 id="220-command-line-tool-added">Added</h4>

* 命令行配置文件支持用 `TypeScript` 来编写,从版本 `v2.2.0` 开始,初始化命令执行生成的配置文件默认是 `i18nrc.ts` ,但老版的 `i18nrc.js` 依旧是兼容的


## [2.1.0] - 2023-10-12

<h3 id="210-command-line-tool">Command Line Tool</h3>
Expand Down
12 changes: 12 additions & 0 deletions docs/dist/CHANGELOG_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<details >
<summary>目录</summary>

&emsp;&emsp;[[2.2.0] - 2024-04-xx](#220---2024-04-xx)<br/>
&emsp;&emsp;&emsp;&emsp;[命令行工具](#220-命令行工具)<br/>
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;[Added](#220-命令行工具-added)<br/>
&emsp;&emsp;[[2.1.0] - 2023-10-12](#210---2023-10-12)<br/>
&emsp;&emsp;&emsp;&emsp;[命令行工具](#210-命令行工具)<br/>
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;[Added](#210-命令行工具-added)<br/>
Expand Down Expand Up @@ -68,6 +71,15 @@

</details>

## [2.2.0] - 2024-04-xx

<h3 id="220-命令行工具">命令行工具</h3>

<h4 id="220-命令行工具-added">Added</h4>

* 命令行配置文件支持用 `TypeScript` 来编写,从版本 `v2.2.0` 开始,初始化命令执行生成的配置文件默认是 `i18nrc.ts` ,但老版的 `i18nrc.js` 依旧是兼容的


## [2.1.0] - 2023-10-12

<h3 id="210-命令行工具">命令行工具</h3>
Expand Down
6 changes: 3 additions & 3 deletions docs/dist/COMMAND_LINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<details >
<summary>Table of Contents</summary>

&emsp;&emsp;[1. `i18nrc.js` Configuration](#1--i18nrcjs--configuration)<br/>
&emsp;&emsp;[1. `i18nrc.ts` Configuration](#1--i18nrcts--configuration)<br/>
&emsp;&emsp;&emsp;&emsp;[Basic Configuration](#basic-configuration)<br/>
&emsp;&emsp;&emsp;&emsp;[Output](#output)<br/>
&emsp;&emsp;&emsp;&emsp;[GooglexConfig](#googlexconfig)<br/>
Expand All @@ -21,7 +21,7 @@

</details>

## 1. `i18nrc.js` Configuration
## 1. `i18nrc.ts` Configuration

### Basic Configuration

Expand Down Expand Up @@ -161,4 +161,4 @@ Configuration of Alibaba Cloud Translation
|:-:|:-:|:-:|:-|:-|:-|
|--locale|-L|`en` \| `zh`|ALL|`npx i18n h -L en`<br />`npx i18n h --locale en`|Specify the command line display language<br /><br />The available languages are Chinese (zh)/English (en). The default is English (en)|
|--non-incremental|-|-|`t`<br />`translate`|`npx i18n t --non-incremental`|Turn off incremental translation mode<br /><br />⚠️⚠️⚠️: After turning off incremental translation mode, all texts will be re-translated, which may cause the loss of non-platform translated texts (**Manual translation**). Please use with caution!!!|
|--path|-P|-|`init`<br />`t`<br />`translate`|`npx i18n init -P /xxx/xxx/xxx`<br />`npx i18n t -P /xxx/xxx/xxx`|Specify the configuration file path (parameter is relative path)<br /><br />You only need to specify the path name. The default configuration filename is `i18nrc.js`|
|--path|-P|-|`init`<br />`t`<br />`translate`|`npx i18n init -P /xxx/xxx/xxx`<br />`npx i18n t -P /xxx/xxx/xxx`|Specify the configuration file path (parameter is relative path)<br /><br />You only need to specify the path name. The default configuration filename is `i18nrc.ts`|
6 changes: 3 additions & 3 deletions docs/dist/COMMAND_LINE_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<details >
<summary>目录</summary>

&emsp;&emsp;[1. `i18nrc.js` 配置](#1--i18nrcjs-配置)<br/>
&emsp;&emsp;[1. `i18nrc.ts` 配置](#1--i18nrcts-配置)<br/>
&emsp;&emsp;&emsp;&emsp;[基础配置](#基础配置)<br/>
&emsp;&emsp;&emsp;&emsp;[Output](#output)<br/>
&emsp;&emsp;&emsp;&emsp;[GooglexConfig](#googlexconfig)<br/>
Expand All @@ -21,7 +21,7 @@

</details>

## 1. `i18nrc.js` 配置
## 1. `i18nrc.ts` 配置

### 基础配置

Expand Down Expand Up @@ -161,4 +161,4 @@ OpenAI翻译的配置
|:-:|:-:|:-:|:-|:-|:-|
|--locale|-L|`en` \| `zh`|ALL|`npx i18n h -L en`<br />`npx i18n h --locale en`|指定命令行显示语言<br /><br />可选语言有中文(zh)/ 英文(en), 默认为英文(en)|
|--non-incremental|-|-|`t`<br />`translate`|`npx i18n t --non-incremental`|关闭增量翻译模式<br /><br />⚠️⚠️⚠️:关闭增量翻译模式后,所有的文案会重新翻译,会导致**手工翻译**(非翻译平台翻译的)的文案丢失,需慎重考虑使用!!!|
|--path|-P|-|`init`<br />`t`<br />`translate`|`npx i18n init -P /xxx/xxx/xxx`<br />`npx i18n t -P /xxx/xxx/xxx`|指定配置文件路径(参数为相对路径)<br /><br />只需要指定路径名,配置文件名默认为 `i18nrc.js`|
|--path|-P|-|`init`<br />`t`<br />`translate`|`npx i18n init -P /xxx/xxx/xxx`<br />`npx i18n t -P /xxx/xxx/xxx`|指定配置文件路径(参数为相对路径)<br /><br />只需要指定路径名,配置文件名默认为 `i18nrc.ts`|
15 changes: 8 additions & 7 deletions docs/dist/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
&emsp;&emsp;&emsp;&emsp;[Importing i18n.js in the Project Entry File](#importing-i18njs-in-the-project-entry-file)<br/>
&emsp;&emsp;&emsp;&emsp;[Wrap with `t` `Translation Text` ](#wrap-with--t---translation-text)<br/>
&emsp;&emsp;[3. Initialize Command Line Configuration File](#3-initialize-command-line-configuration-file)<br/>
&emsp;&emsp;[4. Adjust `i18nrc.js` Configuration](#4-adjust--i18nrcjs--configuration)<br/>
&emsp;&emsp;[4. Adjust `i18nrc.ts` Configuration](#4-adjust--i18nrcts--configuration)<br/>
&emsp;&emsp;[5. Execute Translation Command](#5-execute-translation-command)<br/>
&emsp;&emsp;[6. Importing Language Pack](#6-importing-language-pack)<br/>
&emsp;&emsp;[7. Switch Language](#7-switch-language)<br/>
Expand Down Expand Up @@ -86,11 +86,12 @@ Enter the following command at the command line terminal, [more commands](https:
```bash
npx i18n init
```
After the command execution is successful, a `i18nrc.js` file will be generated in the current directory. The default configuration will be as follows:
After the command execution is successful, a `i18nrc.ts` file will be generated in the current directory. The default configuration will be as follows:
```js
const { join } = require('path')
import { join } from 'path'
import { Config } from 'i18n-pro'

module.exports = {
export default {
funcName: 't',
entry: join(__dirname, './src/'),
fileRegExp: /\.[jt]s$/,
Expand All @@ -107,12 +108,12 @@ module.exports = {
},
// proxy: 'http://127.0.0.1:1087',
},
}
} as Config
```


## 4. Adjust `i18nrc.js` Configuration
Adjust the configuration items in the configuration file according to the requirements, [Description](https://github.com/i18n-pro/core/blob/v2.1.0/docs/dist/COMMAND_LINE.md#1--i18nrcjs--configuration) of configuration items
## 4. Adjust `i18nrc.ts` Configuration
Adjust the configuration items in the configuration file according to the requirements, [Description](https://github.com/i18n-pro/core/blob/v2.1.0/docs/dist/COMMAND_LINE.md#1--i18nrcts--configuration) of configuration items

## 5. Execute Translation Command

Expand Down
15 changes: 8 additions & 7 deletions docs/dist/USAGE_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
&emsp;&emsp;&emsp;&emsp;[项目入口文件引入 i18n.js](#项目入口文件引入-i18njs)<br/>
&emsp;&emsp;&emsp;&emsp;[`t` 包裹 `翻译文案` ](#用-t-包裹-翻译文案)<br/>
&emsp;&emsp;[3. 初始化命令行配置文件](#3-初始化命令行配置文件)<br/>
&emsp;&emsp;[4. 调整 `i18nrc.js` 配置](#4-调整-i18nrcjs-配置)<br/>
&emsp;&emsp;[4. 调整 `i18nrc.ts` 配置](#4-调整-i18nrcts-配置)<br/>
&emsp;&emsp;[5. 执行翻译命令](#5-执行翻译命令)<br/>
&emsp;&emsp;[6. 引入语言包](#6-引入语言包)<br/>
&emsp;&emsp;[7. 切换语言](#7-切换语言)<br/>
Expand Down Expand Up @@ -86,11 +86,12 @@ const text = t('hello world')
```bash
npx i18n init
```
命令执行成功后会在当前目录下生成一个 `i18nrc.js` 的文件,默认配置如下:
命令执行成功后会在当前目录下生成一个 `i18nrc.ts` 的文件,默认配置如下:
```js
const { join } = require('path')
import { join } from 'path'
import { Config } from 'i18n-pro'

module.exports = {
export default {
funcName: 't',
entry: join(__dirname, './src/'),
fileRegExp: /\.[jt]s$/,
Expand All @@ -107,12 +108,12 @@ module.exports = {
},
// proxy: 'http://127.0.0.1:1087',
},
}
} as Config
```


## 4. 调整 `i18nrc.js` 配置
根据需求自行调整配置文件中的配置项,配置项的[说明](https://github.com/i18n-pro/core/blob/v2.1.0/docs/dist/COMMAND_LINE_zh-CN.md#1--i18nrcjs-配置)
## 4. 调整 `i18nrc.ts` 配置
根据需求自行调整配置文件中的配置项,配置项的[说明](https://github.com/i18n-pro/core/blob/v2.1.0/docs/dist/COMMAND_LINE_zh-CN.md#1--i18nrcts-配置)

## 5. 执行翻译命令

Expand Down
22 changes: 22 additions & 0 deletions docs/src/changelog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,27 @@ function V_2_1_0() {
)
}

function V_2_2_0() {
return (
<Template
version="2.2.0"
date="2024-04-xx"
commandLine={{
added: [
'U',
tr(
'命令行配置文件支持用{0}来编写,从版本{1}开始,初始化命令执行生成的配置文件默认是{2},但老版的{3}依旧是兼容的',
' `TypeScript` ',
' `v2.2.0` ',
' `i18nrc.ts` ',
' `i18nrc.js` ',
),
],
}}
/>
)
}

export default function ChangeLog(props) {
initI18n(props)

Expand All @@ -443,6 +464,7 @@ export default function ChangeLog(props) {
<H1 skip>{tr('更新日志')}</H1>
{renderLanguage('CHANGELOG')}
<TableOfContents text={tr('目录')} open={false} />
<V_2_2_0 />
<V_2_1_0 />
<V_2_0_0 />
<V_1_3_2 />
Expand Down
4 changes: 2 additions & 2 deletions docs/src/commandline/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ function AliyunConfig() {
function Config() {
return (
<>
<H2>1. {tr('{0}配置', ' `i18nrc.js` ')}</H2>
<H2>1. {tr('{0}配置', ' `i18nrc.ts` ')}</H2>
<BasicConfig />
<Output />
<GooglexConfig />
Expand Down Expand Up @@ -1114,7 +1114,7 @@ function CommandProp() {
{tr('指定配置文件路径(参数为相对路径)')}
<br />
<br />
{tr('只需要指定路径名,配置文件名默认为{0}', ' `i18nrc.js`')}
{tr('只需要指定路径名,配置文件名默认为{0}', ' `i18nrc.ts`')}
</>
),
},
Expand Down
14 changes: 14 additions & 0 deletions docs/src/i18nrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { join } from 'path'
import { Config } from '../../src/type'
import rootConfig from '../../i18nrc.js'

export default {
...rootConfig,
funcName: 'tr',
entry: join(__dirname, '../src/'),
fileRegExp: /\.[jt]sx?$/,
input: 'docs/src/**/*.{js,ts,tsx}',
output: {
path: join(__dirname, './i18n/'),
},
} as Config
10 changes: 6 additions & 4 deletions docs/src/usage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ function InitConfig() {
<CodeBlock langType="bash" code={`npx i18n init `} />
{tr(
'命令执行成功后会在当前目录下生成一个{0}的文件,默认配置如下:',
' `i18nrc.js` ',
' `i18nrc.ts` ',
)}
<CodeBlock
code={getFileContent(resolve(__dirname, '../../../template/i18nrc.js'))}
code={getFileContent(
resolve(__dirname, '../../../template/i18nrc.ts'),
).replace('../src/type', 'i18n-pro')}
/>
</>
)
Expand All @@ -130,14 +132,14 @@ function ModifyConfig() {
return (
<>
<Break />
<H2>{`4. ${tr('调整{0}配置', ' `i18nrc.js` ')}`}</H2>
<H2>{`4. ${tr('调整{0}配置', ' `i18nrc.ts` ')}`}</H2>
{tr(
'根据需求自行调整配置文件中的配置项,配置项的{0}',
render(
<Link
href={getDocHref(
'COMMAND_LINE',
`1. ${tr('{0}配置', ' `i18nrc.js` ')}`,
`1. ${tr('{0}配置', ' `i18nrc.ts` ')}`,
)}
>
{tr('说明')}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"rollup-plugin-prettier": "^2.3.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.33.0",
"ts-node": "^10.9.2",
"tslib": "^2.4.1",
"typescript": "4.8.4",
"vitest": "^0.22.1"
Expand Down
Loading

0 comments on commit 813ac0a

Please sign in to comment.