docusaurus/docs/translation.html
2017-08-17 02:31:45 +00:00

55 lines
No EOL
19 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"/><title>Translations · Docusaurus</title><meta name="viewport" content="width=device-width"/><meta property="og:title" content="Translations · Docusaurus"/><meta property="og:type" content="website"/><meta property="og:url" content="https://docusaurus.io/index.html"/><meta property="og:description" content="Docusaurus allows for easy translation functionality using Crowdin. Documentation files written in English are uploaded to Crowdin for translation by users. Top-level pages written with English strings can be translated by wrapping any strings you want to translate in a `&lt;translate&gt;` tag. Other titles and labels will also be found and properly translated."/><meta name="robots" content="noindex"/><link rel="shortcut icon" href="/img/docusaurus.ico"/><link rel="stylesheet" href="/css/main.css"/><script async="" defer="" src="https://buttons.github.io/buttons.js"></script></head><body class="sideNavVisible"><div class="fixedHeaderContainer"><div class="headerWrapper wrapper"><header><a href="/"><img src="/img/docusaurus.svg"/><h2>Docusaurus</h2></a><div class="navigationWrapper navigationSlider"><nav class="slidingNav"><ul class="nav-site nav-site-internal"><li><a href="/docs/installation.html" target="_self">Docs</a></li><li><a href="/en/help.html" target="_self">Help</a></li><li><a href="https://github.com/facebookexperimental/docusaurus" target="_self">GitHub</a></li></ul></nav></div></header></div></div><div class="navPusher"><div class="docMainWrapper wrapper"><div class="container docsNavContainer" id="docsNav"><nav class="toc"><div class="toggleNav"><section class="navWrapper wrapper"><div class="navBreadcrumb wrapper"><div class="navToggle" id="navToggler"><i></i></div><h2><i></i><span>Guides</span></h2></div><div class="navGroups"><div class="navGroup navGroupActive"><h3>Getting Started</h3><ul><li class="navListItem"><a class="navItem" href="/docs/installation.html#content">Installation</a></li><li class="navListItem"><a class="navItem" href="/docs/site-preparation.html#content">Site Preparation</a></li><li class="navListItem"><a class="navItem" href="/docs/site-creation.html#content">Creating your site</a></li></ul></div><div class="navGroup navGroupActive"><h3>Guides</h3><ul><li class="navListItem"><a class="navItem" href="/docs/custom-pages.html#content">Custom Pages</a></li><li class="navListItem"><a class="navItem" href="/docs/navigation.html#content">Navigation and Sidebars</a></li><li class="navListItem"><a class="navItem" href="/docs/blog.html#content">Adding a Blog</a></li><li class="navListItem navListItemActive"><a class="navItem navItemActive" href="/docs/translation.html#content">Translations</a></li><li class="navListItem"><a class="navItem" href="/docs/search.html#content">Enabling Search</a></li><li class="navListItem"><a class="navItem" href="/docs/versioning.html#content">Versioning</a></li></ul></div><div class="navGroup navGroupActive"><h3>API</h3><ul><li class="navListItem"><a class="navItem" href="/docs/commands.html#content">CLI Commands</a></li><li class="navListItem"><a class="navItem" href="/docs/api-pages.html#content">Pages and Styles</a></li><li class="navListItem"><a class="navItem" href="/docs/site-config.html#content">siteConfig.js</a></li><li class="navListItem"><a class="navItem" href="/docs/doc-markdown.html#content">Markdown Features</a></li></ul></div></div></section></div><script>
var toggler = document.getElementById('navToggler');
var nav = document.getElementById('docsNav');
toggler.onclick = function() {
nav.classList.toggle('docsSliderActive');
};
</script></nav></div><div class="container mainContainer"><div class="wrapper"><div class="post"><header class="postHeader"><a class="edit-page-link button" href="https://github.com/facebookexperimental/docusaurus/edit/master/docs/guides-translation.md" target="_blank">Edit this Doc</a><h1>Translations</h1></header><article><div><p>Docusaurus allows for easy translation functionality using Crowdin. Documentation files written in English are uploaded to Crowdin for translation by users. Top-level pages written with English strings can be translated by wrapping any strings you want to translate in a <code>&lt;translate&gt;</code> tag. Other titles and labels will also be found and properly translated.</p><h2><a class="anchor" name="docusaurus-translation-configurations"></a>Docusaurus Translation Configurations <a class="hash-link" href="#docusaurus-translation-configurations">#</a></h2><p>To generate example files for translations with Docusuaurus, run the <code>examples</code> script with the command line argument <code>translations</code>:</p><pre class="prism language-javascript">npm run examples translations</pre><p>This will create the following files:</p><pre class="prism language-javascript">pages<span class="token operator">/</span>en<span class="token operator">/</span>help<span class="token operator">-</span><span class="token keyword">with</span><span class="token operator">-</span>translations<span class="token punctuation">.</span>js
languages<span class="token punctuation">.</span>js
crowdin<span class="token punctuation">.</span>yaml</pre><p>The <code>pages/en/help-with-translations.js</code> file is the same example help page generated by the <code>examples</code> script but now using translations tags that are described below.
The <code>languages.js</code> file tells Docusaurus what languages you want to enable for your site.
The <code>crowdin.yaml</code> file is used to configure crowdin integration, and is copied out one level into your project repo.</p><h2><a class="anchor" name="writing-pages-to-be-translated"></a>Writing Pages to be Translated <a class="hash-link" href="#writing-pages-to-be-translated">#</a></h2><p>Any pages with text you want to be translated should go into the <code>website/pages/en</code> folder. Simply wrap any strings you want translated in a <code>&lt;translate&gt;</code> tag, and add the following <code>require</code> statement to the top of the file:</p><pre class="prism language-jsx"><span class="token operator">...</span>
<span class="token keyword">const</span> translate <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">&quot;../../server/translate.js&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span>translate<span class="token punctuation">;</span>
<span class="token operator">...</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>translate</span><span class="token punctuation">&gt;</span></span>This is a Header I want translated<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>translate</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">&gt;</span></span>
<span class="token operator">...</span></pre><p>You can also include an optional description attribute to give more context to a translator about how to translate the string:</p><pre class="prism language-jsx"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>translate</span> <span class="token attr-name">desc</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>flower, not verb<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>Rose<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>translate</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span></pre><p>Documentation files do not need to be changed to support translations. They will be uploaded to Crowdin to be translated directly.</p><h2><a class="anchor" name="gathering-strings-to-translate"></a>Gathering Strings to Translate <a class="hash-link" href="#gathering-strings-to-translate">#</a></h2><p>Add the following script to your package.json file:</p><pre class="prism language-json">...
<span class="token property">&quot;scripts&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;write-translations&quot;</span><span class="token operator">:</span> <span class="token string">&quot;docusaurus-write-translations&quot;</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
...</pre><p>Running the script will generate a <code>website/i18n/en.json</code> file containing all the strings that will be translated from English into other languages.</p><p>The script will include text from the following places:</p><ul><li><code>title</code> and <code>sidebar_label</code> strings in document markdown headers</li><li>category names in <code>sidebars.json</code></li><li>tagline in <code>siteConfig.js</code></li><li>header link <code>label</code> strings in <code>siteConfig.js</code></li><li>strings wrapped in the <code>&lt;translate&gt;</code> tag in any <code>.js</code> files inside <code>pages</code></li></ul><h2><a class="anchor" name="how-strings-get-translated"></a>How Strings Get Translated <a class="hash-link" href="#how-strings-get-translated">#</a></h2><p>Docusaurus itself does not do any translation from one language to another. Instead, it uses <a href="https://crowdin.com/" target="_blank">Crowdin</a> to manage translations and then downloads appropriately translated files from Crowdin. More information on how to set up Crowdin translations later.</p><h2><a class="anchor" name="how-docusaurus-uses-string-translations"></a>How Docusaurus Uses String Translations <a class="hash-link" href="#how-docusaurus-uses-string-translations">#</a></h2><p>This section provides some more context for how translation works, but is not necessary information for the user to know.</p><p>For things like the strings found in the headers and sidebars of pages, Docusaurus references a translated version of <code>i18n/en.json</code> (for example, a <code>i18n/fr.json</code> file downloaded from Crowdin).</p><p>For documentation text itself, fully translated markdown files will be compiled in the same way English documentation markdown files would be.</p><p>For other pages, Docusaurus will automatically transform all <code>&lt;translate&gt;</code> tags into function calls that will return appropriately translated strings. For each language that is enabled with <code>languages.js</code>, Docusaurus will build translated pages using the files in <code>pages/en</code> and the language&#x27;s respective <code>.json</code> file in <code>i18n</code>.</p><h2><a class="anchor" name="crowdin-set-up"></a>Crowdin Set-Up <a class="hash-link" href="#crowdin-set-up">#</a></h2><p>Create your translation project on <a href="https://www.crowdin.com/" target="_blank">Crowdin</a>. You can use <a href="https://support.crowdin.com/translation-process-overview/" target="_blank">Crowdin&#x27;s guides</a> to learn more about the translations work flow.</p><p>To automatically get the translations for your files, update the <code>circle.yml</code> 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 <code>circle.yml</code> file:</p><pre class="prism language-yaml"><span class="token key atrule">machine</span><span class="token punctuation">:</span>
<span class="token key atrule">node</span><span class="token punctuation">:</span>
<span class="token key atrule">version</span><span class="token punctuation">:</span> 6.10.3
<span class="token key atrule">npm</span><span class="token punctuation">:</span>
<span class="token key atrule">version</span><span class="token punctuation">:</span> 3.10.10
<span class="token key atrule">test</span><span class="token punctuation">:</span>
<span class="token key atrule">override</span><span class="token punctuation">:</span>
<span class="token punctuation">-</span> <span class="token string">&quot;true&quot;</span>
<span class="token key atrule">deployment</span><span class="token punctuation">:</span>
<span class="token key atrule">website</span><span class="token punctuation">:</span>
<span class="token key atrule">branch</span><span class="token punctuation">:</span> master
<span class="token key atrule">commands</span><span class="token punctuation">:</span>
<span spellcheck="true" class="token comment"># configure git user</span>
<span class="token punctuation">-</span> git config <span class="token punctuation">-</span><span class="token punctuation">-</span>global user.email &quot;test<span class="token punctuation">-</span>site<span class="token punctuation">-</span>bot@users.noreply.github.com&quot;
<span class="token punctuation">-</span> git config <span class="token punctuation">-</span><span class="token punctuation">-</span>global user.name &quot;Website Deployment Script&quot;
<span class="token punctuation">-</span> echo &quot;machine github.com login test<span class="token punctuation">-</span>site<span class="token punctuation">-</span>bot password $GITHUB_TOKEN&quot; <span class="token punctuation">&gt;</span> ~/.netrc
<span spellcheck="true" class="token comment"># install Docusaurus and generate file of English strings</span>
<span class="token punctuation">-</span> cd website &amp;&amp; npm install &amp;&amp; npm run write<span class="token punctuation">-</span>translations &amp;&amp; cd ..
<span spellcheck="true" class="token comment"># crowdin install</span>
<span class="token punctuation">-</span> sudo apt<span class="token punctuation">-</span>get install default<span class="token punctuation">-</span>jre
<span class="token punctuation">-</span> wget https<span class="token punctuation">:</span>//artifacts.crowdin.com/repo/deb/crowdin.deb <span class="token punctuation">-</span>O crowdin.deb
<span class="token punctuation">-</span> sudo dpkg <span class="token punctuation">-</span>i crowdin.deb
<span spellcheck="true" class="token comment"># translations upload/download</span>
<span class="token punctuation">-</span> crowdin <span class="token punctuation">-</span><span class="token punctuation">-</span>config crowdin.yaml upload sources <span class="token punctuation">-</span><span class="token punctuation">-</span>auto<span class="token punctuation">-</span>update <span class="token punctuation">-</span>b master
<span class="token punctuation">-</span> crowdin <span class="token punctuation">-</span><span class="token punctuation">-</span>config crowdin.yaml download <span class="token punctuation">-</span>b master
<span spellcheck="true" class="token comment"># build and publish website</span>
<span class="token punctuation">-</span> cd website &amp;&amp; GIT_USER=test<span class="token punctuation">-</span>site<span class="token punctuation">-</span>bot npm run publish<span class="token punctuation">-</span>gh<span class="token punctuation">-</span>pages</pre><p>The <code>crowdin</code> command uses the <code>crowdin.yaml</code> file generated with the <code>examples</code> script. It should be placed in your project directory to configure how and what files are uploaded/downloaded.</p><p>Note that in the <code>crowdin.yaml</code> file, <code>CROWDIN_PROJECT_ID</code> and <code>CROWDIN_API_KEY</code> are environment variables set-up in Circle for your Crowdin project. They can be found in your Crowdin project settings.</p><p>Now, Circle will help you automatically get translations prior to building your website. The provided <code>crowdin.yaml</code> file will copy translated documents into <code>website/translated_docs/</code>, and translated versions of the <code>i18n/en.json</code> strings file will into <code>i18n/${language}.json</code>.</p><p>If you wish to use Crowdin on your machine locally, you can install the <a href="https://support.crowdin.com/cli-tool/" target="_blank">Crowdin CLI tool</a> and run the same commands found in the <code>circle.yaml</code> file. The only difference is that you must set <code>project_identifier</code> and <code>api_key</code> values in the <code>crowdin.yaml</code> file since you will not have Circle environment variables set up. </p><h2><a class="anchor" name="translations-and-versioning"></a>Translations and Versioning <a class="hash-link" href="#translations-and-versioning">#</a></h2><p>If you wish to have translation and versioning for your documentation, add the following section to the end of your <code>crowdin.yaml</code> file:</p><pre class="prism language-yaml"> <span class="token punctuation">-</span>
<span class="token key atrule">source</span><span class="token punctuation">:</span> <span class="token string">&#x27;/website/versioned_docs/**/*.md&#x27;</span>
<span class="token key atrule">translation</span><span class="token punctuation">:</span> <span class="token string">&#x27;/website/translated_docs/%locale%/**/%original_file_name%&#x27;</span>
<span class="token key atrule">languages_mapping</span><span class="token punctuation">:</span> <span class="token important">*anchor</span></pre><p>Translated, versioned documents will be copied into <code>website/translated_docs/${language}/${version}/</code>.</p></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="blog.html#content">← Previous</a><a class="docs-next button" href="search.html#content">Next →</a></div></div></div></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/" class="nav-home"><img src="/img/docusaurus_monochrome.svg" alt="Docusaurus" width="66" height="58"/></a><div><h5>Docs</h5><a href="
/docs/installation.html">Getting Started</a></div><div><h5>Community</h5><a href="/en/users.html">User Showcase</a></div><div><h5>More</h5><a href="https://github.com/facebookexperimental/docusaurus">GitHub</a><a class="github-button" href="https://github.com/facebookexperimental/docusaurus" data-icon="octicon-star" data-count-href="/facebookexperimental/docusaurus/stargazers" data-count-api="/repos/facebookexperimental/docusaurus#stargazers_count" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><a href="https://code.facebook.com/projects/" target="_blank" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2017 Facebook Inc.</section></footer></div></body></html>