i18next / i18next-express-middleware

[deprecated] can be replaced with i18next-http-middleware
https://github.com/i18next/i18next-http-middleware
MIT License
206 stars 52 forks source link

bug: language tags are case-sensitive #207

Open matchdav opened 4 years ago

matchdav commented 4 years ago

From the RFC spec

2.1.1. Formatting of Language Tags

At all times, language tags and their subtags, including private use and extensions, are to be treated as case insensitive: there exist conventions for the capitalization of some of the subtags, but these MUST NOT be taken to carry meaning.

Thus, the tag "mn-Cyrl-MN" is not distinct from "MN-cYRL-mn" or "mN- cYrL-Mn" (or any other combination), and each of these variations

So for example, eS should resolve to es

https://tools.ietf.org/html/rfc5646#section-2.1

I would submit a patch for this but I'm not sure where the final value is set

jamuhl commented 4 years ago

These conventions include:

o [ISO639-1] recommends that language codes be written in lowercase ('mn' Mongolian).

o [ISO15924] recommends that script codes use lowercase with the initial letter capitalized ('Cyrl' Cyrillic).

o [ISO3166-1] recommends that country codes be capitalized ('MN' Mongolia).

jamuhl commented 4 years ago

We enforce the ISO recommendations

matchdav commented 4 years ago

That doesn't make sense, you're not enforcing anything. No errors are thrown. It's silent failure.

In any case, the ISO is a recommendation whereas the above is a spec; the recommendation is for human readability, not how the headers are handled over the wire.

consistent formatting and presentation of language tags will aid users.

matchdav commented 4 years ago

This is basically my code should run even if it fails linting.

jamuhl commented 4 years ago

Seems we talk about different things...i18next gets something passed in as locale from a detector (I did not write them all myself - so not sure what you refer too) -> it uses that and reformats it to ISO recommendation -> further uses that to lookup paths in the backend (which needs some sort of agreed case sensitivity)...

so I'm not sure what you like to change? but I guess it's only the detector for header?!? That would mean to change the regex here https://github.com/i18next/i18next-express-middleware/blob/master/src/languageLookups/header.js#L16