Internationalization (i18n)

You can use internationalization to present your site in different languages. The default language is set by modifying the language setting in _config.yml. You can also set multiple languages and modify the order of default languages.

language: zh-tw

- zh-tw
- en

Language Files

Language files can be YAML or JSON files. You should put them into the languages folder in the theme. There is support for the printf format in language files.


Use __ or _p helpers in templates to get the translated strings. The former is for normal usage and the latter is for plural strings. For example:

title: Home
add: Add
zero: No videos
one: One video
other: %d videos
<%= __('index.title') %>
// Home

<%= _p('', 3) %>
// 3 videos


You can set the language of pages in front-matter, or modify the i18n_dir setting in _config.yml to enable automatic detection by Hexo.

i18n_dir: :lang

The default value of i18n_dir setting is :lang, which means that Hexo will detect the language within the first segment of URL. For example:

/index.html => en
/archives/index.html => en
/zh-tw/index.html => zh-tw

The string will only be served as a language when the language file exists. So archives in /archives/index.html (example 2) will not get served as a language.