10up / headstartwp

Build a headless website fast with WordPress, the world’s most popular CMS, and Next.js, the most popular React framework. A free and open source solution by the experts at 10up.
https://headstartwp.10up.com
159 stars 16 forks source link

With Polylang, error rendering pages in default language #844

Closed sambrodie closed 1 month ago

sambrodie commented 1 month ago

Describe the bug

When trying to view a page in the default language, the following error is thrown:

Error: Unsuported lang ([page slug]), make sure you add all desired locales to "config.i18n.locales"

For example if the page is /my-page, the error would be:

Error: Unsuported lang (my-page), make sure you add all desired locales to "config.i18n.locales"

Steps to Reproduce

  1. Install Polylang
  2. And English and at least 1 other language, and set English to the default language
  3. Create an English page
  4. View the English page

Screenshots, screen recording, code snippet

Languages: https://share.zight.com/p9uoRBgN Error: https://share.zight.com/12ujpbBe

Environment information

No response

WordPress information

No response

Code of Conduct

sambrodie commented 1 month ago

Intl.getCanonicalLocales() has some really weird idiosyncrasies. If you pass it a string that begins with 4 letters followed by a non-letter character, it will produce an error. But if you pass a string that begins with 5 or 6 characters, for example, it won’t. So:

So ultimately we can’t rely on Intl.getCanonicalLocales(). Unfortunately, if we want to validate that string as a locale, and assume that the string can be any valid locale, it looks like we may have to use a library of all existing locales to compare it to.

Do we need validation for any possibly valid locale?

sambrodie commented 1 month ago

Could possibly use this: https://github.com/validatorjs/validator.js/blob/master/src/lib/isISO6391.js

But since that list isn't static, it would have to be maintained.