Spellcheck: Use full locale, otherwise all which match base
Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
parent
6686bd4ef8
commit
ac23b6377a
|
@ -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)));
|
||||
}
|
||||
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
Loading…
Reference in New Issue