florrain / locale

Browser locale negotiation for node.js
MIT License
257 stars 36 forks source link

best() choose locale en when it should pick locale en_GB #38

Open danielesegato opened 7 years ago

danielesegato commented 7 years ago

Using locale version 0.1.0.

Take this example:

// classic string from a browser with both en-us and en-gb
var locs = new Locale.Locales('it-it, it;q=0.9, en-us;q=0.8, en-gb;q=0.7, en;q=0.6')
var best = locs.best(new Locale.Locales('en-gb,en,fr,de', 'en'));
best.normalized

This print: en

I would have expected en_GB since it is in the list of supported languages and it has an higher score then en (0.7 vs 0.6).

locs:

{
  '0': 
   Locale {
     code: 'it-it',
     language: 'it',
     country: 'IT',
     normalized: 'it_IT',
     score: 1 },
  '1': Locale { code: 'it', language: 'it', normalized: 'it', score: 0.9 },
  '2': 
   Locale {
     code: 'en-us',
     language: 'en',
     country: 'US',
     normalized: 'en_US',
     score: 0.8 },
  '3': 
   Locale {
     code: 'en-gb',
     language: 'en',
     country: 'GB',
     normalized: 'en_GB',
     score: 0.7 },
  '4': Locale { code: 'en', language: 'en', normalized: 'en', score: 0.6 },
  length: 5 }

if I replace en-gb with en-us in the supported list I get en-us as expected