getzola / zola

A fast static site generator in a single binary with everything built-in. https://www.getzola.org
https://www.getzola.org
MIT License
13.99k stars 964 forks source link

Zola is validating language incorrectly #2169

Open pickfire opened 1 year ago

pickfire commented 1 year ago

Bug Report

Environment

Zola version: 0.17.2

Expected Behavior

zh-CN should not be valid language and should be suggested to use zh-Hans-CN or zh-Hans instead. I have seen zh-CN quite often in quite a few sites since it renders differently if it is done incorrectly and less readable.

Current Behavior

zh-CN passed language validation check since it uses unic-langid but is not recognized by browser, it should instead use zh-Hans which is specified by https://datatracker.ietf.org/doc/html/rfc5646#appendix-A and https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang.

I filled an issue to hexo too https://github.com/hexojs/hexo/issues/5186.

Step to reproduce

  1. Install a theme (I didn't expect to have to install a theme just to test this out, and the first that I installed even broke, I almost want to ignore writing this issue)
  2. Set default_language = "zh-CN" in config.toml.
Keats commented 1 year ago

Do you know a crate that validates language code for the browser?

pyfisch commented 1 year ago

Both tags are valid, for a static site generator it might be useful to suggest adding a script to certain language codes.

pickfire commented 1 year ago

Let me investigate on this, I think I need to check what needs to be done and if needed probably a separate crate will be done.

jonassmedegaard commented 1 year ago

Looks like the crate language-tags does exactly what is needed here.

jonassmedegaard commented 1 year ago

Another crate seemingly doing exactly what is needed here is fluent-langneg, also given that zola might use Fluent in future.

Keats commented 1 year ago

fluent-langneg sounds like a good solution