I am starting to localize our website to German with the help of a translator. The site is all in English at the moment. Given that we have a default language, I thought Hugo would fill in any missing translated pages with the content from the default language. But instead, it seems like I get a lot of ‘missing reference’ errors if I don’t make a copy of every content file to the new language I am adding. So if I have translations for 2-3 of our page bundles, I can put those in, but I thought Hugo would allow more incremental translations of the page bundles.
See https://gohugo.io/functions/lang.merge. This is for filling in gaps when you are iterating (ranging) through a collection of pages (e.g., on a list page).
2. Mount the en directory on top of the de directory
structure
content/
├── de/
│ ├── _index.md
│ └── test-1.md <-- Note that test-2.md and test-3.md are not present
└── en/
├── _index.md
├── test-1.md
├── test-2.md
└── test-3.md
config.toml
[languages.en]
weight = 1
[languages.de]
weight = 2
# EN content
[[module.mounts]]
source = 'content/en'
target = 'content'
lang = 'en'
# DE content
[[module.mounts]]
source = 'content/de'
target = 'content'
lang = 'de'
# This fills in the gaps in DE content with EN content
[[module.mounts]]
source = 'content/en'
target = 'content'
lang = 'de'
git clone --single-branch -b hugo-forum-topic-37225 https://github.com/jmooring/hugo-testing hugo-forum-topic-37225
cd hugo-forum-topic-37225
hugo server
thank you - this was a very helpful example! We had a problem on our site where the [module.mounts] sections needed to be reordered to put the EN content at the end, otherwise the english site didn’t get any content. I’m not able to reproduce that issue on your small test repo though. I thought I would make a note of it in case anyone else finds this topic through search.
Second issue, which I can reproduce on the test repo - the home page isn’t picking up the translated content. I always see the ‘en’ content, even for ‘de’ or ‘nl’. When I go to localhost:1313/de i still see the “(en)” in the page that is rendered, even though de/_index.md exists. Do you know how to work around that?
Thanks to @bep’s work over the weekend, using mounts to fill in missing translations now works with two or more languages.
Notes:
1) The functionality will be available in the next release. Or, if you can build from source, it’s available now.
2) In site configuration, you can configure all your language mounts first, then configure the overrides. For example:
config.toml
#------------------------------------------------------------------------------
# Languages
#------------------------------------------------------------------------------
[languages.en]
languageName = 'English'
weight = 1
[languages.de]
languageName = 'Deutsch'
weight = 2
[languages.nl]
languageName = 'Nederlands'
weight = 3
#------------------------------------------------------------------------------
# Content mounts
#------------------------------------------------------------------------------
# EN content
[[module.mounts]]
source = 'content/en'
target = 'content'
lang = 'en'
# DE content
[[module.mounts]]
source = 'content/de'
target = 'content'
lang = 'de'
# NL content
[[module.mounts]]
source = 'content/nl'
target = 'content'
lang = 'nl'
#------------------------------------------------------------------------------
# Fill in the missing translations
#------------------------------------------------------------------------------
# This fills in the gaps in DE content with EN content
[[module.mounts]]
source = 'content/en'
target = 'content'
lang = 'de'
# This fills in the gaps in NL content with EN content.
[[module.mounts]]
source = 'content/en'
target = 'content'
lang = 'nl'
3) I have pushed changes to the test site we’ve been working with. It now includes a fourth language (es, without a content directory). Please take it for a spin once you have updated or compiled Hugo.
git clone --single-branch -b hugo-forum-topic-37225 https://github.com/jmooring/hugo-testing hugo-forum-topic-37225
cd hugo-forum-topic-37225
hugo server