update modules

This commit is contained in:
s2
2020-06-08 08:50:28 +02:00
parent ae4aaf2668
commit 27635904a6
477 changed files with 20385 additions and 35036 deletions

View File

@@ -6,7 +6,7 @@
[![Bower](https://img.shields.io/bower/v/i18next-xhr-backend.svg)]()
[![David](https://img.shields.io/david/i18next/i18next-xhr-backend.svg?style=flat-square)](https://david-dm.org/i18next/i18next-xhr-backend)
This is a simple i18next backend to be used in the browser. It will load resources from a backend server using xhr.
This is a simple i18next backend to be used in the browser. It will load resources from a backend server using the xhr API.
# Getting started
@@ -26,9 +26,7 @@ Wiring up:
import i18next from 'i18next';
import XHR from 'i18next-xhr-backend';
i18next
.use(XHR)
.init(i18nextOptions);
i18next.use(XHR).init(i18nextOptions);
```
- As with all modules you can either pass the constructor function (class) to the i18next.use or a concrete instance.
@@ -65,12 +63,24 @@ i18next
// here it removes the letter a from the json (bad idea)
parse: function(data) { return data.replace(/a/g, ''); },
//parse data before it has been sent by addPath
parsePayload: function(namespace, key, fallbackValue) { return { key } },
// allow cross domain requests
crossDomain: false,
// allow credentials on cross domain requests
withCredentials: false,
// overrideMimeType sets request.overrideMimeType("application/json")
overrideMimeType: false,
// custom request headers sets request.setRequestHeader(key, value)
customHeaders: {
authorization: 'foo',
// ...
},
// define a custom xhr function
// can be used to support XDomainRequest in IE 8 and 9
//
@@ -96,61 +106,28 @@ Options can be passed in:
import i18next from 'i18next';
import XHR from 'i18next-xhr-backend';
i18next
.use(XHR)
.init({
backend: options
});
i18next.use(XHR).init({
backend: options,
});
```
on construction:
```js
import XHR from 'i18next-xhr-backend';
const xhr = new XHR(null, options);
import XHR from 'i18next-xhr-backend';
const xhr = new XHR(null, options);
```
via calling init:
```js
import XHR from 'i18next-xhr-backend';
const xhr = new XHR();
xhr.init(null, options);
import XHR from 'i18next-xhr-backend';
const xhr = new XHR();
xhr.init(null, options);
```
## Misc
#### Usage with webpack's bundle loader instead of using xhr requests
To use with webpack, install [bundle-loader](https://github.com/webpack/bundle-loader) and [json-loader](https://github.com/webpack/json-loader).
Define a custom xhr function, webpack's bundle loader will load the translations for you.
```js
function loadLocales(url, options, callback, data) {
try {
let waitForLocale = require('bundle!./locales/'+url+'.json');
waitForLocale((locale) => {
callback(locale, {status: '200'});
})
} catch (e) {
callback(null, {status: '404'});
}
}
i18next
.use(XHR)
.init({
backend: {
loadPath: '{{lng}}',
parse: (data) => data,
ajax: loadLocales
}
}, (err, t) => {
// ...
});
```
#### TypeScript definitions
- Install from `@types` (for TypeScript v2 and later):
@@ -161,7 +138,7 @@ i18next
typings install --save --global dt~i18next-xhr-backend
--------------
---
<h3 align="center">Gold Sponsors</h3>