diff --git a/README.md b/README.md
index 06079c5..6efd254 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ English | [简体中文](https://github.com/i18n-pro/react/blob/vdoc/README_zh-C
- [要求](#要求)
+ [Requirement](#requirement)
[Features](#features)
[Live Demo](#live-demo)
[Principle](#principle)
@@ -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**
@@ -103,8 +103,8 @@ render(
# Help Document
->为了避免不必要的重复文档内容,该库的部分文档是链接 `i18n-pro` 中的内容
当前文档中 `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`
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)
diff --git a/docs/dist/API.md b/docs/dist/API.md
index 8db1faa..98ce6cb 100644
--- a/docs/dist/API.md
+++ b/docs/dist/API.md
@@ -1,44 +1,44 @@
# API
->为了避免不必要的重复文档内容,该库的部分文档是链接 `i18n-pro` 中的内容
当前文档中 `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`
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
Table of Contents
[I18nProvider](#i18nprovider)
- [类型](#i18nprovider-类型)
- [参数说明](#i18nprovider-参数说明)
+ [Type](#i18nprovider-type)
+ [Parameter Description](#i18nprovider-parameter-description)
[useI18n](#usei18n)
- [类型](#usei18n-类型)
+ [Type](#usei18n-type)
( - props: I18nState & { children: React.ReactNode }, + props: i18nState & { children: React.ReactNode }, ) => JSX.Element-
参数名 | -说明 | +Parameter name | +Description |
---|---|---|---|
children | -需要国际化的内容 | +Content that requires internationalization |
() => ({ t, diff --git a/docs/dist/API_zh-CN.md b/docs/dist/API_zh-CN.md index ed1c820..796b9ad 100644 --- a/docs/dist/API_zh-CN.md +++ b/docs/dist/API_zh-CN.md @@ -18,7 +18,7 @@类型
( - props: I18nState & { children: React.ReactNode }, + props: i18nState & { children: React.ReactNode }, ) => JSX.Elementdiff --git a/docs/dist/CHANGELOG.md b/docs/dist/CHANGELOG.md index aa24c28..80a7c7b 100644 --- a/docs/dist/CHANGELOG.md +++ b/docs/dist/CHANGELOG.md @@ -8,17 +8,17 @@ English | [简体中文](https://github.com/i18n-pro/react/blob/vdoc/docs/dist/C-## [1.0.0] - 2022-03-xx +## [1.0.0] - 2023-08-xxTable of Contents
- [[1.0.0] - 2022-03-xx](#100---2022-03-xx)
+ [[1.0.0] - 2023-08-xx](#100---2023-08-xx)
[API](#100-api)
[Added](#100-api-added)
API
Added
-* 新增 `I18nProvider` 和 `useI18n` 基础实现 +* Add `I18nProvider` and `useI18n` basic implementations diff --git a/docs/dist/CHANGELOG_zh-CN.md b/docs/dist/CHANGELOG_zh-CN.md index 780d04e..e9a6001 100644 --- a/docs/dist/CHANGELOG_zh-CN.md +++ b/docs/dist/CHANGELOG_zh-CN.md @@ -8,13 +8,13 @@-## [1.0.0] - 2022-03-xx +## [1.0.0] - 2023-08-xx目录
- [[1.0.0] - 2022-03-xx](#100---2022-03-xx)
+ [[1.0.0] - 2023-08-xx](#100---2023-08-xx)
[API](#100-api)
[Added](#100-api-added)
API
diff --git a/docs/dist/USAGE.md b/docs/dist/USAGE.md index 3451997..e9a8db2 100644 --- a/docs/dist/USAGE.md +++ b/docs/dist/USAGE.md @@ -1,36 +1,36 @@ # Quick Start ->为了避免不必要的重复文档内容,该库的部分文档是链接 `i18n-pro` 中的内容
当前文档中 `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`
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-## 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 @@ -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 @@ -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' @@ -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' @@ -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' @@ -167,4 +167,4 @@ render( ## 8. Demo -真实代码示例可参考 `README` 文档中的 [Live Demo](https://github.com/i18n-pro/react/tree/vdoc#live-demo) \ No newline at end of file +Real code examples can refer to [Live Demo](https://github.com/i18n-pro/react/tree/vdoc#live-demo) in the `README` document \ No newline at end of file diff --git a/docs/src/api/index.tsx b/docs/src/api/index.tsx index 0ee8b94..9634db1 100644 --- a/docs/src/api/index.tsx +++ b/docs/src/api/index.tsx @@ -1,14 +1,25 @@ -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( + {title}, + ) +} + function I18nProvider(props: I18nProProps) { const { i18nProPkg } = props @@ -16,9 +27,12 @@ function I18nProvider(props: I18nProProps) { <>Table of Contents
- [1. 安装](#1-安装)
- [2. 接入API](#2-接入api)
- [配置初始状态](#配置初始状态)
- [接入 `I18nProvider` 和 `useI18n` ,并用 `t` 包裹 `Translation Text` ](#接入-i18nprovider-和-usei18n-并用-t-包裹-translation-text)
- [3. 初始化命令行配置文件](#3-初始化命令行配置文件)
- [4. 调整 `i18nrc.js` 配置](#4-调整-i18nrcjs-配置)
- [5. 执行翻译命令](#5-执行翻译命令)
- [6. 引入语言包](#6-引入语言包)
- [7. 切换语言](#7-切换语言)
+ [1. Install](#1-install)
+ [2. Access API](#2-access-api)
+ [Configure initial state](#configure-initial-state)
+ [Connect `I18nProvider` and `useI18n` , and wrap `Translation Text` with `t` ](#connect--i18nprovider--and--usei18n--and-wrap--translation-text--with--t)
+ [3. Initialize Command Line Configuration File](#3-initialize-command-line-configuration-file)
+ [4. Adjust `i18nrc.js` Configuration](#4-adjust--i18nrcjs--configuration)
+ [5. Execute Translation Command](#5-execute-translation-command)
+ [6. Importing Language Pack](#6-importing-language-pack)
+ [7. Switch Language](#7-switch-language)
[8. Demo](#8-demo)
JSX.Element`} propsDesc={ <> @@ -43,21 +57,15 @@ function I18nProvider(props: I18nProProps) { function UseI18n(props: I18nProProps) { const { i18nProPkg } = props - function getTitleToA(title: string) { - return render( - {title}, - ) - } - return ( <> ({ - ${getTitleToA('t')}, - ${getTitleToA('setI18n')}, - ${getTitleToA('i18nState')}, + ${getTitleToA(i18nProPkg, 't')}, + ${getTitleToA(i18nProPkg, 'setI18n')}, + ${getTitleToA(i18nProPkg, 'i18nState')}, })`} /> > diff --git a/docs/src/changelog/index.tsx b/docs/src/changelog/index.tsx index e2f6a6d..9bd8530 100644 --- a/docs/src/changelog/index.tsx +++ b/docs/src/changelog/index.tsx @@ -6,7 +6,7 @@ function V_1_0_0() { return ( - I18nProvider :{t('配置国际化初始化属性的容器组件')} +I18nProvider :{getI18nProviderDesc()}- useI18n :{t('获取国际化 API 和状态的 hook 方法')} +useI18n :{getUseI18nDesc()}diff --git a/docs/src/utils.tsx b/docs/src/utils.tsx index 774f75a..31aa037 100644 --- a/docs/src/utils.tsx +++ b/docs/src/utils.tsx @@ -229,3 +229,11 @@ export function renderLanguage(filename: string) { > ) } + +export function getI18nProviderDesc() { + return t('配置国际化初始化属性的容器组件') +} + +export function getUseI18nDesc() { + return t('获取国际化 API 和状态的 hook 方法') +}