-
Notifications
You must be signed in to change notification settings - Fork 501
/
Copy pathi18n.js
61 lines (57 loc) · 1.87 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
import i18n from 'i18next'
import ICU from 'i18next-icu'
import Backend from 'i18next-chained-backend'
import LocalStorageBackend from 'i18next-localstorage-backend'
import HttpBackend from 'i18next-http-backend'
import LanguageDetector from 'i18next-browser-languagedetector'
import pkgJson from '../package.json'
import locales from './lib/languages.json'
import getValidLocaleCode from './lib/i18n-localeParser.js'
const { version } = pkgJson
export const localesList = Object.values(locales)
i18n
.use(ICU)
.use(Backend)
.use(LanguageDetector)
.init({
load: 'currentOnly', // see https://github.com/i18next/i18next-http-backend/issues/61
backend: {
backends: [
LocalStorageBackend,
HttpBackend
],
backendOptions: [
{ // LocalStorageBackend
defaultVersion: version,
expirationTime: (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') ? 1 : 7 * 24 * 60 * 60 * 1000
},
{ // HttpBackend
loadPath: (lngs, namespaces) => {
const locale = getValidLocaleCode({ i18n, localeCode: lngs[0], languages: locales })
// ensure a relative path is used to look up the locales, so it works when loaded from /ipfs/<cid>
return `locales/${locale}/${namespaces}.json`
}
}
]
},
ns: ['app', 'welcome', 'status', 'files', 'explore', 'peers', 'settings', 'notify'],
defaultNS: 'app',
fallbackNS: 'app',
fallbackLng: {
'zh-Hans': ['zh-CN', 'en'],
'zh-Hant': ['zh-TW', 'en'],
zh: ['zh-CN', 'en'],
ko: ['ko-KR', 'en'],
default: ['en']
},
debug: process.env.DEBUG,
// react i18next special options (optional)
react: {
wait: true,
useSuspense: false,
bindI18n: 'languageChanged loaded',
bindStore: 'added removed',
nsMode: 'default'
}
})
export default i18n