hugo-theme-stack-starter icon indicating copy to clipboard operation
hugo-theme-stack-starter copied to clipboard

zh-cn date format not localized

Open CarlossShi opened this issue 2 months ago • 1 comments

  • hugo version: extended_0.152.2
  • stack version: v3.31.0

The date shown in https://dev.stack.jimmycai.com/ar is correctly localized as مارس 09, 2019. However, the date in https://dev.stack.jimmycai.com/zh-cn is shown as Sep 09, 2020, which is expected to be 2020年9月9日.

For my Cloudflare deployment, I've checked https://github.com/CaiJimmy/hugo-theme-stack/issues/1040, and add modified details.html and footer.html to layouts/partials/article/components under template folder, but the zh-cn date localization remains unfixed.

Any help would be greatly appreciated.

CarlossShi avatar Oct 31 '25 03:10 CarlossShi

Thank you for raising this issue.

This problem is actually very difficult to solve. The theme used zh-cn for the Chinese (Simplified) translation. However, this language code does not adhere to the syntax described in RFC 5646, which is zh.

Hugo's date translation relies on the language code being valid. You can view the translation file used by Hugo here: https://github.com/gohugoio/locales/tree/master/zh.

This issue affects not only zh-cn but also zh-hk, for example, which should be zh_Hans_HK.

The problem with Hugo's i18n is that it uses the language key to populate the folder. This change will therefore modify the URL of all pages associated with that language in multilingual mode and also affect the filenames of Markdown files (e.g. changing index.zh-cn.md to index.zh.md).

I haven't found a way to get around this. The final solution would therefore be to change the names of all files in the i18n folder to adhere to the rule.

If you are using a single language, this should not be a problem. As a quick fix, create an 'i18n' folder, copy i18n/zh-cn.yaml from the theme and rename it i18n/zh.yaml, then change the language from zh-cn to zh.

CaiJimmy avatar Nov 01 '25 20:11 CaiJimmy