Implementing multilingual in Hexo
Comment | 0ViewI want to do my multilingual site in a sudden, so I search for the simple and appropriate way to achieve that but I failed. However in Mr.SaltyLeo’s blog I found this particular article Hexo adds multi-language support「internationalized i18n」, and figure it out.
The idea is simple. First, using hexo to generate my main-lang site, then generate the sub-lang site. Third, copy the generated-sub-resource-folder to main-resourece-folder, and deploy it! That’all.
For example, I created my en
folder to hold my sub-lang site content. Then I copy all the files & folders except the one in .gitignore
in the original folder to this folder, and there is what I’ve done after.
First: Modifying config to genereate each sites
There is just a little to edit with config files. Since my choice of hexo’s theme is maupassant
and what I’ve to do is to add a entrance(as you can see in the up-right corner of this page) of another multilingual-site. I need to add a config to each _config.yml
files in each theme folder:
1 | menu: |
finally, we should modify the right path to our new lang-site. Going to the Hexo’s config file(NOT THEME) and change these three attributes:
1 | language: en # original zh-CN |
Second: Creating script to generating blog files automatically
Content is the essential part to our blog. After we finished the config part, we should think about in what way we make our file?
I used to use hexo’s command to help me generating article.
1 | hexo new article-name |
However, in our new circumstance we should use that command twice! No one wants that. So the first thought came to my mind was creating a new command that do it for me. That’s why I write this js file:
1 | const { exec } = require("child_process"); |
and give it a npm script to run. Now I can use
1 | npm run create article-name |
to generate files automatically for me.(This blog was generated by the method BTW.)
Now you have your config & articles ready, the next step is to
Deploy
The process is simple
Generate main-site > Generate sub-site > copy sub-site to main-site > deploy
But I’m using Windows now, so there was no shell for me to save my time. Node’s fs module is my only savior.
So I write this js file to do the copy and deploy for me:
1 | const { exec } = require("child_process"); |
and give it a npm script, now I can use
1 | npm run d(eploy) |
to deploy my blog!
Hope you enjoy it.
- Blog Link: https://blog.decay.fun/en/2019/08/21/implementing-multilingual-in-hexo/
- Copyright Declaration: The author owns the copyright. Please indicate the source reproduced!
Share用中文浏览本文