Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(i18n): 🩹 Fixing store for localStorageBackend plugin #2192

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,38 @@ import getValidLocaleCode from './lib/i18n-localeParser.js'
const { version } = pkgJson
export const localesList = Object.values(locales)

let i18nBackend = [HttpBackend]
let i18nBackendOptions = [
{ // 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`
}
}
]

if (typeof window !== 'undefined' && 'localStorage' in window) {
i18nBackend = [LocalStorageBackend, ...i18nBackend]
i18nBackendOptions = [
{ // LocalStorageBackend
defaultVersion: version,
expirationTime: (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') ? 1 : 7 * 24 * 60 * 60 * 1000,
store: typeof window !== 'undefined' && 'localStorage' in window ? window.localStorage : null
},
...i18nBackendOptions
]
}

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`
}
}
]
backends: i18nBackend,
backendOptions: i18nBackendOptions
},
ns: ['app', 'welcome', 'status', 'files', 'explore', 'peers', 'settings', 'notify'],
defaultNS: 'app',
Expand Down
Loading