Spellcheck: Use full locale, otherwise all which match base

This commit is contained in:
Scott Nonnenberg authored and GitHub committed 2022-06-27 13:44:13 -07:00
1 parent 5d570e2d67
commit 054e443071
2 files changed
+5 -8

No files matched your search

+4 -6
View File
@@ -15,18 +15,16 @@ export function getLanguages(
userLocale: string,
availableLocales: ReadonlyArray<string>
): Array<string> {
const baseLocale = userLocale.split('-')[0];
// Attempt to find the exact locale
const candidateLocales = uniq([userLocale, baseLocale]).filter(l =>
// First attempt to find the exact locale
const candidateLocales = uniq([userLocale, userLocale]).filter(l =>
availableLocales.includes(l)
);
if (candidateLocales.length > 0) {
return candidateLocales;
}
// If no languages were found then just return all locales that start with the
// base
// If no languages were found then return all locales that start with the base
const baseLocale = userLocale.split('-')[0];
return uniq(availableLocales.filter(l => l.startsWith(baseLocale)));
}
+1 -2
View File
@@ -10,7 +10,6 @@ describe('SpellCheck', () => {
it('works with locale and base available', () => {
assert.deepEqual(getLanguages('en-US', ['en-US', 'en-CA', 'en']), [
'en-US',
'en',
]);
});
@@ -22,7 +21,7 @@ describe('SpellCheck', () => {
});
it('works with only base locale available', () => {
assert.deepEqual(getLanguages('en-US', ['en', 'en-CA']), ['en']);
assert.deepEqual(getLanguages('en-US', ['en', 'en-CA']), ['en', 'en-CA']);
});
it('works with only full locale available', () => {