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