English
This website implements quarto with 2 languages. Currently, you are looking at the english version.
To use multi language support, I make use of quarto profiles. Some ideas are from here.
Current approach
- Create profiles for each language:
en/de. Each has its own YAML file:_quarto-en.ymlandquarto-de.yml. In these yaml files, specify the language and the menu items for each language:
quarto-en.yml"
lang: en
website:
navbar:
left:
- href: index.qmd
text: Home
- href: about.qmd
text: "About"
title: "Multi-languages Websites with Quarto!"quarto-en.yml"
website:
navbar:
left:
- href: index.qmd
text: Home
- href: about.qmd
text: "Infos"
title: "Mehrsprachige Websiten mit Quarto!"- Specify a default profile using groups. The default language is rendered to
docs, the other language is rendered to a subdir ofdocs. Add a navbar item (right) to switch to the other language
quarto-en.yml"
project:
output-dir: docs
website:
navbar:
right:
- href: de
text: 🌍 Auf Deutsch wechselnquarto-en.yml"
project:
output-dir: docs/de
website:
navbar:
right:
- href: ../
text: 🌍 Switch to English- Conditionally show content on each page using divs with the
.content-visible when-profile="de"syntax
:::{.content-visible when-profile="de"}
## Deutsch
Diese Website implementiert quarto mit 2 Sprachen. Derzeit sehen Sie die deutsche Version. Wie das ganze funktioniert ist nur in der englischen Version sichtbar.
:::- To render:
- If possible, render the default profile first (
quarto render) and the other second (e.g.quarto render --profile de) - If you need to render the other language first, use
--no-clean(quarto render --profile de --no-clean) to prefentdocsfrom being purged first
- If possible, render the default profile first (
- To publish
- We cannot use
quarto publish, since this is this command isoutput-dir-aware. Instead, we specifydocsto be the source forgh-pageson GitHub. The disadvantage is that you need to versioncontrol your html-files. - Netlify would be an elegant solution with some overhead (create an netlify account, install the netlify-cli). Here you have the additional advantage of being able to use
_redirectsdepending on the preferred user language in the browser settings.
- We cannot use
Note
Anything not in a conditional div is displayed in both language versions (like this callout block you are reading right now)