This article mainly discusses how Hexo achieves internationalization in the simplest way, and this method is highly applicable. I personally think that there is no requirement for which theme to use.

Ideal Solution

There is a button on the home page, by clicking this button, you can switch the language page with one click (the example of this blog will be Chinese and English). At the same time, the realization of this method does not need to buy a new domain name.

It is worth noting that this method is not a direct translation, so you need to maintain N blog files of the post at the same time (N is the number of your languages), so if you need to update the blog, you need to update N files at the same time.

The following implementation process will use Chinese and English as examples. For more languages, please refer to this tutorial:

Implementation Process

(1)Divide the page folder, assuming that your original files are stored in a folder called hexo, which mainly stores Chinese files. Now create a new folder called hexo-en to store the English folder. Note: they are siblings!

The built folder should be as follows:

文件夹位置展示

(2) Copy all files except node_modules from hexo to hexoen, separate the site

(3) Next, modify the contents of the _config.yml files of the two hexo files. The first one in the figure below is hexo, and the second one is hexo-en: (this step is to modify the main language of website)

hexo

hexo-en

(4) Continue to modify the root directory url and root of _config.yml, the first one in the figure below is hexo, and the second one is hexo-en:

hexo

hexo-en

(5) Modify the jump link of your own menu corresponding to the theme. Note that there is a hint here—**You can jump to the link of your own github.io/en, and you can also jump to the link of your own domain name/en . I don’t know why the jump to github.io failed here, and 404 was displayed, but the jump to the domain name thellu.com/en succeeded. **You can choose the jump address according to your actual situation.

In addition, note that if you have a Chinese homepage, the menu should be set to English; if you are an English homepage, the menu should be set to Chinese.

The first picture below is hexo, and the second one is hexo-en:

hexo

hexo-en

(6) Congratulations, the basic configuration is now complete! Now execute npm install in the hexoen folder to install the required plugins.

(7) Finally, modify the command that you submit files to github every time, you need to use cp to merge and submit files every time. I am using an absolute path here, so it is convenient to modify the address when cd path:

1
cd /d/Blog/hexo && hexo clean && hexo g && cd /d/Blog/hexoen && hexo clean && hexo g && cd /d/Blog/hexo && cp -r /d/Blog/hexoen/public/. /d/Blog/hexo/public/en/ && hexo d

(8) Congratulations, the configuration is now complete! You can check to see if your website has successfully redirected the page. The only downside is that clicking will jump to a new page instead of updating the old one.

Common Error

When uploading with the above code after writing the md file normally, sometimes an error will be reported inexplicably:

err : Error: Spawn Failed

The problem usually occurs in the .deploy_git folder, which is a Git repository generated by the hexo framework rendering. The hexo d command is to push it to github. Most of the problems are caused by git changing the contents of some .deploy_git files when pushing or hexo d, resulting in an error.

All in all, just delete this file.

Then call the following command:

1
git config --global core.autocrlf false

Then execute the clean g d command of hexo.

But note that there are two other reasons for this error:

  • Our submission to github code uses absolute path. If you open git bash in hexoen, the .deploy_git file may be saved in the hexoen folder. Remember to delete it at this time.
  • Network fluctuations, delete .deploy_git and wait for a while for it to be fine