-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18n.js
63 lines (53 loc) · 1.79 KB
/
i18n.js
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
const env = process.env.NODE_ENV || 'development'
const dev = env !== 'production'
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import Locize from 'i18next-locize-backend/cjs'
import LanguageDetector from 'i18next-browser-languagedetector'
const supportedLocales = ['en', 'es', 'de', 'fr', 'hi', 'it', 'ko', 'pt', 'tr', 'zh', 'sk']
// NOTE: For future reference:
// https://dev.to/adrai/how-to-properly-internationalize-a-react-application-using-i18next-3hdb
// @ts-ignore
i18n
.use(Locize)
.use(LanguageDetector)
.use(initReactI18next)
.init({
i18n: {
defaultLocale: 'en',
locales: supportedLocales
},
// debug: dev,
partialBundledLanguages: true,
fallbackLng: 'en',
supportedLngs: supportedLocales,
// preload: supportedLocales,
ns: ['common'],
defaultNS: 'common',
saveMissing: dev,
serializeConfig: false,
// React config
react: {
// trigger a rerender when language is changed
bindI18n: 'languageChanged',
// we're NOT using suspsense to detect when the translations have loaded
useSuspense: false
},
// Locize config
backend: {
projectId: process.env.NEXT_PUBLIC_LOCIZE_PROJECT_ID,
apiKey: process.env.NEXT_PUBLIC_LOCIZE_DEV_API_KEY,
referenceLng: 'en'
},
// LanguageDetector config
detection: {
// check if language is cached in cookies, if not check local storage
order: ['querystring', 'cookie', 'localStorage', 'navigator', 'path'],
// next-i18next by default searches for the 'next-i18next' cookie on server requests
lookupCookie: 'next-i18next',
lookupLocalStorage: 'i18nextLng',
// cache the language in cookies and local storage
caches: ['cookie', 'localStorage']
}
})
export default i18n