i18n - Using git
A possible translation strategy is to version control the translation files to Git (or any other VCS).
#
TradeoffsThis strategy has advantages:
- Easy to get started: just add the
i18n
folder to Git - Easy for developers: Git, GitHub and pull-requests are mainstream developer tools
- Free (or without any additional cost, assuming you already use Git)
- Low friction: does not require signing-up to an external tool
- Rewarding: contributors are happy to have a nice contribution history
Using Git also present some shortcomings:
- Hard for non-developers: they do not master Git and pull-requests
- Hard for professional translations: they are used to SaaS translation softwares and advanced features
- Hard to maintain: you have to keep the translated files in sync with the untranslated files
note
Some large-scale technical projects (ReactJS, VueJS, Gatsby, TypeScript, Nuxt...) use Git for translations.
Refer to the Docusaurus i18n RFC for our notes and links studying these systems.
#
Git tutorialThis is a walk-through of using Git to translate a newly initialized English Docusaurus website into French, and assume you already followed the i18n tutorial.
#
Prepare the Docusaurus siteInitialize a new Docusaurus site:
Add the site configuration for the French language:
Translate the homepage:
i18n
folder#
Initialize the Use the write-translations CLI command to initialize the JSON translation files for the French locale:
- npm
- Yarn
tip
Use the --messagePrefix '(fr) '
option to make the untranslated strings stand out.
Hello
will appear as (fr) Hello
and makes it clear a translation is missing.
Copy your untranslated Markdown files to the French folder:
Add all these files to Git.
#
Translate the filesTranslate the Markdown and JSON files in i18n/fr
and commit the translation.
You should now be able to start your site in French and see the translations:
- npm
- Yarn
You can also build the site locally or on your CI:
- npm
- Yarn
#
RepeatFollow the same process for each locale you need to support.
#
Maintain the translationsKeeping translated files consistent with the originals can be challenging, in particular for Markdown documents.
#
Markdown translationsWhen an untranslated Markdown document is edited, it is your responsibility to maintain the respective translated files, and we unfortunately don't have a good way to help you do so.
To keep your translated sites consistent, when the website/docs/doc1.md
doc is edited, you need backport these edits to i18n/fr/docusaurus-plugin-content-docs/current/doc1.md
.
#
JSON translationsTo help you maintain the JSON translation files, it is possible to run again the write-translations CLI command:
- npm
- Yarn
New translation will be appended, and existing ones will not be overridden.
tip
Reset your translations with the --override
option.