Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

517 B
Raw Blame
export function resolveByLocale<T>(table: Readonly<Record<string, T>>, locale: string): T | undefined {
  const normalized = locale.trim().toLowerCase();
  if (!normalized) return undefined;

  const keys = Object.keys(table);
  const exact = keys.find((key) => key.toLowerCase() === normalized);
  if (exact) return table[exact];

  const base = normalized.split('-')[0];
  const sameLanguage = keys.find((key) => key.toLowerCase().split('-')[0] === base);
  return sameLanguage ? table[sameLanguage] : undefined;
}