From 06746179b9179384a00d97f2b7a8909e08ae0297 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 2 Mar 2026 14:02:43 +0200 Subject: [PATCH] add region name cache --- src/locale/helpers.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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