Missing / empty fallback translations

Hello. I’ve spent 2 days trying to fix this, would really appreciate a fresh pair of eyes please and thank you.

I have in my config

defaultContentLanguage: en-au


    - en-au


        languageCode: en-au
        languageName: Australia
        contentDir: content/en-au
        languageCode: es
        languageName: Spain
        contentDir: content/es

I have a data file in i18n/en-au.json which contains

    "home": {
        "beacon": "gday"

The data file i18n/es.json does not contain this key.

In my template I have:

    {{ $headline := i18n "home.beacon" }}
    <h1>{{ $headline }}</h1>

When I view the site in en-au I can see the value. When I view it in Spanish, I get an empty string. No fallback.

If I add enableMissingTranslationPlaceholders: true to my config I get [i18n] home.beacon as the displayed value, its not falling back.

Can anyone unscramble me and advise on this, would really appreciate it. Thank you.

This isn’t a core config setting. Is this something specific to your theme?

You are running into this bug:

Hugo doesn’t fallback to i18n/<defaultContentLanguage>.<toml/yaml/json>.

It falls back to i18n/en.<toml/yaml/json>.


This was something that someone suggested, a hail mary if you will.

You are running into this bug:

While bugs aren’t great, now I know about it I can deal with it, thank you.

So I made an en.json file and put:

    "home": {
        "beacon": "HELLO"

I was expecting to see HELLO appear when I viewed Spanish but it didn’t work. Are there any other magic switches I’d need to toggle? Thank you.

I am unable to reproduce the behavior as described.

Try it:

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

Thanks for the demo code, I’ll take a look, thank you.

@jmooring - your code works as expected, I’ve tried to line mine up exactly the same but its still not falling back. Its like it can’t find en.json. Thanks for doing the PR.

Without seeing the project it’s difficult to say why this is happening.

1 Like