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' ...@@ -3,21 +3,14 @@ import { useMemo } from 'react'
import { useUserLocale } from 'state/user/hooks' import { useUserLocale } from 'state/user/hooks'
import useParsedQueryString from './useParsedQueryString' 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 * Given a locale string (e.g. from user agent), return the best match for corresponding SupportedLocale
* @param maybeSupportedLocale the fuzzy locale identifier * @param maybeSupportedLocale the fuzzy locale identifier
*/ */
function parseLocale(maybeSupportedLocale: string): SupportedLocale | undefined { function parseLocale(maybeSupportedLocale: string): SupportedLocale | undefined {
return ( const lowerMaybeSupportedLocale = maybeSupportedLocale.toLowerCase()
MAPPED_DEFAULT_LOCALES[maybeSupportedLocale.toLowerCase()] ?? return SUPPORTED_LOCALES.find(
SUPPORTED_LOCALES.find((locale) => locale === maybeSupportedLocale) (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