[v2] Translations approach
See original GitHub issueš„ Proposal
An umbrella issue to track the translations work for v2 and guide the design and implementation on the feature in v2. Give suggestions and feedback on this issue.
Some initial thoughts:
- Translations should be a core feature built into Docusaurus core, not implemented specifically by any plugins
- We expose a current locale value in the context. Elements which need it can read from it
- For performance reasons, each translated website should be its own website (can be done via adding a
/<locale>/
to thebaseUrl
). This is basically sharding the website bundle so that the main bundle doesnāt contain routes for each locale. If performance isnāt a concern, then probably thereās no need to do this
Follow this issue for updates.
Some tools to consider using:
- https://github.com/globalizejs/globalize
- https://facebook.github.io/fbt/
- https://react.i18next.com/
- https://github.com/i18next/react-i18next/
Issues with v1 translations
- Build times are slow, especially when combined with versioning
- https://stackoverflow.com/questions/59125516/versioned-docusaurus-site-returns-404-for-the-other-languages
- #586
- #648
- #2206
- #2266
- #2278
- #2306
- #2471
Have you read the Contributing Guidelines on issues?
Yes
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:12 (6 by maintainers)
Top Results From Across the Web
WHODAS 2.0 Translation package
The WHODAS 2.0 Translation package provides protocols and supporting material for translation and linguistic evaluation of the WHO Disability Assessment ...
Read more >5 Best Translation Methods. Translation Techniques
What are the best translation methods? Ā· 1. Word-for-word translation Ā· 2. Literal translation Ā· 3. Communicative translation Ā· 4. Semantic translation Ā·...
Read more >Translating text (Basic)
This document describes how to use the Cloud Translation - Basic (v2) to translate text. The input text can be plain text or...
Read more >The Back Translation method: what is it and why use it?
The back translation method can give you clear documentation of all phases of the QA process. We can provide you with three different...
Read more >Bible Translations: Methods of Translation
After all, God said about him that āI send my angelos before your face . . .ā (Mark 1:2). In both II Corinthians...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nebrelbug Versioning might change a bit. We might end up doing
/<baseUrl>/<locale>/<docs>/<version>/<doc-path>
. IMO locale should be a first class feature in Docusaurus.Iāve been exploring using Docusaurus for a multilingual site, only to realize v2 doesnāt have any i18n layer. I have some experience with localizing products/documentation in various forms, including some automated localization pipelines, so here are my thoughts on how I would expect i18n to be handled:
/
URL on a multi-lingual site would redirect to a language-specific URL (e.g./en/
,/de/
,/fr/
) based on available languages for that URL, and userās browser language preferences./some-folder/some-page/
would redirect the user to e.g./en/some-folder/some-page/
,/de/some-folder/some-page/
or/fr/some-folder/some-page/
. An ability to provide deep links that auto-resolve to the target userās language is a must when using them in the product UI, marketing emails, and so on.sidebars.js
must not break the build, but hide that link from the document tree, and give a warning in the console log.Proposal
A set of localizable files include
docusaurus.config.js
,sidebars.js
and content folders (blog/
,docs/
). Imagine that you can have them sitting together in some common subfolder, e.g.content/
. So the structure becomes:All localizable content needed by plugins needs to be externalized into JavaScript/TypeScript/JSON files and reside in the
content/
folder as well. Ideally there would be some common format and file naming convention that all plugins are expected to use.Running
docusaurus build
without parameters would compile only the site inside the default (content/
) subfolder, with its local config, sidebars and content.An external localization process would need to take the source
content/
folder and create localized variants of this folder, for example,content-de/
,content-fr/
, etc. Running Docusaurus against a specific content folder would render that portion of the site. For example,docusaurus build content-fr
would try to loadcontent-fr/docusaurus.config.js
relative to the current working directory, and resolve all the documents relative to that file.Each content variant needs to have its unique root URL (mount point) so that the variants can be deployed to the target site independently. This could be done directly in each version of
docusaurus.config.js
, but it might be cleaner to have them listed in some global config.content-de/
would get a/de/
root URL,content-fr/
would map to/fr/
, and so on. The defaultcontent/
folder, depending on the source language, would also get a specific root URL, e.g./en/
. Having a root URL other than/
is necessary for per-URL language redirects.Making a version of a site means that the current state of these content folders needs to be duplicated. For example, when one decides to cut a version
1.x
, what would be done is:content
folder is copied tocontent-1.x
folder, and the root URL of the versioned copy changes from its current one, e.g./en/
, to/en/1.x/
content-de
folder is copied tocontent-de-1.x
with/de/1.x/
root URLcontent-fr
folder is copied tocontent-fr-1.x
with/fr/1.x/
root URLSimilarly, running
docusaurus deploy <content-directory>
would deploy this specific directory. It would be handy to have globs supported, so that one could saydocusaurus deploy *
to deploy all content directories, ordocusaurus deploy *-1.x
to redeploy all the content directories that end with-1.x
.Docusaurus would likely need to have static pre-rendered maps of all files for each of the content directories so that it can do quick lookups and per-URL language-based redirects, and that language negotiation/redirect portion will be shared across all content variants. Redeploying a particular language or a particular version would update these static maps, allowing to dynamically render the language switcher on all the pages.
Current workaround
Right now it should be possible to mimic the behavior I described above to some extent by creating a side project for each language variant and deploying each sub-site independently to a subdirectory of a global site. Symlinking directories like
node_modules
,src
and some common files might help in keeping all these versions in sync. A global 404 handler might be used to dynamically switch to an available language-specific variant of the page if a generic URL is provided.Sorry if thatās a lot of text to process. š Would love to hear your thoughts.