Do all page bundles need localized copies once you add a new language?

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.

I wanted to check if I understand this correctly.

There are two approaches that I can think of.

1. Use lang.Merge

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'

And when you build the site…

public/
├── de/
│   ├── test-1/
│   │   └── index.html
│   ├── test-2/
│   │   └── index.html
│   ├── test-3/
│   │   └── index.html
│   └── index.html
├── en/
│   ├── test-1/
│   │   └── index.html
│   ├── test-2/
│   │   └── index.html
│   ├── test-3/
│   │   └── index.html
│   └── index.html
└── index.html

Try it:

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
6 Likes

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?

I cannot reproduce that behavior with the test site posted above.

When I visit http://localhost:1313/de/ this is what I see:

Notice the (de) in the site title.

Also, the test site was not configured with a nl language, so perhaps you changed something.

Sorry for not providing the code - i generalized the two language case to 3. I’ve put it on github here: GitHub - mdonohue/hugo-testing at hugo-forum-topic-37225

I also updated to hugo 0.95 to make sure my older version wasn’t the culprit. The problem still persists for me

hugo version

hugo v0.95.0-9F2E76AF darwin/amd64 BuildDate=2022-03-16T14:20:19Z VendorInfo=gohugoio

:white_check_mark: Two languages, using the first language to fill in the missing translations in the second language

:white_check_mark: Thee languages, using the first language to fill in the missing translations in the second language

:x: Thee languages, using the first language to fill in the missing translations in the other two languages

I’ve update the test site. To make it fail, uncomment the last block in config.toml.

git clone --single-branch -b hugo-forum-topic-37225 https://github.com/jmooring/hugo-testing hugo-forum-topic-37225
cd hugo-forum-topic-37225

This approach may not be possible with three or more languages, but I’d really like another set of eyes on it. Sorry to do this, but… @bep.

If there’s a way to make this work it would save a lot of time.

1 Like

:slight_smile:

What do you mean by “fail”?

Point taken. It doesn’t fail.

It just isn’t doing what I would like it to do, and my expectation/desire may be unrealistic.

If I uncomment the last block in config.toml, and then visit http://localhost:1313/nl/, what I get is:

Test 1 (en)
Test 2 (en)
Test 3 (en)

What I want is:

Test 1 (nl)
Test 2 (en)
Test 3 (nl)

I am trying to use mounts to fill in missing translations, essentially trying to accomplish what is suggested in #9195.

No, your expectations matches mine, so this is a bug. A little bit of a puzzling bug, but I suspect an easy fix. Can you create a GH issue?

2 Likes

https://github.com/gohugoio/hugo/issues/9693

1 Like

@mdonohue

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
11 Likes

Nice work :clap:

this really helped solve the previous pain point Multilingual, Multi country, multi currency, Multi-domain support

where I have to add content for each language while the only difference being the date and currency. for example in English American and English UK

So now I can use 1 content directory en and only modify the parts of the page and use it in en-us en-gb etc.

well done :+1:

1 Like

Thank you! With the 0.96 release of Hugo we are now able to handle incremental translation updates without a lot of file copying.

1 Like

A post was split to a new topic: Question about filling in translation gaps

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.