Skip to content

Internationalization ​

From v1.2.0, H2O-ac supports internationalization, which can be controlled by site and page level.

Field data ​

All field data for internationalization are stored in /_data/locales/. The files are named with the common languages as follows:

FilenameLanguage
zh-Hans.ymlSimiplied Chinese
zh-Hant.ymlTraditional Chinese
en.ymlEnglish
ja.ymlJapanese

The supported fields mainly includes cover, panel, footer, post, archives, categories and langs. Please refer to Source Code for more details.

Site config ​

It's recommended to enable all possible languages and set the most used language for posts to default language.

yaml
languages: ['zh-Hans', 'zh-Hant', 'en', 'ja']  # The internationalization list
default_lang: 'zh-Hans'  # Default language

If you want to write a post or page with a non-default language, please define the language used in meta information of the post or the page. The following is an example with English:

yaml
lang: en

If one post or page has more than one language version, you can define them in meta information to info readers like below:

yaml
langs: [en, zh-Hans]

o0COTW.webp

Because the page with different languages will be generated automatically, the urls for different languages have to follow the rules. Otherwise, a 404 error will happen.

For example, the homepage of default language is /index.html:

  • If Simplied Chinese is the default language, the homepage with English will be /en/index.html. The homepage with Traditional Chinese will be /zh-Hant/index.html.
  • If English is the default language, the homepage with Simplied Chinese will be /zh-Hans/index.html.

WARNING

  • The pages with the default language could not be accessed with subdirectory!!!
  • If the language used in post or page is not listed in site.languages, a 404 error will happen.

Released under the MIT License.