-
Notifications
You must be signed in to change notification settings - Fork 1
/
i18n.ts
103 lines (98 loc) · 1.9 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { notFound } from 'next/navigation';
import { getRequestConfig } from 'next-intl/server';
export const languages = [
{
code: 'en-US',
lang: 'en',
backendValue: 'en',
label: 'English',
},
{
code: 'ja-JP',
lang: 'ja',
backendValue: 'jp',
label: '日本語',
},
{
code: 'pt-BR',
lang: 'pt',
backendValue: 'pt',
label: 'Português',
},
{
code: 'es-ES',
lang: 'es',
backendValue: 'es',
label: 'Español',
},
{
code: 'de-DE',
lang: 'de',
backendValue: 'de',
label: 'Deutsch',
},
{
code: 'ru-RU',
lang: 'ru',
backendValue: 'ru',
label: 'Русский',
},
{
code: 'fr-FR',
lang: 'fr',
backendValue: 'fr',
label: 'Français',
},
{
code: 'zh-CN',
lang: 'cn',
backendValue: 'zh',
label: '简体中文',
},
{
code: 'zh-TW',
lang: 'tw',
backendValue: 'tw',
label: '繁體中文',
},
{
code: 'ko-KR',
lang: 'ko',
backendValue: 'ko',
label: '한국어',
},
{
code: 'th-TH',
lang: 'th',
backendValue: 'th',
label: 'ไทย',
},
{
code: 'vi-VN',
lang: 'vi',
backendValue: 'vi',
label: 'Tiếng Việt',
},
{
code: 'ar-SA',
lang: 'ar',
backendValue: 'ar',
label: 'العربية',
},
];
export const generateLanguagePaths = (baseRoute: string, route: string) =>
languages.reduce(
(paths, { code, lang }) => ({
...paths,
[lang === 'en' ? 'x-default' : code]: lang === 'en' ? `${baseRoute}/${route}` : `${baseRoute}/${lang}/${route}`,
}),
{},
);
export const locales = languages.map((lang) => lang.lang);
export default getRequestConfig(async ({ locale }) => {
// Validate that the incoming `locale` parameter is valid
if (!locales.includes(locale as any)) notFound();
return {
messages: (await import(`./messages/${locale}.json`)).default,
};
});