-
Notifications
You must be signed in to change notification settings - Fork 2
/
i18n.ts
62 lines (52 loc) · 1.39 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { notFound } from 'next/navigation';
import { createLocalizedPathnamesNavigation } from 'next-intl/navigation';
import { getRequestConfig } from 'next-intl/server';
enum LocalePrefixes {
ALWAYS = 'always',
NEVER = 'never',
ASNEEDED = 'as-needed', // removes prefix on default locale
}
const locales = [
'da',
'en',
'es-419',
'es-AR',
'es-CL',
'es-CO',
'es-LA',
'es-MX',
'es-PE',
'es',
'it',
'nl',
'pl',
'pt',
'de',
'fr',
'ja',
'no',
'pt-BR',
'sv',
] as const;
type LocalePrefixesType = `${LocalePrefixes}`;
// Temporary we use NEVER prefix to prioritize accept-language header
// & disable internationalized routes due to incomplete multilingual implementation
const localePrefix: LocalePrefixesType = LocalePrefixes.NEVER;
const defaultLocale = 'en';
type LocaleType = (typeof locales)[number];
export default getRequestConfig(async (params) => {
let lang = params.locale as LocaleType; // eslint-disable-line
if (!locales.includes(lang)) notFound();
return {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
messages: await import(`./messages/${lang}`),
};
});
export const { Link, getPathname, redirect, usePathname, useRouter } =
createLocalizedPathnamesNavigation({
locales,
pathnames: {},
localePrefix,
});
export { LocalePrefixes, locales, localePrefix, defaultLocale };
export type { LocaleType };