Skip to content

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

Description

@danielesegato

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions