translate-your-site.mdx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ---
  2. sidebar_position: 2
  3. ---
  4. # Translate your site
  5. Let's translate `docs/intro.md` to French.
  6. ## Configure i18n
  7. Modify `docusaurus.config.js` to add support for the `fr` locale:
  8. ```js title="docusaurus.config.js"
  9. export default {
  10. i18n: {
  11. defaultLocale: 'en',
  12. locales: ['en', 'fr'],
  13. },
  14. };
  15. ```
  16. ## Translate a doc
  17. Copy the `docs/intro.md` file to the `i18n/fr` folder:
  18. ```bash
  19. mkdir -p i18n/fr/docusaurus-plugin-content-docs/current/
  20. cp docs/intro.md i18n/fr/docusaurus-plugin-content-docs/current/intro.md
  21. ```
  22. Translate `i18n/fr/docusaurus-plugin-content-docs/current/intro.md` in French.
  23. ## Start your localized site
  24. Start your site on the French locale:
  25. ```bash
  26. npm run start -- --locale fr
  27. ```
  28. Your localized site is accessible at [http://localhost:3000/fr/](http://localhost:3000/fr/) and the `Getting Started` page is translated.
  29. :::caution
  30. In development, you can only use one locale at a time.
  31. :::
  32. ## Add a Locale Dropdown
  33. To navigate seamlessly across languages, add a locale dropdown.
  34. Modify the `docusaurus.config.js` file:
  35. ```js title="docusaurus.config.js"
  36. export default {
  37. themeConfig: {
  38. navbar: {
  39. items: [
  40. // highlight-start
  41. {
  42. type: 'localeDropdown',
  43. },
  44. // highlight-end
  45. ],
  46. },
  47. },
  48. };
  49. ```
  50. The locale dropdown now appears in your navbar:
  51. ![Locale Dropdown](./img/localeDropdown.png)
  52. ## Build your localized site
  53. Build your site for a specific locale:
  54. ```bash
  55. npm run build -- --locale fr
  56. ```
  57. Or build your site to include all the locales at once:
  58. ```bash
  59. npm run build
  60. ```