An example of how to make a multilingual site with Hugo, the super-fast static website generator.
Hugo has had support for multilingual content since version 0.17. Hugo's multilingual mode has good documentation, but sometimes it can be helpful to see an example. This repository shows a common configuration for making a multilingual site with Hugo.
Another purpose of this repository is for testing Hugo themes. All Hugo themes are not created equal with regard to internationalisation (i18n); in fact most just hard-code the English strings into the HTML templates, making multilingual sites impossible. Using such themes with this example should make it easier to see what they need to change to implement good i18n.
To see how this repository looks with a certain theme, clone it, then clone the theme into a subdirectory of the themes
directory.
$ git clone https://github.com/rayjolt/hugo-multilingual-example.git
$ cd hugo-multilingual-example
$ git clone https://github.com/example/some-hugo-theme.git themes/some-hugo-theme
You can then test the site using Hugo's built-in server.
$ hugo server -t some-hugo-theme
The master
branch contains content and configuration for three languages. If you want to use only two languages, you can check out the bilingual
branch.
$ git checkout bilingual
Things to do when making a theme i18n-ready:
- Move all hard-coded strings to i18n files.
- Add a language switcher to the site navigation.
- Make all links in templates language-relative.
- Add links to translated content.
- Set the correct
lang
attribute on thehtml
element. - Set
lang
attributes for any content that is not in the page's default language, e.g. links in the language switcher. - For languages with right-to-left (RTL) scripts, add
dir="rtl"
to thehtml
element. (Note: as of April 2017, this is not well-supported in Hugo.) - Flip the CSS for RTL scripts.