Requirements
- make English version of the contents those are in the original language (Japanese)
- to make them use a machine translation[^1]
- manually write an English contents if possible[^2]
^1: I need a hook that the machine translation is triggered in the build phase
^2: the build phase must distinguish the contents those are manually written to not override them by machine translation
Multilingualization on Hugo
Hugo automatically publishes multilingual sites by preparing a content file with the same name for each languages.
However it’s impossible to show the content in the original language when the translated content file doesn’t exist.
We have to implement such function ourselves.
https://gohugo.io/content-management/multilingual/#translate-your-content
Specification
- Prerequisite
- all contents exist on the original language (Japanese)
- some of them have manually translated but other are not
- automatically make an English translation of content - that is lacking a translation - during the build phase
- the tanslation runs in CI before Hugo builds html files
Implementation
The script (create_multilingual_contents.py) does:
- recursively looks up
xxx.ja-jp.md
files incontent/
directory - if the translation (
xxx.en.md
) does not exists, creates it and copies the original file contents
Operation
- all contents files in the original language are made with name
xxx.ja-jp.md
- if I translate a content by myself, create a file with name
xxx.en.md
- the CI takes care of the rest
TODO
- the operation doesn’t work on the local environment (it does work, but we have to remove the automatically created translations)