Spellcheck: Use full locale, otherwise all which match base

Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
automated-signal 2022-06-27 14:50:24 -07:00 committed by GitHub
parent 6686bd4ef8
commit ac23b6377a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 8 deletions

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)));
}

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', () => {