-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n.ts
33 lines (25 loc) · 978 Bytes
/
i18n.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { notFound } from 'next/navigation';
import { getRequestConfig } from 'next-intl/server';
import { locales } from './navigation';
type Locale = 'en' | 'es' | 'ka' | 'ru';
type MessagesLoader = () => Promise<IntlMessages>;
const localeData: Record<Locale, MessagesLoader> = {
en: () => import('./messages/en.json').then((module) => module.default),
//@ts-ignore
es: () => import('./messages/es.json').then((module) => module.default),
//@ts-ignore
ka: () => import('./messages/ka.json').then((module) => module.default),
//@ts-ignore
ru: () => import('./messages/ru.json').then((module) => module.default),
};
export default getRequestConfig(async ({ locale }) => {
if (!locales.includes(locale as any)) notFound();
const messagesLoader = localeData[locale as Locale];
if (!messagesLoader) {
throw new Error(`Messages loader not found for locale ${locale}`);
}
const messages = await messagesLoader();
return {
messages,
};
});