mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-18 10:41:56 +10:00
25 lines
676 B
TypeScript
25 lines
676 B
TypeScript
import { i18n } from "@lingui/core";
|
|
import dayjs from "dayjs";
|
|
|
|
import { dayjsLocales } from "./dayjs";
|
|
|
|
export const defaultLocale = "en-US";
|
|
|
|
export async function dynamicActivate(locale: string) {
|
|
try {
|
|
const { messages } = await import(`../locales/${locale}/messages.po`);
|
|
|
|
if (messages) {
|
|
i18n.loadAndActivate({ locale, messages });
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
if (dayjsLocales[locale]) {
|
|
dayjs.locale(await dayjsLocales[locale]());
|
|
}
|
|
} catch {
|
|
// eslint-disable-next-line lingui/no-unlocalized-strings
|
|
throw new Error(`Failed to load messages for locale: ${locale}`);
|
|
}
|
|
}
|