akoenig/express-lingua — Issue #3: Lingua is too naive when parsing the Accept-Language header
Author: homme
Created: 2011-10-20 15:21:14+00:00
State: open

Firstly, thanks for providing lingua - apart from this issue it's just what I need!

Regarding the issue, take the following Accept-Language header value: 'en-gb;q=0.8,en-us;q=0.5,en;q=0.3'. Currently lingua extracts 'en-gb' as the locale. This is fine if I have a lingua resource for the 'en-gb' locale but imagine I only have a lingua resource with 'en-us', or more likely simply 'en'. In the latter two cases the lingua will currently use the default locale which I consider a bug. Instead I think lingua should be make a locale choice based on the full header value. This means ordering the language tags by qvalue in case more than one tag matches a resource (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4).

In addition it would be useful if lingua could also extract the primary subtags (i.e. the 'en' in 'en-gb') and match them against a resource (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.10).

I'll attempt to provide a patch for this functionality.