Introduction
As I consume more information, I often find the need to write articles in other languages (especially since modern projects are almost always multilingual). Ever since I added i18n support to my graduation project, I’ve wanted it for everything I design or build. Even my recent practice project includes multilingual support (though that one is a bit dated; I’m working on a more modern version now).
Looking back at my blog—the project I’ve maintained the longest—it still lacked internationalization. While I mostly write in Simplified Chinese, my previous blog was a messy mix of Chinese and English in the UI. It worked for me, but it was likely confusing for others.
I tried setting up multilingual support in Jekyll but never quite got it right, so I switched to Hugo, which supports it natively. Every theme has its quirks, and this theme’s approach to categories and tags differs significantly from my previous one, so I’ll need time to adapt. This post is a bit rough because the configuration seems heavily theme-dependent, and the official documentation is already quite comprehensive.
Environment
I’m using Hugo via Docker, so I didn’t have to mess with local environment issues. You can see my setup here .
Creating the Blog
Create a new blog:
| |
Enter the directory:
| |
Initialize the repository:
| |
Install a theme. I’m using hugo-theme-stack , but the process is similar for others:
| |
Configure hugo.toml to use the theme:
| |
Preview:
| |
Preview including drafts:
| |
Some changes (like configuration or page structure) might require clearing the cache:
| |
Build the site (output defaults to the public directory):
| |
Multilingual Support
In your site configuration file (I use YAML), set the default language:
| |
Then define the specific language settings:
| |
Font Internationalization: https://blog.yexca.net/archives/240
Writing Articles
Unlike Jekyll, Hugo’s article structure is slightly more complex. Adding i18n makes it even more so, though this allows for high customization. This may vary by theme. In my case, the language configuration points to specific directories under content.
You can specify which directories contain your main content in the stack theme configuration:
| |
This means my Simplified Chinese posts should be in content/zh-cn/posts. Other directories are theme-specific; check your theme’s example site for details.
To create a new Simplified Chinese post:
| |
If you don’t specify a timezone, it defaults to UTC. Coming from Jekyll, I find manually writing the timestamp a bit tedious.
Default post templates are located in blogName/archetypes and can be converted to YAML format.