A Comprehensive Solution for Hexo i18n - Tutorial 2
It is quite difficult to create a multilingual (i18n) site for Hexo. However, in these two blogs I will provide you with a comprehensive solution for internationalization. The first tutorial creates a blog with a provided theme. The second tutorial explains how to creates a blog with a custom theme of your choice. You can go back to Tutorial 1 if you want a theme devoted to i18n (other themes may or may not support i18n).
This tutorial will guide you through creating an i18n Hexo blog using a theme of your choice. As for demostration, we will be using the popular theme “oranges”. However, you can modify these steps for any theme you prefer.
Step 1 - Installation
The first step is to install the required plugin and theme. Navigate to your blog’s folder and execute the following commands:
$ npm uninstall hexo-generator-index hexo-generator-archive hexo-generator-category hexo-generator-tag
$ npm install hexo-generator-plus --save
$ git clone https://github.com/zchengsite/hexo-theme-oranges.git themes/oranges
Step 2 - Setup
Change the theme to world in _config.yml
:
theme: oranges
Step 3 - Internationalization
Please follow these steps for internationalization
- Create a new folder for each language, and put all posts and pages in the corresponding folder. For example:
sources/
_posts/
en/
post1.md
post2.md
zh/
post3.md
post4.md
- Add the following to
_config.yml
:
generator_plus:
language: ['first language', 'second language']
- Change
new_post_name
variable in _config.yml tonew_post_name: :lang/:title.md
- Change
permalink
variable in _config.ymlpermalink: :lang/{what was here before}
Step 4 - Completion
Your blog setup is now complete! Run hexo g && hexo s
to view the results.
4.1 Theme Configuration
Follow the configuration for the “oranges” theme if you want (click here).
4.2 Generator Configuration
Here are additional options for generating the website. Merge the following code with the existing generator_plus
config (ie. remove the first line, and append it after generator_plus: language: ['first language', 'second language']
).
generator_plus:
pagination_dir: 'page'
index_generator:
per_page: 10
order_by: -date
archive_generator:
per_page: 10
order_by: -date
category_generator:
per_page: 10
order_by: -date
enable_index_page: false
tag_generator:
per_page: 10
order_by: -date
enable_index_page: false
Overall Options:
- pagination_dir: Pagination url.
- default: pagination_dir in original config, if not defined then
page
.
- default: pagination_dir in original config, if not defined then
For all generators:
- per_page: The number of posts/categories/tags displayed per page.
- default:
10
. 0
disables pagination
- default:
- order_by: The order of posts.
- default: date descending
For category_generator
and tag_generator
only:
- enable_index_page: Whether to generate the index page for categories and categories.
- default: false