-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathni18n.config.ts
51 lines (46 loc) · 1.22 KB
/
ni18n.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type { NamespacesNeeded, Ni18nOptions } from 'ni18n'
import { i18n } from './next.config'
import { loadTranslations as ni18nLoadTranslations } from 'ni18n'
import path from 'path'
import HttpBackend from 'i18next-http-backend'
import ChainedBackend from 'i18next-chained-backend'
import LocalStorageBackend from 'i18next-localstorage-backend'
const isBrowser = typeof window !== 'undefined'
export const ni18nConfig: Ni18nOptions = {
supportedLngs: i18n?.locales,
ns: [
'home',
'projects',
'blog',
'common',
'error',
'skills',
'about',
'certificate',
],
use: isBrowser ? [ChainedBackend] : undefined,
backend: isBrowser
? {
backends: [LocalStorageBackend, HttpBackend],
backendOptions: [
{
expirationTime: 24 * 60 * 60 * 1000,
},
{
loadPath: '/locales/{{lng}}/{{ns}}.json',
},
],
}
: undefined,
}
export const loadTranslations = async (
initialLocale?: string | undefined,
namespacesNeeded?: NamespacesNeeded | undefined
) => {
const locales = path.resolve('./', './public/locales')
return await ni18nLoadTranslations(
ni18nConfig,
initialLocale,
namespacesNeeded
)
}