@@ -12,30 +12,38 @@ import getValidLocaleCode from './lib/i18n-localeParser.js'
12
12
const { version } = pkgJson
13
13
export const localesList = Object . values ( locales )
14
14
15
+ let i18nBackend = [ HttpBackend ]
16
+ let i18nBackendOptions = [
17
+ { // HttpBackend
18
+ loadPath : ( lngs , namespaces ) => {
19
+ const locale = getValidLocaleCode ( { i18n, localeCode : lngs [ 0 ] , languages : locales } )
20
+ // ensure a relative path is used to look up the locales, so it works when loaded from /ipfs/<cid>
21
+ return `locales/${ locale } /${ namespaces } .json`
22
+ }
23
+ }
24
+ ]
25
+
26
+ if ( typeof window !== 'undefined' && 'localStorage' in window ) {
27
+ i18nBackend = [ LocalStorageBackend , ...i18nBackend ]
28
+ i18nBackendOptions = [
29
+ { // LocalStorageBackend
30
+ defaultVersion : version ,
31
+ expirationTime : ( ! process . env . NODE_ENV || process . env . NODE_ENV === 'development' ) ? 1 : 7 * 24 * 60 * 60 * 1000 ,
32
+ store : typeof window !== 'undefined' && 'localStorage' in window ? window . localStorage : null
33
+ } ,
34
+ ...i18nBackendOptions
35
+ ]
36
+ }
37
+
15
38
i18n
16
39
. use ( ICU )
17
40
. use ( Backend )
18
41
. use ( LanguageDetector )
19
42
. init ( {
20
43
load : 'currentOnly' , // see https://github.com/i18next/i18next-http-backend/issues/61
21
44
backend : {
22
- backends : [
23
- LocalStorageBackend ,
24
- HttpBackend
25
- ] ,
26
- backendOptions : [
27
- { // LocalStorageBackend
28
- defaultVersion : version ,
29
- expirationTime : ( ! process . env . NODE_ENV || process . env . NODE_ENV === 'development' ) ? 1 : 7 * 24 * 60 * 60 * 1000
30
- } ,
31
- { // HttpBackend
32
- loadPath : ( lngs , namespaces ) => {
33
- const locale = getValidLocaleCode ( { i18n, localeCode : lngs [ 0 ] , languages : locales } )
34
- // ensure a relative path is used to look up the locales, so it works when loaded from /ipfs/<cid>
35
- return `locales/${ locale } /${ namespaces } .json`
36
- }
37
- }
38
- ]
45
+ backends : i18nBackend ,
46
+ backendOptions : i18nBackendOptions
39
47
} ,
40
48
ns : [ 'app' , 'welcome' , 'status' , 'files' , 'explore' , 'peers' , 'settings' , 'notify' ] ,
41
49
defaultNS : 'app' ,
0 commit comments