INNER CODE UNIT · TypeScript

isSupportedLocale

opensquilla/opensquilla · opensquilla-webui/src/i18n/index.ts:49

export function isSupportedLocale(value: unknown): value is LocaleCode {
  return typeof value === 'string' && (SUPPORTED_LOCALES as readonly string[]).includes(value)
}

/** Map an arbitrary BCP-47 tag to a supported locale, or null if unsupported. */
export function normalizeLocale(raw: string | null | undefined): LocaleCode | null {
  if (!raw) return null
  const lower = raw.toLowerCase()
  if (lower === 'en' || lower.startsWith('en-') || lower.startsWith('en_')) return 'en'
  if (lower.startsWith('zh')) return 'zh-Hans'
  if (lower.startsWith('ja')) return 'ja'
  if (lower.startsWith('fr')) return 'fr'
  if (lower.startsWith('de')) return 'de'
  if (lower.startsWith('es')) return 'es'
  return null
}

/** Load and register a locale's messages (idempotent). en is always present. */

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…