Skip to content

Commit

Permalink
refactor: use map over multiple if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Oct 16, 2024
1 parent 21129ab commit b2f9f84
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/ui/src/services/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import * as process from 'process';
import { initReactI18next } from 'react-i18next';

export let dateFnsLocale = undefined;
const dateFnsLocaleMap = {
'es-ES': 'es',
'fr-FR': 'fr',
} as const;

async function setDateFnsLocale(lng: string) {
if(lng==='es-ES') lng='es';
if(lng==='fr-FR') lng='fr';
dateFnsLocale = await import(`date-fns/locale/${lng}/index.js`).catch((e) => console.error(e));
const languageToLoad = dateFnsLocaleMap[lng as keyof typeof dateFnsLocaleMap] || lng;
dateFnsLocale = await import(`date-fns/locale/${languageToLoad}/index.js`).catch((e) =>
console.error(e)
);
}

export async function initI18n({ lng, basePath }: { lng: string; basePath: string }) {
Expand Down

0 comments on commit b2f9f84

Please sign in to comment.