Display translation key instead of an empty string if the key has no translation

Can I force display the key instead of an empty string, if the key has no translation for some particular language? Currently I get an empty string if there is no translation in the i18n database.

If a translation is not found, I would like to have the fallback to display the translation taken from the “defaultContentLanguage”. If the translation in the “defaultContentLanguage” is not present, then display the key itself.

Is that possible?

I may suggest checking how it behaves in latest Hugo version (0.100.2) compared to 0.69.0.

You can use this construct:

{{ or (T "foo") "foo" }}

Try it:

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

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