File size: 915 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
const resourcesToBackend = (res) => ({
  type: 'backend',
  init (services, backendOptions, i18nextOptions) { /* use services and options */ },
  read (language, namespace, callback) {
    if (typeof res === 'function') { // in case someone wants to customize the loading...
      if (res.length < 3) {
        // no callback
        try {
          const r = res(language, namespace)
          if (r && typeof r.then === 'function') {
            // promise
            r.then((data) => callback(null, (data && data.default) || data)).catch(callback)
          } else {
            // sync
            callback(null, r)
          }
        } catch (err) {
          callback(err)
        }
        return
      }
      // normal with callback
      res(language, namespace, callback)
      return
    }
    callback(null, res && res[language] && res[language][namespace])
  }
})

export default resourcesToBackend