|
@@ -1,25 +1,22 @@
|
|
|
----
|
|
|
|
|
-id: translation
|
|
|
|
|
-title: Translations & Localization
|
|
|
|
|
----
|
|
|
|
|
|
|
+# 翻译 & 本地化
|
|
|
|
|
|
|
|
-Docusaurus allows for easy translation functionality using [Crowdin](https://crowdin.com/). Documentation files written in English are uploaded to Crowdin for translation by users within a community. Top-level pages written with English strings can be translated by wrapping any strings you want to translate in a `<translate>` tag. Other titles and labels will also be found and properly translated.
|
|
|
|
|
|
|
+Docusaurus允许使用 [Crowdin](https://crowdin.com/) 轻松实现翻译功能。 以英文撰写的文档文件将上传到 Crowdin,由社区内的用户进行翻译。 使用英文字符串编写的顶层页面可以通过在 `<translate>` 标签中包装要翻译的任何字符串来翻译。 其他标题和标签也将被找到并正确翻译。
|
|
|
|
|
|
|
|
-## Docusaurus Translation Configurations
|
|
|
|
|
|
|
+## Docusaurus 翻译配置
|
|
|
|
|
|
|
|
-To generate example files for translations with Docusaurus, run the `examples` script with the command line argument `translations`:
|
|
|
|
|
|
|
+要用 Docusaurus 生成用于翻译的示例文件,请使用命令行参数 `translations` 运行 `examples` 脚本:
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
npm run examples translations
|
|
npm run examples translations
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-or
|
|
|
|
|
|
|
+或
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
yarn examples translations
|
|
yarn examples translations
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-This will create the following files:
|
|
|
|
|
|
|
+这将创建以下文件:
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
pages/en/help-with-translations.js
|
|
pages/en/help-with-translations.js
|
|
@@ -27,24 +24,24 @@ languages.js
|
|
|
../crowdin.yaml
|
|
../crowdin.yaml
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-The `pages/en/help-with-translations.js` file includes the same starter help page generated by the `examples` script, but now includes translation tags.
|
|
|
|
|
|
|
+`pages/en/help-with-translations.js` 文件包含由 `examples` 脚本生成的相同的起始帮助页面,但现在包含了翻译标签。
|
|
|
|
|
|
|
|
-The `languages.js` file tells Docusaurus what languages you want to enable for your site. By default, we expect English to be enabled.
|
|
|
|
|
|
|
+`languages.js` 文件告诉 Docusaurus 你想为你的网站启用什么语言。 默认情况下,我们希望启用英文。
|
|
|
|
|
|
|
|
-The `crowdin.yaml` file is used to configure crowdin integration, and is copied up one level into your docusaurus project repo. If your docusaurus project resides in `/project/website`, then `crowdin.yaml` will be copied to `/project/crowdin.yaml`.
|
|
|
|
|
|
|
+`crowdin.yaml` 文件用于配置 crowdin 集成,并将其复制到您的 docusaurus 项目库。 如果您的docusaurus 项目驻留在 `/project/website` 中,则 `crowdin.yaml `将被复制到 `/project/crowdin.yaml` 中。
|
|
|
|
|
|
|
|
-## Translating Your Existing Docs
|
|
|
|
|
|
|
+## 翻译现有文档
|
|
|
|
|
|
|
|
-Your documentation files do not need to be changed or moved to support translations. They will be uploaded to Crowdin to be translated directly.
|
|
|
|
|
|
|
+您的文档文件不需要更改或移动来支持翻译。 他们将被上传到 Crowdin 直接翻译。
|
|
|
|
|
|
|
|
|
|
+## 在页面上启用翻译
|
|
|
|
|
|
|
|
-## Enabling Translations on Pages
|
|
|
|
|
|
|
+页面允许您自定义页面或帮助页面等页面的布局和特定内容。
|
|
|
|
|
|
|
|
-Pages allow you to customize layout and specific content of pages like a custom index page or help page.
|
|
|
|
|
|
|
+包含要翻译的文字的页面应放置在 `website/pages/en` 文件夹中。
|
|
|
|
|
|
|
|
-Pages with text that you want translated should be placed in `website/pages/en` folder.
|
|
|
|
|
|
|
+将需要翻译的字符串封装在一个 `<translate>` 标签中,并在文件的顶部添加下面的 `require` 语句:
|
|
|
|
|
|
|
|
-Wrap strings you want translated in a `<translate>` tag, and add the following `require` statement to the top of the file:
|
|
|
|
|
```jsx
|
|
```jsx
|
|
|
...
|
|
...
|
|
|
const translate = require("../../server/translate.js").translate;
|
|
const translate = require("../../server/translate.js").translate;
|
|
@@ -55,18 +52,20 @@ const translate = require("../../server/translate.js").translate;
|
|
|
...
|
|
...
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-You can also include an optional description attribute to give more context to a translator about how to translate the string:
|
|
|
|
|
|
|
+您还可以包含一个可选的 description 属性,为翻译者提供更多关于如何翻译字符串的上下文:
|
|
|
|
|
+
|
|
|
```jsx
|
|
```jsx
|
|
|
<p>
|
|
<p>
|
|
|
<translate desc="flower, not verb">Rose</translate>
|
|
<translate desc="flower, not verb">Rose</translate>
|
|
|
<p>
|
|
<p>
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-## Gathering Strings to Translate
|
|
|
|
|
|
|
+## 提取字符串到翻译
|
|
|
|
|
+
|
|
|
|
|
+必须提取本地化页面内的字符串并提供给 Crowdin。
|
|
|
|
|
|
|
|
-The strings within localized Pages must be extracted and provided to Crowdin.
|
|
|
|
|
|
|
+将以下脚本添加到您的package.json文件中:
|
|
|
|
|
|
|
|
-Add the following script to your package.json file:
|
|
|
|
|
```json
|
|
```json
|
|
|
...
|
|
...
|
|
|
"scripts": {
|
|
"scripts": {
|
|
@@ -75,51 +74,51 @@ Add the following script to your package.json file:
|
|
|
...
|
|
...
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-Running the script will generate a `website/i18n/en.json` file containing all the strings that will be translated from English into other languages.
|
|
|
|
|
|
|
+运行脚本将生成一个 `website/i18n/en.json` 文件,其中包含所有将从英文翻译成其他语言的字符串。
|
|
|
|
|
|
|
|
-The script will include text from the following places:
|
|
|
|
|
|
|
+该脚本将包括来自以下地方的文本:
|
|
|
|
|
|
|
|
-- `title` and `sidebar_label` strings in document markdown headers
|
|
|
|
|
-- category names in `sidebars.json`
|
|
|
|
|
-- tagline in `siteConfig.js`
|
|
|
|
|
-- header link `label` strings in `siteConfig.js`
|
|
|
|
|
-- strings wrapped in the `<translate>` tag in any `.js` files inside `pages`
|
|
|
|
|
|
|
+- 文档 markdown header 中的 `title` 和 `sidebar_label` 字符串
|
|
|
|
|
+- `sidebars.json` 中的类别名称
|
|
|
|
|
+- 在 `siteConfig.js` 中的 tagline
|
|
|
|
|
+- `siteConfig.js` 中的 header link 的 `label ` 字符串
|
|
|
|
|
+- 在 `pages` 内的任何 `.js` 文件中的 `<translate>` 标签中包装的字符串
|
|
|
|
|
|
|
|
-## How Strings Get Translated
|
|
|
|
|
|
|
+## 如何获得翻译的字符串
|
|
|
|
|
|
|
|
-Docusaurus itself does not do any translation from one language to another. Instead, it integrates [Crowdin](https://crowdin.com/) to upload translations and then downloads the appropriately translated files from Crowdin.
|
|
|
|
|
|
|
+Docusaurus 本身不会从一种语言翻译到另一种语言。 相反,它集成了 [Crowdin](https://crowdin.com/) 来上传翻译,然后从 Crowdin 下载适当翻译的文件。
|
|
|
|
|
|
|
|
-## How Docusaurus Uses String Translations
|
|
|
|
|
|
|
+## Docusaurus 如何使用字符串翻译
|
|
|
|
|
|
|
|
-This section provides context about how translations in Docusaurus works.
|
|
|
|
|
|
|
+本节介绍 Docusaurus 中的翻译如何工作。
|
|
|
|
|
|
|
|
-### Strings
|
|
|
|
|
|
|
+### 字符串
|
|
|
|
|
|
|
|
-A Docusaurus site has many strings used throughout it that require localization. However, maintaining a list of strings used through out a site can be laborious. Docusaurus simplifies this by centralizing strings.
|
|
|
|
|
|
|
+Docusaurus 网站有很多字符串需要本地化。 但是,维持在网站中使用的字符串列表可能是很费力的。 Docusaurus 通过集中字符串来简化这一点。
|
|
|
|
|
|
|
|
-The header navigation, for example can have links to 'Home' or your 'Blog'. This and other strings found in the headers and sidebars of pages are extracted and placed into `i18n/en.json`. When your files are translated, say into Spanish, a `i18n/es-ES.json` file will be downloaded from Crowdin. Then, when the Spanish pages are generated, Docusaurus will replace the English version of corresponding strings with translated strings from the corresponding localized strings file (e.g. In a Spanish enabled site 'Help' will become 'Ayuda').
|
|
|
|
|
|
|
+例如,标题导航可以链接到“主页”或“博客”。 在页面的标题和侧边栏中找到的这个和其他字符串被提取并放置到 `i18n/en.json` 中。 当你的文件被翻译成西班牙语时,一个 `i18n/es-ES.json` 文件将从 Crowdin 下载。 然后,当生成西班牙语页面时,Docusaurus 将从相应的本地化字符串文件中替换相应字符串的英文版本(例如,在启用西班牙语的网站“Help”中将变成“Ayuda”)。
|
|
|
|
|
|
|
|
-### Markdown Files
|
|
|
|
|
|
|
+### Markdown 文件
|
|
|
|
|
|
|
|
-For documentation files themselves, translated versions of these files are downloaded and then rendered through the proper layout template.
|
|
|
|
|
|
|
+对于文档文件本身,下载这些文件的翻译版本,然后通过适当的版面模板进行渲染。
|
|
|
|
|
|
|
|
-### Other Pages
|
|
|
|
|
|
|
+### 其它页面
|
|
|
|
|
|
|
|
-For other pages, Docusaurus will automatically transform all `<translate>` tags it finds into function calls that return the translated strings from the corresponding localized file _`locale.json`_.
|
|
|
|
|
|
|
+对于其他页面,Docusaurus 会自动将所发现的所有 `<translate>` 标签转换为函数调用,从相应的本地化文件 _`locale.json`_ 返回翻译后的字符串。
|
|
|
|
|
|
|
|
## Crowdin
|
|
## Crowdin
|
|
|
|
|
|
|
|
-Crowdin is a company that provides translation services. For Open Source projects, Crowdin provides free string translations
|
|
|
|
|
|
|
+Crowdin是一家提供翻译服务的公司。 对于开源项目,Crowdin 提供免费的字符串翻译。
|
|
|
|
|
|
|
|
-Create your translation project on [Crowdin](https://crowdin.com/). You can use [Crowdin's guides](https://support.crowdin.com/translation-process-overview/) to learn more about the translations work flow. _We suggest that you deselect and do not include "English" as a translateable language to prevent the creation of `en-US` localization files as this can lead to confusion._
|
|
|
|
|
|
|
+在 [Crowdin](https://crowdin.com/) 上创建您的翻译项目。 您可以使用[Crowdin的指南]](https://support.crowdin.com/translation-process-overview/)来了解有关翻译工作流程的更多信息。 _我们建议您不要选择“英语”作为可翻译的语言,以防止创建 `en-US` 本地化文件,因为这会导致混淆。_
|
|
|
|
|
|
|
|
-Your project will need a `crowdin.yaml` file generated.
|
|
|
|
|
|
|
+您的项目需要生成一个 `crowdin.yaml` 文件。
|
|
|
|
|
|
|
|
-> You will need to install `crowdin-cli`. Please follow the [installation directions](https://support.crowdin.com/cli-tool/).
|
|
|
|
|
|
|
+> 你将需要安装 `crowdin-cli`。 请参照[安装说明](https://support.crowdin.com/cli-tool/)。
|
|
|
|
|
|
|
|
-The example below can be automatically generated by the docusaurus cli with the `examples` script. It should be placed in the top level of your project directory to configure how and what files are uploaded/downloaded.
|
|
|
|
|
|
|
+下面的例子可以由 docusaurus cli 用 `examples` 脚本自动生成。 它应该放置在项目目录的顶层,以配置如何上传/下载文件。
|
|
|
|
|
|
|
|
-Below is an example crowdin configuration for the respective languages: German, Spanish, French, Japanese, Korean, Behasa Indonesia, Portuguese Brazilian, Chinese Simplified, and Chinese Traditional.
|
|
|
|
|
|
|
+以下是德语,西班牙语,法语,日语,韩语,印度尼西亚语,巴西葡萄牙语,简体中文和繁体中文的各种语言的配置示例。
|
|
|
|
|
|
|
|
```yaml
|
|
```yaml
|
|
|
project_identifier_env: CROWDIN_DOCUSAURUS_PROJECT_ID
|
|
project_identifier_env: CROWDIN_DOCUSAURUS_PROJECT_ID
|
|
@@ -144,13 +143,13 @@ files:
|
|
|
'zh-TW': 'zh-TW'
|
|
'zh-TW': 'zh-TW'
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-You can go [here](https://support.crowdin.com/configuration-file/) to learn more about customizing your `crowdin.yaml` file.
|
|
|
|
|
|
|
+你可以在[这里](https://support.crowdin.com/configuration-file/)了解更多关于定制你的 `crowdin.yaml` 文件的信息。
|
|
|
|
|
|
|
|
-### Manual File Sync
|
|
|
|
|
|
|
+### 手动同步文件
|
|
|
|
|
|
|
|
-You will want to manually sync your files to and from crowdin. The sync process will upload any markdown files in `/docs` as well as translatable strings in `website/i18n/en.json`. (These strings can be generated by running `yarn write-translations`.)
|
|
|
|
|
|
|
+您将需要手动同步您的文件下拉和上传到 crowdin。 同步过程将上传 `/ docs` 中的任何 markdown 文件以及 `website/i18n/en.json` 中的可翻译字符串。 (这些字符串可以通过运行 `yarn write-translations` 来生成。)
|
|
|
|
|
|
|
|
-You can add the following to your `package.json` to manually trigger crowdin.
|
|
|
|
|
|
|
+您可以将以下内容添加到您的 `package.json` 中以手动触发 crowdin。
|
|
|
|
|
|
|
|
```json
|
|
```json
|
|
|
"scripts": {
|
|
"scripts": {
|
|
@@ -161,15 +160,15 @@ You can add the following to your `package.json` to manually trigger crowdin.
|
|
|
},
|
|
},
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-These commands require having an environment variable set with your crowdin project id and api key (`CROWDIN_PROJECT_ID`, `CROWDIN_API_KEY`). You can add them inline like above or add them permanently to your `.bashrc` or `.bash_profile`.
|
|
|
|
|
|
|
+这些命令需要拥有一个环境变量,用您的 crowdin 项目 id 和 api key(`CROWDIN_PROJECT_ID`,`CROWDIN_API_KEY`)设置。 你可以像上面一样内联添加它们,或者将它们永久添加到你的 `.bashrc` 或 `.bash_profile` 中。
|
|
|
|
|
|
|
|
-If you run more than one localized Docusaurus project on your computer, you should change the name of the environment variables to something unique (`CROWDIN_PROJECTNAME_PROJECT_ID`, `CROWDIN_PROJECTNAME_API_KEY`).
|
|
|
|
|
|
|
+如果在计算机上运行多个本地化的 Docusaurus 项目,则应该将环境变量的名称更改为唯一(`CROWDIN_PROJECTNAME_PROJECT_ID`, `CROWDIN_PROJECTNAME_API_KEY`)。
|
|
|
|
|
|
|
|
-### Automated File Sync Using CircleCI
|
|
|
|
|
|
|
+### 使用 CircleCI 自动同步文件
|
|
|
|
|
|
|
|
-You can automate pulling down and uploading translations for your files using the [CircleCI](https://circleci.com) web continuous integration service.
|
|
|
|
|
|
|
+您可以使用 [CircleCI](https://circleci.com) 网络持续集成服务自动为您的文件下拉和上传翻译。
|
|
|
|
|
|
|
|
-First, update the `circle.yml` file in your project directory to include steps to upload English files to be translated and download translated files using the Crowdin CLI. Here is an example `circle.yml` file:
|
|
|
|
|
|
|
+首先,更新项目目录中的 `circle.yml` 文件,包括上传要翻译的英文文件的步骤,以及使用 Crowdin CLI 下载已翻译的文件。 这是一个 `circle.yml` 文件的例子:
|
|
|
|
|
|
|
|
```yaml
|
|
```yaml
|
|
|
machine:
|
|
machine:
|
|
@@ -186,34 +185,34 @@ deployment:
|
|
|
website:
|
|
website:
|
|
|
branch: master
|
|
branch: master
|
|
|
commands:
|
|
commands:
|
|
|
- # configure git user
|
|
|
|
|
|
|
+ # 配置 git 用户
|
|
|
- git config --global user.email "test-site-bot@users.noreply.github.com"
|
|
- git config --global user.email "test-site-bot@users.noreply.github.com"
|
|
|
- git config --global user.name "Website Deployment Script"
|
|
- git config --global user.name "Website Deployment Script"
|
|
|
- echo "machine github.com login test-site-bot password $GITHUB_TOKEN" > ~/.netrc
|
|
- echo "machine github.com login test-site-bot password $GITHUB_TOKEN" > ~/.netrc
|
|
|
- # install Docusaurus and generate file of English strings
|
|
|
|
|
|
|
+ # 安装 Docusaurus 并生成英文字符串文件
|
|
|
- cd website && npm install && npm run write-translations && cd ..
|
|
- cd website && npm install && npm run write-translations && cd ..
|
|
|
- # crowdin install
|
|
|
|
|
|
|
+ # 安装 crowdin
|
|
|
- sudo apt-get install default-jre
|
|
- sudo apt-get install default-jre
|
|
|
- wget https://artifacts.crowdin.com/repo/deb/crowdin.deb -O crowdin.deb
|
|
- wget https://artifacts.crowdin.com/repo/deb/crowdin.deb -O crowdin.deb
|
|
|
- sudo dpkg -i crowdin.deb
|
|
- sudo dpkg -i crowdin.deb
|
|
|
- # translations upload/download
|
|
|
|
|
|
|
+ # 翻译 上传/下载
|
|
|
- crowdin --config crowdin.yaml upload sources --auto-update -b master
|
|
- crowdin --config crowdin.yaml upload sources --auto-update -b master
|
|
|
- crowdin --config crowdin.yaml download -b master
|
|
- crowdin --config crowdin.yaml download -b master
|
|
|
- # build and publish website
|
|
|
|
|
|
|
+ # 构建和发布网站
|
|
|
- cd website && GIT_USER=test-site-bot npm run publish-gh-pages
|
|
- cd website && GIT_USER=test-site-bot npm run publish-gh-pages
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-The `crowdin` command uses the `crowdin.yaml` file generated with the `examples` script. It should be placed in your project directory to configure how and what files are uploaded/downloaded.
|
|
|
|
|
|
|
+`crowdin` 命令使用 `examples` 脚本生成的 `crowdin.yaml` 文件。 它应该放在您的项目目录中,以配置如何上传/下载文件。
|
|
|
|
|
|
|
|
-Note that in the `crowdin.yaml` file, `CROWDIN_PROJECT_ID` and `CROWDIN_API_KEY` are environment variables set-up in Circle for your Crowdin project. They can be found in your Crowdin project settings.
|
|
|
|
|
|
|
+请注意,在 `crowdin.yaml` 文件中,`CROWDIN_PROJECT_ID` 和 `CROWDIN_API_KEY` 是Circle 中为你的 Crowdin 项目设置的环境变量。 他们可以在您的 Crowdin 项目设置中找到。
|
|
|
|
|
|
|
|
-Now, Circle will help you automatically get translations prior to building your website. The provided `crowdin.yaml` file will copy translated documents into `website/translated_docs/`, and translated versions of the `i18n/en.json` strings file will into `i18n/${language}.json`.
|
|
|
|
|
|
|
+现在,Circle 将帮助您在构建您的网站之前自动获取翻译。 提供的 `crowdin.yaml` 文件会将翻译后的文件复制到 `website/translated_docs/` 中,`i18n/en.json` 字符串文件的翻译版本将转换为 `i18n/${language}.json`。
|
|
|
|
|
|
|
|
-If you wish to use Crowdin on your machine locally, you can install the [Crowdin CLI tool](https://support.crowdin.com/cli-tool/) and run the same commands found in the `circle.yaml` file. The only difference is that you must set `project_identifier` and `api_key` values in the `crowdin.yaml` file since you will not have Circle environment variables set up.
|
|
|
|
|
|
|
+如果你想在本地使用你的机器上的 Crowdin,你可以安装 [Crowdin CLI 工具](https://support.crowdin.com/cli-tool/) 并运行 `circle.yaml` 文件中的命令。 唯一的区别是你必须在 `crowdin.yaml` 文件中设置 `project_identifier` 和 `api_key` 值,因为你不会设置 Circle 环境变量。
|
|
|
|
|
|
|
|
-## Versioned Translations
|
|
|
|
|
|
|
+## 版本化翻译
|
|
|
|
|
|
|
|
-If you wish to have translation and versioning for your documentation, add the following section to the end of your `crowdin.yaml` file:
|
|
|
|
|
|
|
+如果您希望为文档进行翻译和版本控制,请将以下部分添加到 `crowdin.yaml` 文件的末尾:
|
|
|
|
|
|
|
|
```yaml
|
|
```yaml
|
|
|
-
|
|
-
|
|
@@ -222,6 +221,6 @@ If you wish to have translation and versioning for your documentation, add the f
|
|
|
languages_mapping: *anchor
|
|
languages_mapping: *anchor
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-Translated, versioned documents will be copied into `website/translated_docs/${language}/${version}/`.
|
|
|
|
|
|
|
+翻译版本的文档将被复制到 `website/translated_docs/${language}/${version}/`。
|
|
|
|
|
|
|
|
-> Ensure in your Crowdin settings, in the Translations section, that "Duplicate Strings" are set to ["Hide - all duplicates will share the same translation"](https://support.crowdin.com/api/create-project/). This setting will ensure that identical strings between versions share a single translation.
|
|
|
|
|
|
|
+> 确保在您的 Crowdin 设置的翻译部分中将 “重复字符串” 设置为[“隐藏 - 所有重复将共享相同的翻译”](https://support.crowdin.com/api/create-project/)。 此设置将确保不同版本之间的相同字符串共享一个翻译。
|