-
Notifications
You must be signed in to change notification settings - Fork 2
Conversation
index.js
Outdated
@@ -88,6 +90,14 @@ function parseLocaleIntoCodes (locale) { | |||
}; | |||
} | |||
|
|||
function handleDeprecatedLocales(language) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“Handle” isn’t a useful word to put in a function name. How about getStandardLanguage()
?
lib/deprecated-locales.js
Outdated
@@ -0,0 +1,10 @@ | |||
module.exports = [{ | |||
previously: 'iw', | |||
current: 'he' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn’t need to be an array of objects. A simple object mapping deprecated codes to standard codes would do. If we need to attach more information to each entry in the future, we can use nested objects again. But for now it just makes getStandardLanguage()
more complicated and less performant.
@@ -22,6 +25,11 @@ tape('test bestMatchingLocale', function(t) { | |||
t.equal(locale.bestMatchingLocale('es-mx', availableLocales), 'es'); | |||
t.equal(locale.bestMatchingLocale('zh-Hans-region', availableLocales), 'zh-Hans'); | |||
t.equal(locale.bestMatchingLocale('pt-BR', availableLocales), 'pt-PT'); | |||
|
|||
t.equal(locale.bestMatchingLocale('iw', availableLocales), 'he', 'Test deprecated locale'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test case for a deprecated language plus a country code, such as iw-IL
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Closes: #4
This handles older, deprecated locales by inspecting the language component of a locale and seeing if it is one of the deprecated locales. If it is, the current locale is returned instead.
/cc @danpaz @1ec5