diff --git a/src/locale/helpers.ts b/src/locale/helpers.ts index 5a88ac53cb..eb384dfecf 100644 --- a/src/locale/helpers.ts +++ b/src/locale/helpers.ts @@ -314,17 +314,26 @@ export function regionName(countryCode: string, appLang: string): string { return countryCode } +const regionNamesCache = new Map() + +function getRegionNames(appLang: string): Intl.DisplayNames { + let cached = regionNamesCache.get(appLang) + if (!cached) { + cached = new Intl.DisplayNames([appLang], { + type: 'region', + fallback: 'none', + }) + regionNamesCache.set(appLang, cached) + } + return cached +} + function getLocalizedRegionName( countryCode: string, appLang: string, ): string | undefined { try { - const allNames = new Intl.DisplayNames([appLang], { - type: 'region', - fallback: 'none', - }) - - return allNames.of(countryCode) + return getRegionNames(appLang).of(countryCode) } catch (err) { console.warn('Error getting localized region name:', err) return undefined