Repository navigation
Closed
Labels
proposalThis issue is a proposal, usually non-trivial change
Description
💥 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
- Feature request: Add ability to change default language #586
- "Edit doc" should more seamlessly integrate with translations #648
- Non-English Tutorial Section Images Render Markup #2206
- Translated sidebar no longer translated once versioned #2266
- Is there a way to restrict sending text for translation to Crowdin? (Docusaurus) #2278
- Pages with redirects instead of translations when docsUrl === '' and path to file includes 'en' #2306
- <html> element does not have a [lang] attribute #2471
Have you read the Contributing Guidelines on issues?
Yes
Reacted by Muhammad Satrio Wicaksono
Reacted by nothingismagick
Metadata
Metadata
Assignees
Labels
proposalThis issue is a proposal, usually non-trivial change
Activity
fanny commentedon Apr 29, 2020
Do you plan use an approach like the
react-i18n-intl? In the v1, we have thecrowdinto make the translations, but this put the limitation to assume that the default language is english. Is a plan to v2 change this architecture, to make possible the developer submit your own translations and we use a framework to read them?yangshun commentedon Apr 29, 2020
There are two things we need to translate here:
react-i18n-intlbgub commentedon Apr 30, 2020
@yangshun would #2302 need to be completed first, or will versioning stay similar enough as presented to the user?
yangshun commentedon May 30, 2020
@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.bgub commentedon May 30, 2020
////meaning something like/en/docs/v2/somedoc-name?yangshun commentedon Jun 5, 2020
@nebrelbug Sorry I had to wrap the text in a code tags for it to show. But you got it!
nothingismagick commentedon Jun 20, 2020
We would still love to be able to use
crowdinif that is possible.slorber commentedon Jun 22, 2020
There are many potential solutions for i18n in v2 that we are thinking about.
I think for regular MD docs, we should stick to integrating with a SaaS that allows uploading MD files directly, so that translators can work in full doc context, instead of translating key/value pairs.
Keeping compability with Crowdin is probably important to v1 users.
We also need to validate that Crowdin and other i18n SaaS providers works great with MDX (ie docs pages embedding React components for interactive demos). If you have feedback on that I'm interested.
iafan commentedon Jul 20, 2020
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.jsmust 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.jsand 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 buildwithout 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-frwould try to loadcontent-fr/docusaurus.config.jsrelative 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:contentfolder is copied tocontent-1.xfolder, and the root URL of the versioned copy changes from its current one, e.g./en/, to/en/1.x/content-defolder is copied tocontent-de-1.xwith/de/1.x/root URLcontent-frfolder is copied tocontent-fr-1.xwith/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.xto 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,srcand 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.
slorber commentedon Jul 20, 2020
Thanks for your feedback @iafan . I agree with you on most parts. If you are on discord, that could be useful that we chat before I start working on this feature
iafan commentedon Jul 20, 2020
@slorber Of course. I DM'ed you on Discord.
slorber commentedon Aug 20, 2020
Hey there. I'm closing this issue in favor of a new one: #3317
I'm working on i18n, and have already integrated a few feedbacks from this issue already.