Is it possible to make language key to be differenced with locale name?

Since v0.87.0, Hugo brings a new feature of localizing time and dates. I gave it a shot, but it seems that need to keep the language key to be equaled to the locale name.
So I’m wondering whether is it possible to make language key to be differenced with locale name?

In order to localize time, customize the key of language which appear in the URL(zh-cn, zh-tw).

Details:

languags.toml

[zh-cn]
  languageName = "简体中文"
  weight = 4
  contentDir = "content/zh-cn"

[zh-hans]
  languageName = "zh-hans"
  weight = 4
  contentDir = "content/zh-hans"

[zh_hans]
  languageName = "zh_hans"
  weight = 4
  contentDir = "content/zh_hans"

The zh_hans works as excepted, the rest of languages are not working.

partial:

{{ .Date | time.Format ":date_full" }}

I also take a close look at the source code, Hugo uses the language key for getting a translator and locale, but I’m not sure that.

I think you can’t use - in language key, Try this

[cn]
  languageName = "简体中文"
  weight = 4
  contentDir = "content/zh-cn"

[hans]
  languageName = "zh-hans"
  weight = 4
  contentDir = "content/zh-hans"

@Mehedi No, that won’t work. This issue is about matching the locales defined by https://github.com/gohugoio/locales.

2 Likes

@Mehedi Thanks for replying, as jmooring said, the issue is about matching the locale name and language key.

1 Like