-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathi18n.config.ts
32 lines (28 loc) · 962 Bytes
/
i18n.config.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
import { notFound } from 'next/navigation';
import { IntlErrorCode } from 'next-intl';
import { getRequestConfig } from 'next-intl/server';
export type Locale = 'en' | 'es';
export const DEF_LOCALE: Locale = 'en';
export const SUPPORTED_LOCALES: Locale[] = ['en', 'es'];
export const localeMap: Record<Locale, string> = {
en: 'English',
es: 'Español'
};
export default getRequestConfig(async ({ locale }) => {
// Validate that the incoming `locale` parameter is valid
if (!SUPPORTED_LOCALES.includes(locale as any)) notFound();
return {
messages: (await import(`./translations/${locale}.json`)).default,
// https://next-intl-docs.vercel.app/docs/usage/configuration#error-handling
onError(error) {
if (error.code === IntlErrorCode.MISSING_MESSAGE) {
console.error(error.originalMessage);
} else {
console.log(error.originalMessage);
}
},
getMessageFallback() {
return '';
}
};
});