kiwirafe.blog

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

  1. 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
  1. Add the following to _config.yml:
generator_plus:
  language: ['first language', 'second language']
  1. Change new_post_name variable in _config.yml to new_post_name: :lang/:title.md
  2. Change permalink variable in _config.yml permalink: :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:

For all generators:

For category_generator and tag_generator only: