defaultContentLanguage for a specific module

Hi everyone,
hope your good :slight_smile:

I have a multilingual website: fr, en and es
My defaultContentLanguage is fr

I use a hugo module for a admin section, without translation, only i18n/en.yml file available for this module.

As I am in defaultContentLanguage fr it tries to find french translation (i18n/fr.yml) but it does not exist and unfortunately therefore does not fallback on the i18n/en.yml.
So I end up with empty texts.

Any idea?

Thanks a lot.

Seb

I18n translate falls back to the default language. Usually makes sense cause the default should be completely defined.

I could think of:

  • define all “admin” relevant english terms in the french one. Maybe using a prefix.

  • use a dedicated layout for your admin section without calls to translate

Hi @irkode,

so, I should duplicate i18n/en.yml in many languages like fr.yml, es.yml… to avoid this kind of problem.

Or else make it not use {{ i18n key }} in the admin module and write the texts in hard copy (therefore no longer translatable which is not great).

No other means?

Thanks
Seb

That’s not exactly what I said (or ment :wink:

You have a

  • default language let’s call it DEFAULT
  • other languages lets call them OTHER

if you use the translation with I18N

If you try to translate something in OTHER and that is not defined it will use DEFAULT.

That for me states:

  • the admin page for ALL languages is in english only
  • You don’t want to translate it

so for me that statement now does not make much sense:

IF you define all admin relevant texts (that might in future be translated) in the DEFAULT language. And don’t set them in any OTHER. Then all OTHER will use that DEFAULT because of the fallback.

Another option would be to handle the language switcher to always link to the english page.

I don’t think you can have different default language based on section/page level

I’ve done this before to handle situations where there may not be any i18n files yet:

{{ or (T "foo_key") "foo_value" }}

Be advised that if you do this:

hugo --printI18nWarnings

Hugo will emit a warning when the translation doesn’t exist, regardless of the fact that you’ve hardcoded a fallback value.

WARN  i18n|MISSING_TRANSLATION|en|foo_key

Related open issues :


There’s another approach using module mounts. In your site configuration:

[[module.mounts]]
source = 'i18n'
target = 'data/i18n'

Then in your templates:

{{ or (T "foo_key") site.Data.i18n.en.foo_key }}
1 Like

Hi @irkode @jmooring,

thank you for this precious time spent to answer me :slight_smile:

I like this way of doing {{ or (T "foo_key") "foo_value" }}, to secursise translation.

But I would find it interesting to have a defaultContentLanguage for a module or a theme. This would allow people who do not have a common defaultContentLanguage for their site to have a placeholder no matter what.

e.g: If I take the example of the Ananke theme and than my site is in Korean defaultContentLanguage, I will have empty texts.

Thanks,
Seb