My last PR (#23) introduced a regression whereby two locales with the same language and country codes but a different separator ("-" vs. "_") would not correctly match. An example of how this can happen:
var userLocales = new locale.Locales(['en_US']);
var supportedLocales = new locale.Locales(['en', 'en-US']);
var bestLocale = userLocales.best(supportedLocales).toString(); // returns `en` instead of `en-US`
This happened because the best() method was matching locales based on their toString() values, which now returns the original code (instead of one always separated with an "_").
This PR fixes that bug by introducing a normalized attribute on the Locale specifically for use when matching locales using best(). In addition, I altered the index() method on Locales to map the locale code to the array index at which that Locale object is located in the supported locales array passed in to best() so that we could return the original Locale object passed in.
Let me know if you have any questions and sorry for the regression.
My last PR (#23) introduced a regression whereby two locales with the same language and country codes but a different separator ("-" vs. "_") would not correctly match. An example of how this can happen:
This happened because the
best()
method was matching locales based on theirtoString()
values, which now returns the original code (instead of one always separated with an "_").This PR fixes that bug by introducing a normalized attribute on the
Locale
specifically for use when matching locales usingbest()
. In addition, I altered theindex()
method onLocales
to map the locale code to the array index at which thatLocale
object is located in the supported locales array passed in tobest()
so that we could return the originalLocale
object passed in.Let me know if you have any questions and sorry for the regression.