File size: 1,304 Bytes
bc20498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  typeof define === 'function' && define.amd ? define(factory) :
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.i18nextResourcesToBackend = factory());
})(this, (function () { 'use strict';

  var resourcesToBackend = function resourcesToBackend(res) {
    return {
      type: 'backend',
      init: function init(services, backendOptions, i18nextOptions) {},
      read: function read(language, namespace, callback) {
        if (typeof res === 'function') {
          if (res.length < 3) {
            try {
              var r = res(language, namespace);
              if (r && typeof r.then === 'function') {
                r.then(function (data) {
                  return callback(null, data && data.default || data);
                }).catch(callback);
              } else {
                callback(null, r);
              }
            } catch (err) {
              callback(err);
            }
            return;
          }
          res(language, namespace, callback);
          return;
        }
        callback(null, res && res[language] && res[language][namespace]);
      }
    };
  };

  return resourcesToBackend;

}));