kiwirafe.blog

A Comprehensive Solution for Hexo i18n - Tutorial 1

It is quite difficult to create a multilingual (i18n) site for Hexo. However, in the following 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 jump straight to Tutorial 2 if you want a customized theme.

This tutorial will guide you through creating an i18n Hexo blog using the “world” theme. The “world” theme is a theme devoted to i18n - meaning it fully supports a multilingual site. You can find a demo here.

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/kiwirafe/hexo-theme-world.git themes/world

Step 2 - Setup

Change the theme to world in _config.yml:

theme: world

and turn off syntax highlighter (the theme uses customized CDN instead):

syntax_highlighter: 

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. Copy the content from theme/world/_config.world.yml into your main _config.yml file. This file is the exact same as the default config file, expect a few changes to support i18n.

  2. At the right end of your _config.yml file and change the language settings if needed:

generator_plus:
  language: ['first language', 'second language']

Step 4 - Completion

Your blog setup is now complete! Run hexo g && hexo s to view the results.

4.1 Writing

This theme supports categories and categories. All you have to do is add the following to front-matter:

category: "My Category"
tag: "My Tag"

This theme also supports Mathjax:

mathjax: true

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: