@andre1502/react-utilities 0.9.3 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3203,12 +3203,24 @@ var resourcesToBackend = function resourcesToBackend(res) {
3203
3203
  const getV = divider => {
3204
3204
  return Math.floor(Date.now() / divider);
3205
3205
  };
3206
- const initI18n = (initReactI18next, lang, fallbackLang, langCacheExpiredTimeMs, resources, version, withLocalstorageBackend, cdnUrl, debug) => {
3206
+ const initI18n = _ref => {
3207
+ let {
3208
+ initReactI18next,
3209
+ lang,
3210
+ fallbackLang,
3211
+ langCacheExpiredTimeMs,
3212
+ resources,
3213
+ version,
3214
+ useBackend,
3215
+ withLocalstorageBackend = false,
3216
+ cdnUrl = '',
3217
+ debug = false
3218
+ } = _ref;
3207
3219
  let backends = [];
3208
3220
  let backendOptions = [];
3209
3221
  const langs = Object.keys(resources);
3210
3222
  // https://www.i18next.com/how-to/backend-fallback
3211
- if (withLocalstorageBackend) {
3223
+ if (useBackend && withLocalstorageBackend) {
3212
3224
  const versions = {};
3213
3225
  langs.forEach(value => Object.assign(versions, {
3214
3226
  [value]: version
@@ -3223,7 +3235,7 @@ const initI18n = (initReactI18next, lang, fallbackLang, langCacheExpiredTimeMs,
3223
3235
  versions: versions
3224
3236
  });
3225
3237
  }
3226
- if (cdnUrl) {
3238
+ if (useBackend && cdnUrl) {
3227
3239
  backends.push(Backend);
3228
3240
  backendOptions.push({
3229
3241
  // load resources from url path
@@ -3235,7 +3247,9 @@ const initI18n = (initReactI18next, lang, fallbackLang, langCacheExpiredTimeMs,
3235
3247
  reloadInterval: langCacheExpiredTimeMs // can be used to reload resources in a specific interval (milliseconds) (useful in server environments)
3236
3248
  });
3237
3249
  }
3238
- backends.push(resourcesToBackend(resources));
3250
+ if (useBackend) {
3251
+ backends.push(resourcesToBackend(resources));
3252
+ }
3239
3253
  // https://www.i18next.com/misc/creating-own-plugins#languagedetector
3240
3254
  const languageDetector = {
3241
3255
  type: 'languageDetector',
@@ -3248,8 +3262,8 @@ const initI18n = (initReactI18next, lang, fallbackLang, langCacheExpiredTimeMs,
3248
3262
  return lang;
3249
3263
  }
3250
3264
  };
3251
- const config = {
3252
- debug: debug ?? false,
3265
+ let config = {
3266
+ debug: debug,
3253
3267
  compatibilityJSON: 'v4',
3254
3268
  ns: ['translation'],
3255
3269
  defaultNS: 'translation',
@@ -3258,20 +3272,25 @@ const initI18n = (initReactI18next, lang, fallbackLang, langCacheExpiredTimeMs,
3258
3272
  load: 'currentOnly',
3259
3273
  keySeparator: false,
3260
3274
  nonExplicitSupportedLngs: true,
3261
- backend: {
3262
- backends: backends,
3263
- backendOptions: backendOptions,
3264
- cacheHitMode: 'refreshAndUpdateStore',
3265
- reloadInterval: langCacheExpiredTimeMs,
3266
- refreshExpirationTime: langCacheExpiredTimeMs // only after determined time it should trigger a refresh if necessary
3267
- },
3268
- react: {
3269
- bindI18nStore: 'added' // this way, when the HttpBackend delivers new translations (thanks to refreshAndUpdateStore), the UI gets updated
3270
- },
3271
3275
  interpolation: {
3272
3276
  escapeValue: false // react already safes from xss
3273
3277
  }
3274
3278
  };
3279
+ if (useBackend) {
3280
+ config = {
3281
+ ...config,
3282
+ backend: {
3283
+ backends: backends,
3284
+ backendOptions: backendOptions,
3285
+ cacheHitMode: 'refreshAndUpdateStore',
3286
+ reloadInterval: langCacheExpiredTimeMs,
3287
+ refreshExpirationTime: langCacheExpiredTimeMs // only after determined time it should trigger a refresh if necessary
3288
+ },
3289
+ react: {
3290
+ bindI18nStore: 'added' // this way, when the HttpBackend delivers new translations (thanks to refreshAndUpdateStore), the UI gets updated
3291
+ }
3292
+ };
3293
+ }
3275
3294
  if (!instance.isInitialized) {
3276
3295
  instance.use(Backend$1).use(languageDetector).use(initReactI18next) // passes i18n down to react-i18next
3277
3296
  .init(config, (ex, t) => {
@@ -3279,13 +3298,10 @@ const initI18n = (initReactI18next, lang, fallbackLang, langCacheExpiredTimeMs,
3279
3298
  console.error(`Error when i18n init`, ex);
3280
3299
  return;
3281
3300
  }
3282
- setInterval(() => {
3283
- instance.reloadResources();
3284
- }, langCacheExpiredTimeMs);
3285
3301
  });
3286
3302
  }
3287
3303
  };
3288
3304
 
3289
3305
  exports.getV = getV;
3290
3306
  exports.initI18n = initI18n;
3291
- //# sourceMappingURL=I18n-CB7SyXYJ.js.map
3307
+ //# sourceMappingURL=I18n-qeRA3rLa.js.map