2021-08-25 11:33:29 +00:00
+++
title = "Multilingual and i18n"
2023-11-28 22:52:24 +00:00
weight = 7
2021-08-25 11:33:29 +00:00
+++
2017-08-20 15:10:29 +00:00
2021-09-11 13:46:14 +00:00
The Relearn theme is fully compatible with Hugo multilingual mode.
2017-08-20 15:10:29 +00:00
2023-10-02 07:57:37 +00:00
- Available languages: Arabic, Simplified Chinese, Traditional Chinese, Czech, Dutch, English, Finnish, French, German, Hindi, Hungarian, Indonesian, Italian, Japanese, Korean, Polish, Portuguese, Russian, Spanish, Swahili, Turkish, Vietnamese. Feel free to contribute!
2023-02-09 23:34:47 +00:00
- Full support for languages written right to left
2017-08-20 15:10:29 +00:00
- Automatic menu generation from multilingual content
- In-browser language switching
2023-08-25 17:24:57 +00:00
![I18n menu ](i18n-menu.gif?width=18.75rem )
2017-08-20 15:10:29 +00:00
## Basic configuration
2023-11-29 23:14:22 +00:00
After learning [how Hugo handle multilingual websites ](https://gohugo.io/content-management/multilingual ), define your languages in your `hugo.toml` file.
2017-08-20 15:10:29 +00:00
2021-09-11 13:46:14 +00:00
For example with current English and Piratized English website.
2017-08-20 15:10:29 +00:00
2023-01-25 11:41:02 +00:00
{{% notice note %}}
2023-05-17 18:58:37 +00:00
Make sure your default language is defined as the first one in the `[languages]` array, as the theme needs to make assumptions on it
2023-01-25 11:41:02 +00:00
{{% /notice %}}
2024-03-02 10:04:52 +00:00
{{< multiconfig file = hugo > }}
2017-08-20 15:10:29 +00:00
defaultContentLanguage = "en"
2023-05-17 18:58:37 +00:00
[languages]
[languages.en]
2022-02-24 22:10:10 +00:00
title = "Hugo Relearn Theme"
2017-08-20 15:10:29 +00:00
weight = 1
languageName = "English"
2023-05-17 18:58:37 +00:00
[languages.pir]
2022-02-24 22:10:10 +00:00
title = "Cap'n Hugo Relearrrn Theme"
2017-08-20 15:10:29 +00:00
weight = 2
2021-09-11 13:46:14 +00:00
languageName = "Arrr! Pirrrates"
2024-03-02 10:04:52 +00:00
{{< / multiconfig > }}
2017-08-20 15:10:29 +00:00
2023-06-09 22:14:46 +00:00
Then, for each new page, append the _id_ of the language to the file.
2017-08-20 15:10:29 +00:00
- Single file `my-page.md` is split in two files:
2024-03-02 10:04:52 +00:00
- in English: `my-page.md`
- in Piratized English: `my-page.pir.md`
2017-08-20 15:10:29 +00:00
- Single file `_index.md` is split in two files:
2024-03-02 10:04:52 +00:00
- in English: `_index.md`
- in Piratized English: `_index.pir.md`
2017-08-20 15:10:29 +00:00
{{% notice info %}}
Be aware that only translated pages are displayed in menu. It's not replaced with default language content.
{{% /notice %}}
{{% notice tip %}}
2022-07-04 22:19:27 +00:00
Use [slug ](https://gohugo.io/content-management/multilingual/#translate-your-content ) frontmatter parameter to translate urls too.
2017-08-20 15:10:29 +00:00
{{% /notice %}}
2022-06-12 17:24:14 +00:00
## Search
In case each page's content is written in one single language only, the above configuration will already configure the site's search functionality correctly.
{{% notice warning %}}
2023-01-30 16:59:28 +00:00
Although the theme supports a wide variety of supported languages, the site's search via the [Lunr ](https://lunrjs.com ) search library does not.
2022-06-12 17:24:14 +00:00
You'll see error reports in your browsers console log for each unsupported language. Currently unsupported are:
2023-01-30 16:59:28 +00:00
- Czech
2022-06-12 17:24:14 +00:00
- Indonesian
- Polish
2023-10-02 07:57:37 +00:00
- Swahili
2022-06-12 17:24:14 +00:00
{{% /notice %}}
### Search with mixed language support
2023-11-29 23:14:22 +00:00
In case your page's content contains text in multiple languages (e.g. you are writing a Russian documentation for your english API), you can add those languages to your `hugo.toml` to broaden search.
2022-06-12 17:24:14 +00:00
2024-03-02 10:04:52 +00:00
{{< multiconfig file = hugo > }}
2022-06-12 17:24:14 +00:00
[params]
additionalContentLanguage = [ "en" ]
2024-03-02 10:04:52 +00:00
{{< / multiconfig > }}
2022-06-12 17:24:14 +00:00
As this is an array, you can add multiple additional languages.
{{% notice note %}}
2022-10-31 11:10:36 +00:00
Keep in mind that the language code required here, is the base language code. E.g. if you have additional content in `zh-CN` , you have to add just `zh` to this parameter.
2022-06-12 17:24:14 +00:00
{{% /notice %}}
2017-08-20 20:29:35 +00:00
## Overwrite translation strings
2017-08-20 15:10:29 +00:00
2023-06-09 22:14:46 +00:00
Translations strings are used for common default values used in the theme (_Edit_ button, _Search placeholder_ and so on). Translations are available in English and Piratized English but you may use another language or want to override default values.
2017-08-20 15:10:29 +00:00
2021-08-23 21:51:52 +00:00
To override these values, create a new file in your local i18n folder `i18n/<idlanguage>.toml` and inspire yourself from the theme `themes/hugo-theme-relearn/i18n/en.toml`
2017-08-20 15:10:29 +00:00
## Disable language switching
2021-08-23 21:51:52 +00:00
Switching the language in the browser is a great feature, but for some reasons you may want to disable it.
2017-08-20 15:10:29 +00:00
2023-11-29 23:14:22 +00:00
Just set `disableLanguageSwitchingButton=true` in your `hugo.toml`
2017-08-20 15:10:29 +00:00
2024-03-02 10:04:52 +00:00
{{< multiconfig file = hugo > }}
2017-08-20 15:10:29 +00:00
[params]
disableLanguageSwitchingButton = true
2024-03-02 10:04:52 +00:00
{{< / multiconfig > }}