INNER CODE UNIT · TypeScript

normalizeLocale

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

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. */
export async function loadLocaleMessages(code: LocaleCode): Promise<void> {
  if (loaded.has(code)) return
  const loader = loaders[code as Exclude<LocaleCode, typeof DEFAULT_LOCALE>]
  if (!loader) return
  const mod = await loader()

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…