howto multi-lingual site with Hexo
hexo is a nice & powerfull SSG(static site generator)
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.
1 | language: |
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.
1 | index: |
Templates
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:
en.yml
1 | <%= __('index.title') %> |
Path
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.
1 | 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:
1 | /index.html => en |
The string will only be served as a language when the language file exists. So archives in /archives/index.html will not get served as a language.