Skip to content

Commit

Permalink
docs: update
Browse files Browse the repository at this point in the history
translate the docs
  • Loading branch information
eyelly-wu committed Aug 29, 2023
1 parent 1786369 commit dda5662
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 72 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ English | [简体中文](https://github.com/i18n-pro/react/blob/vdoc/README_zh-C
<summary>Table of Contents</summary>

[Vision](#vision)<br/>
[要求](#要求)<br/>
[Requirement](#requirement)<br/>
[Features](#features)<br/>
[Live Demo](#live-demo)<br/>
[Principle](#principle)<br/>
Expand All @@ -31,7 +31,7 @@ English | [简体中文](https://github.com/i18n-pro/react/blob/vdoc/README_zh-C

# Vision
To make internationalization easy and enjoyable 😄💪🏻
# 要求
# Requirement

* react >= **16.8.0**
* react-dom >= **16.8.0**
Expand Down Expand Up @@ -103,8 +103,8 @@ render(

# Help Document

>为了避免不必要的重复文档内容,该库的部分文档是链接 `i18n-pro` 中的内容<br />当前文档中 `i18n-pro` 相关链接是基于 `2.0.0` 版本,如果你使用的非该版本,需查看你所使用版本对应的文档,以免用法不一致
* 当前库
>To avoid unnecessary duplicate document content, some of the documents in this library are linked to the content in `i18n-pro` <br />The `i18n-pro` related link in the current document is based on the `2.0.0` version. If you are using a different version, you need to check the document corresponding to the version you are using to avoid inconsistent usage
* Current Library
* [Quick Start](https://github.com/i18n-pro/react/blob/vdoc/docs/dist/USAGE.md)
* [API](https://github.com/i18n-pro/react/blob/vdoc/docs/dist/API.md)
* [Changelog](https://github.com/i18n-pro/react/blob/vdoc/docs/dist/CHANGELOG.md)
Expand Down
24 changes: 12 additions & 12 deletions docs/dist/API.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@

# API

>为了避免不必要的重复文档内容,该库的部分文档是链接 `i18n-pro` 中的内容<br />当前文档中 `i18n-pro` 相关链接是基于 `2.0.0` 版本,如果你使用的非该版本,需查看你所使用版本对应的文档,以免用法不一致
>To avoid unnecessary duplicate document content, some of the documents in this library are linked to the content in `i18n-pro` <br />The `i18n-pro` related link in the current document is based on the `2.0.0` version. If you are using a different version, you need to check the document corresponding to the version you are using to avoid inconsistent usage
<details >
<summary>Table of Contents</summary>
&emsp;&emsp;[I18nProvider](#i18nprovider)<br/>
&emsp;&emsp;&emsp;&emsp;[类型](#i18nprovider-类型)<br/>
&emsp;&emsp;&emsp;&emsp;[参数说明](#i18nprovider-参数说明)<br/>
&emsp;&emsp;&emsp;&emsp;[Type](#i18nprovider-type)<br/>
&emsp;&emsp;&emsp;&emsp;[Parameter Description](#i18nprovider-parameter-description)<br/>
&emsp;&emsp;[useI18n](#usei18n)<br/>
&emsp;&emsp;&emsp;&emsp;[类型](#usei18n-类型)<br/>
&emsp;&emsp;&emsp;&emsp;[Type](#usei18n-type)<br/>

</details>

## I18nProvider
Configure container components for internationalization initialization properties
<h3 id="i18nprovider-类型">类型</h3>
<h3 id="i18nprovider-type">Type</h3>
<pre>
(
props: I18nState & { children: React.ReactNode },
props: <a href="https://github.com/i18n-pro/core/blob/v2.0.0/docs/dist/API.md#i18nstate">i18nState</a> & { children: React.ReactNode },
) => JSX.Element
</pre>

<h3 id="i18nprovider-参数说明">参数说明</h3>
其他属性与 <a href="https://github.com/i18n-pro/core/blob/v2.0.0/docs/dist/API.md#initi18n">initI18n</a> 参数一致<table>
<h3 id="i18nprovider-parameter-description">Parameter Description</h3>
The other attributes are consistent with the <a href="https://github.com/i18n-pro/core/blob/v2.0.0/docs/dist/API.md#initi18n">initI18n</a> parameter<table>
<tr>
<th>参数名</th>
<th>说明</th>
<th>Parameter name</th>
<th>Description</th>
</tr>
<tr>
<tr>
<td>children</td>
<td>需要国际化的内容</td>
<td>Content that requires internationalization</td>
</tr>
</tr>
</table>

## useI18n
Hook method for obtaining internationalization API and status
<h3 id="usei18n-类型">类型</h3>
<h3 id="usei18n-type">Type</h3>
<pre>
() => ({
<a href="https://github.com/i18n-pro/core/blob/v2.0.0/docs/dist/API.md#t">t</a>,
Expand Down
2 changes: 1 addition & 1 deletion docs/dist/API_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<h3 id="i18nprovider-类型">类型</h3>
<pre>
(
props: I18nState & { children: React.ReactNode },
props: <a href="https://github.com/i18n-pro/core/blob/v2.0.0/docs/dist/API_zh-CN.md#i18nstate">i18nState</a> & { children: React.ReactNode },
) => JSX.Element
</pre>

Expand Down
6 changes: 3 additions & 3 deletions docs/dist/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ English | [简体中文](https://github.com/i18n-pro/react/blob/vdoc/docs/dist/C
<details >
<summary>Table of Contents</summary>

&emsp;&emsp;[[1.0.0] - 2022-03-xx](#100---2022-03-xx)<br/>
&emsp;&emsp;[[1.0.0] - 2023-08-xx](#100---2023-08-xx)<br/>
&emsp;&emsp;&emsp;&emsp;[API](#100-api)<br/>
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;[Added](#100-api-added)<br/>

</details>

## [1.0.0] - 2022-03-xx
## [1.0.0] - 2023-08-xx

<h3 id="100-api">API</h3>

<h4 id="100-api-added">Added</h4>

* 新增 `I18nProvider` `useI18n` 基础实现
* Add `I18nProvider` and `useI18n` basic implementations

4 changes: 2 additions & 2 deletions docs/dist/CHANGELOG_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<details >
<summary>目录</summary>

&emsp;&emsp;[[1.0.0] - 2022-03-xx](#100---2022-03-xx)<br/>
&emsp;&emsp;[[1.0.0] - 2023-08-xx](#100---2023-08-xx)<br/>
&emsp;&emsp;&emsp;&emsp;[API](#100-api)<br/>
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;[Added](#100-api-added)<br/>

</details>

## [1.0.0] - 2022-03-xx
## [1.0.0] - 2023-08-xx

<h3 id="100-api">API</h3>

Expand Down
60 changes: 30 additions & 30 deletions docs/dist/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@

# Quick Start

>为了避免不必要的重复文档内容,该库的部分文档是链接 `i18n-pro` 中的内容<br />当前文档中 `i18n-pro` 相关链接是基于 `2.0.0` 版本,如果你使用的非该版本,需查看你所使用版本对应的文档,以免用法不一致
>To avoid unnecessary duplicate document content, some of the documents in this library are linked to the content in `i18n-pro` <br />The `i18n-pro` related link in the current document is based on the `2.0.0` version. If you are using a different version, you need to check the document corresponding to the version you are using to avoid inconsistent usage
<details >
<summary>Table of Contents</summary>
&emsp;&emsp;[1. 安装](#1-安装)<br/>
&emsp;&emsp;[2. 接入API](#2-接入api)<br/>
&emsp;&emsp;&emsp;&emsp;[配置初始状态](#配置初始状态)<br/>
&emsp;&emsp;&emsp;&emsp;[接入 `I18nProvider` `useI18n` ,并用 `t` 包裹 `Translation Text` ](#接入-i18nprovider-和-usei18n-并用-t-包裹-translation-text)<br/>
&emsp;&emsp;[3. 初始化命令行配置文件](#3-初始化命令行配置文件)<br/>
&emsp;&emsp;[4. 调整 `i18nrc.js` 配置](#4-调整-i18nrcjs-配置)<br/>
&emsp;&emsp;[5. 执行翻译命令](#5-执行翻译命令)<br/>
&emsp;&emsp;[6. 引入语言包](#6-引入语言包)<br/>
&emsp;&emsp;[7. 切换语言](#7-切换语言)<br/>
&emsp;&emsp;[1. Install](#1-install)<br/>
&emsp;&emsp;[2. Access API](#2-access-api)<br/>
&emsp;&emsp;&emsp;&emsp;[Configure initial state](#configure-initial-state)<br/>
&emsp;&emsp;&emsp;&emsp;[Connect `I18nProvider` and `useI18n` , and wrap `Translation Text` with `t` ](#connect--i18nprovider--and--usei18n--and-wrap--translation-text--with--t)<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;[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/>
&emsp;&emsp;[8. Demo](#8-demo)<br/>

</details>

## 1. 安装
## 1. Install

```bash
npm i @i18n-pro/react
# 或者
# or
yarn add @i18n-pro/react
# 或者
# or
pnpm i @i18n-pro/react
```

## 2. 接入API
## 2. Access API

### 配置初始状态
### Configure initial state

```js
// i18n.ts
Expand All @@ -41,7 +41,7 @@ export default {
} as I18nState
```

### 接入 `I18nProvider` `useI18n` ,并用 `t` 包裹 `Translation Text`
### Connect `I18nProvider` and `useI18n` , and wrap `Translation Text` with `t`

```js
// App.tsx
Expand All @@ -65,19 +65,19 @@ render(
```


## 3. 初始化命令行配置文件
[请参考](https://github.com/i18n-pro/core/blob/v2.0.0/docs/dist/USAGE.md#3-初始化命令行配置文件)
## 3. Initialize Command Line Configuration File
[Please refer to](https://github.com/i18n-pro/core/blob/v2.0.0/docs/dist/USAGE.md#3-initialize-command-line-configuration-file)

## 4. 调整 `i18nrc.js` 配置
[请参考](https://github.com/i18n-pro/core/blob/v2.0.0/docs/dist/USAGE.md#4-调整-i18nrcjs-配置)
## 4. Adjust `i18nrc.js` Configuration
[Please refer to](https://github.com/i18n-pro/core/blob/v2.0.0/docs/dist/USAGE.md#4-adjust--i18nrcjs--configuration)

## 5. 执行翻译命令
[请参考](https://github.com/i18n-pro/core/blob/v2.0.0/docs/dist/USAGE.md#5-执行翻译命令)
## 5. Execute Translation Command
[Please refer to](https://github.com/i18n-pro/core/blob/v2.0.0/docs/dist/USAGE.md#5-execute-translation-command)

## 6. 引入语言包
语言包已经有了,就需要应用到项目中了
## 6. Importing Language Pack
The language pack already exists, so it needs to be applied to the project

如果生成的语言包是每个语言单独文件形式`output.langType == 'multiple'`,操作如下:
If the generated language pack is a separate file form `output.langType == 'multiple'` for each language, the operation is as follows:
```diff
// i18n.ts
import { I18nState } from 'i18n-pro/react'
Expand All @@ -93,7 +93,7 @@ export default {
+ },
} as I18nState
```
如果生成的语言包是聚合的形式`output.langType == 'single'`,操作如下:
If the generated language pack is in the form of aggregation `output.langType == 'single'`, the operation is as follows:
```diff
// i18n.ts
import { I18nState } from 'i18n-pro/react'
Expand All @@ -105,10 +105,10 @@ export default {
+ langs,
} as I18nState
```
至此,项目已经完全接入了国际化,上面 `locale` 指定为目标语言中任意一个,在页面上就能看到翻译好的内容了。后续如果项目中有新增的 `Translation Text` (需要用 `t` 函数包裹哟),就仅仅需要再次执行翻译命令 `npx i18n t` 生成最新的语言包就可以了
At this point, the project has been completely connected to internationalization. The above `locale` specifies any of the target language, and the translated content can be seen on the page. If there are new `Translation Text` (need to be wrapped with `t` function) in the subsequent project, you only need to execute the translation command `npx i18n t` again to generate the latest language package

## 7. 切换语言
可以通过 `setI18n` 来切换语言
## 7. Switch Language
You can switch languages through `setI18n`
```diff
// SwitchLang.tsx
import React from 'react'
Expand Down Expand Up @@ -167,4 +167,4 @@ render(


## 8. Demo
真实代码示例可参考 `README` 文档中的 [Live Demo](https://github.com/i18n-pro/react/tree/vdoc#live-demo)
Real code examples can refer to [Live Demo](https://github.com/i18n-pro/react/tree/vdoc#live-demo) in the `README` document
36 changes: 22 additions & 14 deletions docs/src/api/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
import { Break, H1, render, H3, TableOfContents, getAnchor } from 'jsx-to-md'
import { H1, render, TableOfContents } from 'jsx-to-md'
import I18nProWrapper from '../components/I18nProWrapper'
import SpecialStatement from '../components/SpecialStatement'
import { Package } from '../types'
import { getI18nProDocHref, initI18n } from '../utils'
import {
getI18nProDocHref,
getI18nProviderDesc,
getUseI18nDesc,
initI18n,
} from '../utils'
import FunctionTemplate from './FunctionTemplate'

type I18nProProps = {
i18nProPkg: Package
}

function getTitleToA(i18nProPkg: Package, title: string) {
return render(
<a href={getI18nProDocHref(i18nProPkg, 'API', title)}>{title}</a>,
)
}

function I18nProvider(props: I18nProProps) {
const { i18nProPkg } = props

return (
<>
<FunctionTemplate
name="I18nProvider"
description={t('配置国际化初始化属性的容器组件')}
description={getI18nProviderDesc()}
type={`(
props: I18nState & { children: React.ReactNode },
props: ${getTitleToA(
i18nProPkg,
'i18nState',
)} & { children: React.ReactNode },
) => JSX.Element`}
propsDesc={
<>
Expand All @@ -43,21 +57,15 @@ function I18nProvider(props: I18nProProps) {
function UseI18n(props: I18nProProps) {
const { i18nProPkg } = props

function getTitleToA(title: string) {
return render(
<a href={getI18nProDocHref(i18nProPkg, 'API', title)}>{title}</a>,
)
}

return (
<>
<FunctionTemplate
name="useI18n"
description={t('获取国际化 API 和状态的 hook 方法')}
description={getUseI18nDesc()}
type={`() => ({
${getTitleToA('t')},
${getTitleToA('setI18n')},
${getTitleToA('i18nState')},
${getTitleToA(i18nProPkg, 't')},
${getTitleToA(i18nProPkg, 'setI18n')},
${getTitleToA(i18nProPkg, 'i18nState')},
})`}
/>
</>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/changelog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function V_1_0_0() {
return (
<Template
version="1.0.0"
date="2022-03-xx"
date="2023-08-xx"
api={{
added: [
'U',
Expand Down
36 changes: 34 additions & 2 deletions docs/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,44 @@
"API": "API",
"翻译日志": "Translation log",
"以下特性继承于{0}": "The following features are inherited from {0}",
"待更新": "To be updated",
"该库是基于{0}结合{1}的{2}特性来实现的": "This library is implemented based on {0} combined with {1}'s {2} feature",
"配置国际化初始化属性的容器组件": "Configure container components for internationalization initialization properties",
"简易示例如下": "A simple example is as follows",
"hello world": "Hello world",
"适用于 React 的轻量、简单、灵活、自动翻译的国际化工具": "Lightweight, simple, flexible, automatic translation internationalization tool for React",
"获取国际化 API 和状态的 hook 方法": "Hook method for obtaining internationalization API and status",
"主要由{0}部分构成": "Mainly composed of {0} parts"
"主要由{0}部分构成": "Mainly composed of {0} parts",
"变量插值": "Variable Interpolation",
"插值变量": "Interpolation Variable",
"类型": "Type",
"说明": "Description",
"参数名": "Parameter name",
"命令行工具": "Command Line Tool",
"安装": "Install",
"或者": "or",
"初始化命令行配置文件": "Initialize Command Line Configuration File",
"调整{0}配置": "Adjust {0} Configuration",
"执行翻译命令": "Execute Translation Command",
"引入语言包": "Importing Language Pack",
"语言包已经有了,就需要应用到项目中了": "The language pack already exists, so it needs to be applied to the project",
"如果生成的语言包是每个语言单独文件形式{0},操作如下:": "If the generated language pack is a separate file form {0} for each language, the operation is as follows:",
"如果生成的语言包是聚合的形式{0},操作如下:": "If the generated language pack is in the form of aggregation {0}, the operation is as follows:",
"切换语言": "Switch Language",
"文档": "Documentation",
"参数说明": "Parameter Description",
"返回值": "Return Value",
"至此,项目已经完全接入了国际化,上面{0}指定为目标语言中任意一个,在页面上就能看到翻译好的内容了。后续如果项目中有新增的{1}(需要用{2}函数包裹哟),就仅仅需要再次执行翻译命令{3}生成最新的语言包就可以了": "At this point, the project has been completely connected to internationalization. The above {0} specifies any of the target language, and the translated content can be seen on the page. If there are new {1} (need to be wrapped with {2} function) in the subsequent project, you only need to execute the translation command {3} again to generate the latest language package",
"其他属性与{0}参数一致": "The other attributes are consistent with the {0} parameter",
"需要国际化的内容": "Content that requires internationalization",
"新增{0}和{1}基础实现": "Add {0} and {1} basic implementations",
"为了避免不必要的重复文档内容,该库的部分文档是链接{0}中的内容": "To avoid unnecessary duplicate document content, some of the documents in this library are linked to the content in {0}",
"当前文档中{0}相关链接是基于{1}版本,如果你使用的非该版本,需查看你所使用版本对应的文档,以免用法不一致": "The {0} related link in the current document is based on the {1} version. If you are using a different version, you need to check the document corresponding to the version you are using to avoid inconsistent usage",
"当前库": "Current Library",
"要求": "Requirement",
"接入API": "Access API",
"配置初始状态": "Configure initial state",
"接入{0}和{1},并用{2}包裹{3}": "Connect {0} and {1}, and wrap {3} with {2}",
"请参考": "Please refer to",
"可以通过{0}来切换语言": "You can switch languages through {0}",
"真实代码示例可参考{0}文档中的{1}": "Real code examples can refer to {1} in the {0} document"
}
6 changes: 3 additions & 3 deletions docs/src/readme/Principle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Break, H1, Bold, CodeBlock, List } from 'jsx-to-md'
import { getI18nPro } from '../utils'
import { getI18nPro, getI18nProviderDesc, getUseI18nDesc } from '../utils'

export default function Principle() {
return (
Expand All @@ -17,10 +17,10 @@ export default function Principle() {
<List items={['U', 'I18nProvider', 'useI18n']} />
<Break />
<Break />
<Bold>I18nProvider</Bold>{t('配置国际化初始化属性的容器组件')}
<Bold>I18nProvider</Bold>{getI18nProviderDesc()}
<Break />
<Break />
<Bold>useI18n</Bold>{t('获取国际化 API 和状态的 hook 方法')}
<Bold>useI18n</Bold>{getUseI18nDesc()}
<Break />
<Break />
<Break />
Expand Down
Loading

0 comments on commit dda5662

Please sign in to comment.