The language code of the specified country does not match the I18N file

Such as ‘en-US’.

I have onfigured the language, But always empty after rendering {{ i18n "posts" }} or {{ T "posts" }}

Site config:

defaultContentLanguage: zh-CN

zh-CN.toml

[posts]
  other = "帖子"

Use {{ i18n "posts" }} in layout files, The result is empty. According to the document convention, this is the lack of translation.

After studying, I found a problem!

Here are two cases

Case can working

Site config:

defaultContentLanguage: en

en.toml:

[posts]
  other = "Posts"

Case can’t working

Site config:

defaultContentLanguage: en-US

en-US.toml:

[posts]
  other = "Posts"

I think it’s a bug and I hope it can be solved.


In addition, there is a small suggestion:
I18N files want to use YML and simplified syntax.
Such as

home: Home
posts: Posts

It’s much more convenient than the following grammar.

[home]
  other = "Home"
[posts]
  other = "Posts"

I understand that defaultContentLanguage should have only a language code, not a country code. It seems to be a feature, not a bug.

The same language varies less in different countries. So if I want to load the i18n/en-US.toml language package, how do I configure it?

Please try to rename i18n/en-US.toml to i18n/en.toml and set defaultContentLanguage: en. I think it will work. (v0.55.6)

Yes, it works, as I said above. But it didn’t solve my problem.

Hugo uses nicksnyder/go-i18n to deal with those configuration files. Your suggestion may be suggested by go-i18n.

And now, I found that the following config works with i18n/en-us.toml. Please try. Maybe, this feature allows only lower case letters.

defaultContentLanguage = "en-us"

Solve it! Thank you!

1 Like