Commit 32b56ba0 authored by Moody Salem's avatar Moody Salem

just pick the first occurrence of an abbreviated locale in the locale parsing

parent f97ce35c
......@@ -3,21 +3,14 @@ import { useMemo } from 'react'
import { useUserLocale } from 'state/user/hooks'
import useParsedQueryString from './useParsedQueryString'
/**
* Mapping from locales without region (e.g. es) to the default region specific locale (e.g. es-US)
*/
const MAPPED_DEFAULT_LOCALES: { [localeWithoutRegion: string]: SupportedLocale } = {
en: 'en-US',
}
/**
* Given a locale string (e.g. from user agent), return the best match for corresponding SupportedLocale
* @param maybeSupportedLocale the fuzzy locale identifier
*/
function parseLocale(maybeSupportedLocale: string): SupportedLocale | undefined {
return (
MAPPED_DEFAULT_LOCALES[maybeSupportedLocale.toLowerCase()] ??
SUPPORTED_LOCALES.find((locale) => locale === maybeSupportedLocale)
const lowerMaybeSupportedLocale = maybeSupportedLocale.toLowerCase()
return SUPPORTED_LOCALES.find(
(locale) => locale === lowerMaybeSupportedLocale || locale.slice(0, 2) === lowerMaybeSupportedLocale
)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment