first commit
This commit is contained in:
24
node_modules/i18next-xhr-backend/.circleci/config.yml
generated
vendored
Normal file
24
node_modules/i18next-xhr-backend/.circleci/config.yml
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
version: 2
|
||||
jobs:
|
||||
build:
|
||||
docker:
|
||||
- image: circleci/node:latest-browsers
|
||||
environment:
|
||||
CHROME_BIN: '/usr/bin/google-chrome'
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: update-npm
|
||||
command: 'sudo npm install -g npm@6'
|
||||
- restore_cache:
|
||||
key: dependency-cache-{{ checksum "package.json" }}
|
||||
- run:
|
||||
name: install-npm-wee
|
||||
command: npm install
|
||||
- save_cache:
|
||||
key: dependency-cache-{{ checksum "package.json" }}
|
||||
paths:
|
||||
- ./node_modules
|
||||
- run:
|
||||
name: test
|
||||
command: npm test
|
1
node_modules/i18next-xhr-backend/.coveralls.yml
generated
vendored
Normal file
1
node_modules/i18next-xhr-backend/.coveralls.yml
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
repo_token: 95SiHydOTG99ngOBBMnlRSl28IgE9kAah
|
2
node_modules/i18next-xhr-backend/.prettierignore
generated
vendored
Normal file
2
node_modules/i18next-xhr-backend/.prettierignore
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
dist
|
||||
i18nextXHRBackend*
|
8
node_modules/i18next-xhr-backend/.prettierrc
generated
vendored
Normal file
8
node_modules/i18next-xhr-backend/.prettierrc
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"bracketSpacing": true,
|
||||
"jsxBracketSameLine": false,
|
||||
"printWidth": 100,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
88
node_modules/i18next-xhr-backend/CHANGELOG.md
generated
vendored
Normal file
88
node_modules/i18next-xhr-backend/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
### 3.2.2
|
||||
|
||||
- typescript: Hotfix TS error importing types from i18next [333](https://github.com/i18next/i18next-xhr-backend/pull/333)
|
||||
|
||||
### 3.2.1
|
||||
|
||||
- typescript: Use updated ts export default from i18next [330](https://github.com/i18next/i18next-xhr-backend/pull/330)
|
||||
|
||||
### 3.2.0
|
||||
|
||||
- Parse payload option [326](https://github.com/i18next/i18next-xhr-backend/pull/326)
|
||||
|
||||
### 3.1.2
|
||||
|
||||
- typescript: fix No inputs were found in config file" - tsconfig typo [323](https://github.com/i18next/i18next-xhr-backend/issues/323)
|
||||
|
||||
### 3.1.1
|
||||
|
||||
- typescript: fix use of class, add `use()` tests [322](https://github.com/i18next/i18next-xhr-backend/pull/322)
|
||||
|
||||
### 3.1.0
|
||||
|
||||
- allow customHeaders to be a function [321](https://github.com/i18next/i18next-xhr-backend/pull/321)
|
||||
|
||||
### 3.0.1
|
||||
|
||||
- typescript: Fix the types and use exposed types from i18next [319](https://github.com/i18next/i18next-xhr-backend/pull/319)
|
||||
|
||||
### 3.0.0
|
||||
|
||||
- removes deprecated jsnext:main from package.json
|
||||
- Bundle all entry points with rollup [314](https://github.com/i18next/i18next-xhr-backend/pull/314)
|
||||
- **note:** dist/es -> dist/esm, dist/commonjs -> dist/cjs (individual files -> one bundled file)
|
||||
- removes bower finally
|
||||
|
||||
### 2.0.1
|
||||
|
||||
- typescript: fix types [298](https://github.com/i18next/i18next-xhr-backend/pull/298)
|
||||
|
||||
### 2.0.0
|
||||
|
||||
- typescript: add types
|
||||
|
||||
### 1.5.1
|
||||
|
||||
- fixes add path to use `/locales/...`
|
||||
|
||||
### 1.5.0
|
||||
|
||||
- add .js for browser import implementation [PR268](https://github.com/i18next/i18next-xhr-backend/pull/268)
|
||||
|
||||
### 1.4.3
|
||||
|
||||
- Fix XML parsing error in Firefox [PR265](https://github.com/i18next/i18next-xhr-backend/pull/265)
|
||||
|
||||
### 1.4.2
|
||||
|
||||
- usage with sinon [260](https://github.com/i18next/i18next-xhr-backend/pull/260)
|
||||
|
||||
### 1.4.1
|
||||
|
||||
- fixes ajax
|
||||
|
||||
### 1.4.0
|
||||
|
||||
- add `queryStringParams` option [PR255](https://github.com/i18next/i18next-xhr-backend/pull/255)
|
||||
|
||||
### 1.3.0
|
||||
|
||||
- add support for custom headers [PR250](https://github.com/i18next/i18next-xhr-backend/pull/250)
|
||||
- update dev dependencies
|
||||
|
||||
### 1.2.1
|
||||
|
||||
- downgrade babel-preset-es2015-native-modules to correctly build es files
|
||||
|
||||
### 1.2.0
|
||||
|
||||
- support withCredentials flag on XHR [PR238](https://github.com/i18next/i18next-xhr-backend/pull/238)
|
||||
|
||||
### 1.1.0
|
||||
|
||||
- allows loadPath to be a function [PR236](https://github.com/i18next/i18next-xhr-backend/pull/236)
|
||||
|
||||
### 1.0.1
|
||||
|
||||
- change amd export to unnamed
|
||||
- initial v1
|
22
node_modules/i18next-xhr-backend/LICENSE
generated
vendored
Normal file
22
node_modules/i18next-xhr-backend/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 i18next
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
149
node_modules/i18next-xhr-backend/README.md
generated
vendored
Normal file
149
node_modules/i18next-xhr-backend/README.md
generated
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
# Introduction
|
||||
|
||||
[](https://travis-ci.org/i18next/i18next-xhr-backend)
|
||||
[](https://coveralls.io/github/i18next/i18next-xhr-backend)
|
||||
[](https://www.npmjs.com/package/i18next-xhr-backend)
|
||||
[]()
|
||||
[](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 the xhr API.
|
||||
|
||||
# Getting started
|
||||
|
||||
Source can be loaded via [npm](https://www.npmjs.com/package/i18next-xhr-backend), bower or [downloaded](https://github.com/i18next/i18next-xhr-backend/blob/master/i18nextXHRBackend.min.js) from this repo.
|
||||
|
||||
```
|
||||
# npm package
|
||||
$ npm install i18next-xhr-backend
|
||||
|
||||
# bower
|
||||
$ bower install i18next-xhr-backend
|
||||
```
|
||||
|
||||
Wiring up:
|
||||
|
||||
```js
|
||||
import i18next from 'i18next';
|
||||
import XHR from 'i18next-xhr-backend';
|
||||
|
||||
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.
|
||||
- If you don't use a module loader it will be added to `window.i18nextXHRBackend`
|
||||
|
||||
## Backend Options
|
||||
|
||||
```js
|
||||
{
|
||||
// path where resources get loaded from, or a function
|
||||
// returning a path:
|
||||
// function(lngs, namespaces) { return customPath; }
|
||||
// the returned path will interpolate lng, ns if provided like giving a static path
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
|
||||
// path to post missing resources
|
||||
addPath: 'locales/add/{{lng}}/{{ns}}',
|
||||
|
||||
// your backend server supports multiloading
|
||||
// /locales/resources.json?lng=de+en&ns=ns1+ns2
|
||||
// Adapter is needed to enable MultiLoading https://github.com/i18next/i18next-multiload-backend-adapter
|
||||
// Returned JSON structure in this case is
|
||||
// {
|
||||
// lang : {
|
||||
// namespaceA: {},
|
||||
// namespaceB: {},
|
||||
// ...etc
|
||||
// }
|
||||
// }
|
||||
allowMultiLoading: false, // set loadPath: '/locales/resources.json?lng={{lng}}&ns={{ns}}' to adapt to multiLoading
|
||||
|
||||
// parse data after it has been fetched
|
||||
// in example use https://www.npmjs.com/package/json5
|
||||
// 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
|
||||
//
|
||||
// 'url' will be passed the value of 'loadPath'
|
||||
// 'options' will be this entire options object
|
||||
// 'callback' is a function that takes two parameters, 'data' and 'xhr'.
|
||||
// 'data' should be the key:value translation pairs for the
|
||||
// requested language and namespace, or null in case of an error.
|
||||
// 'xhr' should be a status object, e.g. { status: 200 }
|
||||
// 'data' will be a key:value object used when saving missing translations
|
||||
ajax: function (url, options, callback, data) {},
|
||||
|
||||
// adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5'
|
||||
queryStringParams: { v: '1.3.5' }
|
||||
}
|
||||
```
|
||||
|
||||
Options can be passed in:
|
||||
|
||||
**preferred** - by setting options.backend in i18next.init:
|
||||
|
||||
```js
|
||||
import i18next from 'i18next';
|
||||
import XHR from 'i18next-xhr-backend';
|
||||
|
||||
i18next.use(XHR).init({
|
||||
backend: options,
|
||||
});
|
||||
```
|
||||
|
||||
on construction:
|
||||
|
||||
```js
|
||||
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);
|
||||
```
|
||||
|
||||
## Misc
|
||||
|
||||
#### TypeScript definitions
|
||||
|
||||
- Install from `@types` (for TypeScript v2 and later):
|
||||
|
||||
npm install --save-dev @types/i18next-xhr-backend
|
||||
|
||||
- Install from `typings`:
|
||||
|
||||
typings install --save --global dt~i18next-xhr-backend
|
||||
|
||||
---
|
||||
|
||||
<h3 align="center">Gold Sponsors</h3>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://locize.com/" target="_blank">
|
||||
<img src="https://raw.githubusercontent.com/i18next/i18next/master/assets/locize_sponsor_240.gif" width="240px">
|
||||
</a>
|
||||
</p>
|
214
node_modules/i18next-xhr-backend/dist/cjs/i18nextXHRBackend.js
generated
vendored
Normal file
214
node_modules/i18next-xhr-backend/dist/cjs/i18nextXHRBackend.js
generated
vendored
Normal file
@@ -0,0 +1,214 @@
|
||||
'use strict';
|
||||
|
||||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
||||
|
||||
var _classCallCheck = _interopDefault(require('@babel/runtime/helpers/classCallCheck'));
|
||||
var _createClass = _interopDefault(require('@babel/runtime/helpers/createClass'));
|
||||
var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty'));
|
||||
var _typeof = _interopDefault(require('@babel/runtime/helpers/typeof'));
|
||||
|
||||
var arr = [];
|
||||
var each = arr.forEach;
|
||||
var slice = arr.slice;
|
||||
function defaults(obj) {
|
||||
each.call(slice.call(arguments, 1), function (source) {
|
||||
if (source) {
|
||||
for (var prop in source) {
|
||||
if (obj[prop] === undefined) obj[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
function addQueryString(url, params) {
|
||||
if (params && _typeof(params) === 'object') {
|
||||
var queryString = '',
|
||||
e = encodeURIComponent; // Must encode data
|
||||
|
||||
for (var paramName in params) {
|
||||
queryString += '&' + e(paramName) + '=' + e(params[paramName]);
|
||||
}
|
||||
|
||||
if (!queryString) {
|
||||
return url;
|
||||
}
|
||||
|
||||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1);
|
||||
}
|
||||
|
||||
return url;
|
||||
} // https://gist.github.com/Xeoncross/7663273
|
||||
|
||||
|
||||
function ajax(url, options, callback, data, cache) {
|
||||
if (data && _typeof(data) === 'object') {
|
||||
if (!cache) {
|
||||
data['_t'] = new Date();
|
||||
} // URL encoded form data must be in querystring format
|
||||
|
||||
|
||||
data = addQueryString('', data).slice(1);
|
||||
}
|
||||
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
|
||||
try {
|
||||
var x;
|
||||
|
||||
if (XMLHttpRequest) {
|
||||
x = new XMLHttpRequest();
|
||||
} else {
|
||||
x = new ActiveXObject('MSXML2.XMLHTTP.3.0');
|
||||
}
|
||||
|
||||
x.open(data ? 'POST' : 'GET', url, 1);
|
||||
|
||||
if (!options.crossDomain) {
|
||||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
}
|
||||
|
||||
x.withCredentials = !!options.withCredentials;
|
||||
|
||||
if (data) {
|
||||
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
|
||||
if (x.overrideMimeType) {
|
||||
x.overrideMimeType("application/json");
|
||||
}
|
||||
|
||||
var h = options.customHeaders;
|
||||
h = typeof h === 'function' ? h() : h;
|
||||
|
||||
if (h) {
|
||||
for (var i in h) {
|
||||
x.setRequestHeader(i, h[i]);
|
||||
}
|
||||
}
|
||||
|
||||
x.onreadystatechange = function () {
|
||||
x.readyState > 3 && callback && callback(x.responseText, x);
|
||||
};
|
||||
|
||||
x.send(data);
|
||||
} catch (e) {
|
||||
console && console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
allowMultiLoading: false,
|
||||
parse: JSON.parse,
|
||||
parsePayload: function parsePayload(namespace, key, fallbackValue) {
|
||||
return _defineProperty({}, key, fallbackValue || '');
|
||||
},
|
||||
crossDomain: false,
|
||||
ajax: ajax
|
||||
};
|
||||
}
|
||||
|
||||
var Backend =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Backend(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, Backend);
|
||||
|
||||
this.init(services, options);
|
||||
this.type = 'backend';
|
||||
}
|
||||
|
||||
_createClass(Backend, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
this.services = services;
|
||||
this.options = defaults(options, this.options || {}, getDefaults());
|
||||
}
|
||||
}, {
|
||||
key: "readMulti",
|
||||
value: function readMulti(languages, namespaces, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath(languages, namespaces);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, {
|
||||
lng: languages.join('+'),
|
||||
ns: namespaces.join('+')
|
||||
});
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: "read",
|
||||
value: function read(language, namespace, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath([language], [namespace]);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, {
|
||||
lng: language,
|
||||
ns: namespace
|
||||
});
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: "loadUrl",
|
||||
value: function loadUrl(url, callback) {
|
||||
var _this = this;
|
||||
|
||||
this.options.ajax(url, this.options, function (data, xhr) {
|
||||
if (xhr.status >= 500 && xhr.status < 600) return callback('failed loading ' + url, true
|
||||
/* retry */
|
||||
);
|
||||
if (xhr.status >= 400 && xhr.status < 500) return callback('failed loading ' + url, false
|
||||
/* no retry */
|
||||
);
|
||||
var ret, err;
|
||||
|
||||
try {
|
||||
ret = _this.options.parse(data, url);
|
||||
} catch (e) {
|
||||
err = 'failed parsing ' + url + ' to json';
|
||||
}
|
||||
|
||||
if (err) return callback(err, false);
|
||||
callback(null, ret);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "create",
|
||||
value: function create(languages, namespace, key, fallbackValue) {
|
||||
var _this2 = this;
|
||||
|
||||
if (typeof languages === 'string') languages = [languages];
|
||||
var payload = this.options.parsePayload(namespace, key, fallbackValue);
|
||||
languages.forEach(function (lng) {
|
||||
var url = _this2.services.interpolator.interpolate(_this2.options.addPath, {
|
||||
lng: lng,
|
||||
ns: namespace
|
||||
});
|
||||
|
||||
_this2.options.ajax(url, _this2.options, function (data, xhr) {//const statusCode = xhr.status.toString();
|
||||
// TODO: if statusCode === 4xx do log
|
||||
}, payload);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Backend;
|
||||
}();
|
||||
|
||||
Backend.type = 'backend';
|
||||
|
||||
module.exports = Backend;
|
210
node_modules/i18next-xhr-backend/dist/esm/i18nextXHRBackend.js
generated
vendored
Normal file
210
node_modules/i18next-xhr-backend/dist/esm/i18nextXHRBackend.js
generated
vendored
Normal file
@@ -0,0 +1,210 @@
|
||||
import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
|
||||
import _createClass from '@babel/runtime/helpers/esm/createClass';
|
||||
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
||||
import _typeof from '@babel/runtime/helpers/esm/typeof';
|
||||
|
||||
var arr = [];
|
||||
var each = arr.forEach;
|
||||
var slice = arr.slice;
|
||||
function defaults(obj) {
|
||||
each.call(slice.call(arguments, 1), function (source) {
|
||||
if (source) {
|
||||
for (var prop in source) {
|
||||
if (obj[prop] === undefined) obj[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
function addQueryString(url, params) {
|
||||
if (params && _typeof(params) === 'object') {
|
||||
var queryString = '',
|
||||
e = encodeURIComponent; // Must encode data
|
||||
|
||||
for (var paramName in params) {
|
||||
queryString += '&' + e(paramName) + '=' + e(params[paramName]);
|
||||
}
|
||||
|
||||
if (!queryString) {
|
||||
return url;
|
||||
}
|
||||
|
||||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1);
|
||||
}
|
||||
|
||||
return url;
|
||||
} // https://gist.github.com/Xeoncross/7663273
|
||||
|
||||
|
||||
function ajax(url, options, callback, data, cache) {
|
||||
if (data && _typeof(data) === 'object') {
|
||||
if (!cache) {
|
||||
data['_t'] = new Date();
|
||||
} // URL encoded form data must be in querystring format
|
||||
|
||||
|
||||
data = addQueryString('', data).slice(1);
|
||||
}
|
||||
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
|
||||
try {
|
||||
var x;
|
||||
|
||||
if (XMLHttpRequest) {
|
||||
x = new XMLHttpRequest();
|
||||
} else {
|
||||
x = new ActiveXObject('MSXML2.XMLHTTP.3.0');
|
||||
}
|
||||
|
||||
x.open(data ? 'POST' : 'GET', url, 1);
|
||||
|
||||
if (!options.crossDomain) {
|
||||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
}
|
||||
|
||||
x.withCredentials = !!options.withCredentials;
|
||||
|
||||
if (data) {
|
||||
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
|
||||
if (x.overrideMimeType) {
|
||||
x.overrideMimeType("application/json");
|
||||
}
|
||||
|
||||
var h = options.customHeaders;
|
||||
h = typeof h === 'function' ? h() : h;
|
||||
|
||||
if (h) {
|
||||
for (var i in h) {
|
||||
x.setRequestHeader(i, h[i]);
|
||||
}
|
||||
}
|
||||
|
||||
x.onreadystatechange = function () {
|
||||
x.readyState > 3 && callback && callback(x.responseText, x);
|
||||
};
|
||||
|
||||
x.send(data);
|
||||
} catch (e) {
|
||||
console && console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
allowMultiLoading: false,
|
||||
parse: JSON.parse,
|
||||
parsePayload: function parsePayload(namespace, key, fallbackValue) {
|
||||
return _defineProperty({}, key, fallbackValue || '');
|
||||
},
|
||||
crossDomain: false,
|
||||
ajax: ajax
|
||||
};
|
||||
}
|
||||
|
||||
var Backend =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Backend(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, Backend);
|
||||
|
||||
this.init(services, options);
|
||||
this.type = 'backend';
|
||||
}
|
||||
|
||||
_createClass(Backend, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
this.services = services;
|
||||
this.options = defaults(options, this.options || {}, getDefaults());
|
||||
}
|
||||
}, {
|
||||
key: "readMulti",
|
||||
value: function readMulti(languages, namespaces, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath(languages, namespaces);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, {
|
||||
lng: languages.join('+'),
|
||||
ns: namespaces.join('+')
|
||||
});
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: "read",
|
||||
value: function read(language, namespace, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath([language], [namespace]);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, {
|
||||
lng: language,
|
||||
ns: namespace
|
||||
});
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: "loadUrl",
|
||||
value: function loadUrl(url, callback) {
|
||||
var _this = this;
|
||||
|
||||
this.options.ajax(url, this.options, function (data, xhr) {
|
||||
if (xhr.status >= 500 && xhr.status < 600) return callback('failed loading ' + url, true
|
||||
/* retry */
|
||||
);
|
||||
if (xhr.status >= 400 && xhr.status < 500) return callback('failed loading ' + url, false
|
||||
/* no retry */
|
||||
);
|
||||
var ret, err;
|
||||
|
||||
try {
|
||||
ret = _this.options.parse(data, url);
|
||||
} catch (e) {
|
||||
err = 'failed parsing ' + url + ' to json';
|
||||
}
|
||||
|
||||
if (err) return callback(err, false);
|
||||
callback(null, ret);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "create",
|
||||
value: function create(languages, namespace, key, fallbackValue) {
|
||||
var _this2 = this;
|
||||
|
||||
if (typeof languages === 'string') languages = [languages];
|
||||
var payload = this.options.parsePayload(namespace, key, fallbackValue);
|
||||
languages.forEach(function (lng) {
|
||||
var url = _this2.services.interpolator.interpolate(_this2.options.addPath, {
|
||||
lng: lng,
|
||||
ns: namespace
|
||||
});
|
||||
|
||||
_this2.options.ajax(url, _this2.options, function (data, xhr) {//const statusCode = xhr.status.toString();
|
||||
// TODO: if statusCode === 4xx do log
|
||||
}, payload);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Backend;
|
||||
}();
|
||||
|
||||
Backend.type = 'backend';
|
||||
|
||||
export default Backend;
|
266
node_modules/i18next-xhr-backend/dist/umd/i18nextXHRBackend.js
generated
vendored
Normal file
266
node_modules/i18next-xhr-backend/dist/umd/i18nextXHRBackend.js
generated
vendored
Normal file
@@ -0,0 +1,266 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, global.i18nextXHRBackend = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function _defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) _defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
}
|
||||
|
||||
function _defineProperty(obj, key, value) {
|
||||
if (key in obj) {
|
||||
Object.defineProperty(obj, key, {
|
||||
value: value,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
} else {
|
||||
obj[key] = value;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
var arr = [];
|
||||
var each = arr.forEach;
|
||||
var slice = arr.slice;
|
||||
function defaults(obj) {
|
||||
each.call(slice.call(arguments, 1), function (source) {
|
||||
if (source) {
|
||||
for (var prop in source) {
|
||||
if (obj[prop] === undefined) obj[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); }
|
||||
|
||||
function _typeof(obj) {
|
||||
if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
|
||||
_typeof = function _typeof(obj) {
|
||||
return _typeof2(obj);
|
||||
};
|
||||
} else {
|
||||
_typeof = function _typeof(obj) {
|
||||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
|
||||
};
|
||||
}
|
||||
|
||||
return _typeof(obj);
|
||||
}
|
||||
|
||||
function addQueryString(url, params) {
|
||||
if (params && _typeof(params) === 'object') {
|
||||
var queryString = '',
|
||||
e = encodeURIComponent; // Must encode data
|
||||
|
||||
for (var paramName in params) {
|
||||
queryString += '&' + e(paramName) + '=' + e(params[paramName]);
|
||||
}
|
||||
|
||||
if (!queryString) {
|
||||
return url;
|
||||
}
|
||||
|
||||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1);
|
||||
}
|
||||
|
||||
return url;
|
||||
} // https://gist.github.com/Xeoncross/7663273
|
||||
|
||||
|
||||
function ajax(url, options, callback, data, cache) {
|
||||
if (data && _typeof(data) === 'object') {
|
||||
if (!cache) {
|
||||
data['_t'] = new Date();
|
||||
} // URL encoded form data must be in querystring format
|
||||
|
||||
|
||||
data = addQueryString('', data).slice(1);
|
||||
}
|
||||
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
|
||||
try {
|
||||
var x;
|
||||
|
||||
if (XMLHttpRequest) {
|
||||
x = new XMLHttpRequest();
|
||||
} else {
|
||||
x = new ActiveXObject('MSXML2.XMLHTTP.3.0');
|
||||
}
|
||||
|
||||
x.open(data ? 'POST' : 'GET', url, 1);
|
||||
|
||||
if (!options.crossDomain) {
|
||||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
}
|
||||
|
||||
x.withCredentials = !!options.withCredentials;
|
||||
|
||||
if (data) {
|
||||
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
|
||||
if (x.overrideMimeType) {
|
||||
x.overrideMimeType("application/json");
|
||||
}
|
||||
|
||||
var h = options.customHeaders;
|
||||
h = typeof h === 'function' ? h() : h;
|
||||
|
||||
if (h) {
|
||||
for (var i in h) {
|
||||
x.setRequestHeader(i, h[i]);
|
||||
}
|
||||
}
|
||||
|
||||
x.onreadystatechange = function () {
|
||||
x.readyState > 3 && callback && callback(x.responseText, x);
|
||||
};
|
||||
|
||||
x.send(data);
|
||||
} catch (e) {
|
||||
console && console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
allowMultiLoading: false,
|
||||
parse: JSON.parse,
|
||||
parsePayload: function parsePayload(namespace, key, fallbackValue) {
|
||||
return _defineProperty({}, key, fallbackValue || '');
|
||||
},
|
||||
crossDomain: false,
|
||||
ajax: ajax
|
||||
};
|
||||
}
|
||||
|
||||
var Backend =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Backend(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, Backend);
|
||||
|
||||
this.init(services, options);
|
||||
this.type = 'backend';
|
||||
}
|
||||
|
||||
_createClass(Backend, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
this.services = services;
|
||||
this.options = defaults(options, this.options || {}, getDefaults());
|
||||
}
|
||||
}, {
|
||||
key: "readMulti",
|
||||
value: function readMulti(languages, namespaces, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath(languages, namespaces);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, {
|
||||
lng: languages.join('+'),
|
||||
ns: namespaces.join('+')
|
||||
});
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: "read",
|
||||
value: function read(language, namespace, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath([language], [namespace]);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, {
|
||||
lng: language,
|
||||
ns: namespace
|
||||
});
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: "loadUrl",
|
||||
value: function loadUrl(url, callback) {
|
||||
var _this = this;
|
||||
|
||||
this.options.ajax(url, this.options, function (data, xhr) {
|
||||
if (xhr.status >= 500 && xhr.status < 600) return callback('failed loading ' + url, true
|
||||
/* retry */
|
||||
);
|
||||
if (xhr.status >= 400 && xhr.status < 500) return callback('failed loading ' + url, false
|
||||
/* no retry */
|
||||
);
|
||||
var ret, err;
|
||||
|
||||
try {
|
||||
ret = _this.options.parse(data, url);
|
||||
} catch (e) {
|
||||
err = 'failed parsing ' + url + ' to json';
|
||||
}
|
||||
|
||||
if (err) return callback(err, false);
|
||||
callback(null, ret);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "create",
|
||||
value: function create(languages, namespace, key, fallbackValue) {
|
||||
var _this2 = this;
|
||||
|
||||
if (typeof languages === 'string') languages = [languages];
|
||||
var payload = this.options.parsePayload(namespace, key, fallbackValue);
|
||||
languages.forEach(function (lng) {
|
||||
var url = _this2.services.interpolator.interpolate(_this2.options.addPath, {
|
||||
lng: lng,
|
||||
ns: namespace
|
||||
});
|
||||
|
||||
_this2.options.ajax(url, _this2.options, function (data, xhr) {//const statusCode = xhr.status.toString();
|
||||
// TODO: if statusCode === 4xx do log
|
||||
}, payload);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Backend;
|
||||
}();
|
||||
|
||||
Backend.type = 'backend';
|
||||
|
||||
return Backend;
|
||||
|
||||
})));
|
1
node_modules/i18next-xhr-backend/dist/umd/i18nextXHRBackend.min.js
generated
vendored
Normal file
1
node_modules/i18next-xhr-backend/dist/umd/i18nextXHRBackend.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).i18nextXHRBackend=e()}(this,(function(){"use strict";function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var e=[],n=e.forEach,o=e.slice;function i(t){return n.call(o.call(arguments,1),(function(e){if(e)for(var n in e)void 0===t[n]&&(t[n]=e[n])})),t}function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(t){return(a="function"==typeof Symbol&&"symbol"===r(Symbol.iterator)?function(t){return r(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":r(t)})(t)}function s(t,e){if(e&&"object"===a(e)){var n="",o=encodeURIComponent;for(var i in e)n+="&"+o(i)+"="+o(e[i]);if(!n)return t;t=t+(-1!==t.indexOf("?")?"&":"?")+n.slice(1)}return t}function l(t,e,n,o,i){o&&"object"===a(o)&&(i||(o._t=new Date),o=s("",o).slice(1)),e.queryStringParams&&(t=s(t,e.queryStringParams));try{var r;(r=XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0")).open(o?"POST":"GET",t,1),e.crossDomain||r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.withCredentials=!!e.withCredentials,o&&r.setRequestHeader("Content-type","application/x-www-form-urlencoded"),r.overrideMimeType&&r.overrideMimeType("application/json");var l=e.customHeaders;if(l="function"==typeof l?l():l)for(var u in l)r.setRequestHeader(u,l[u]);r.onreadystatechange=function(){r.readyState>3&&n&&n(r.responseText,r)},r.send(o)}catch(t){console&&console.log(t)}}function u(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"/locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:JSON.parse,parsePayload:function(t,e,n){return function(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}({},e,n||"")},crossDomain:!1,ajax:l}}var c=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.init(t,n),this.type="backend"}var n,o,r;return n=e,(o=[{key:"init",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.services=t,this.options=i(e,this.options||{},u())}},{key:"readMulti",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath(t,e));var i=this.services.interpolator.interpolate(o,{lng:t.join("+"),ns:e.join("+")});this.loadUrl(i,n)}},{key:"read",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath([t],[e]));var i=this.services.interpolator.interpolate(o,{lng:t,ns:e});this.loadUrl(i,n)}},{key:"loadUrl",value:function(t,e){var n=this;this.options.ajax(t,this.options,(function(o,i){if(i.status>=500&&i.status<600)return e("failed loading "+t,!0);if(i.status>=400&&i.status<500)return e("failed loading "+t,!1);var r,a;try{r=n.options.parse(o,t)}catch(e){a="failed parsing "+t+" to json"}if(a)return e(a,!1);e(null,r)}))}},{key:"create",value:function(t,e,n,o){var i=this;"string"==typeof t&&(t=[t]);var r=this.options.parsePayload(e,n,o);t.forEach((function(t){var n=i.services.interpolator.interpolate(i.options.addPath,{lng:t,ns:e});i.options.ajax(n,i.options,(function(t,e){}),r)}))}}])&&t(n.prototype,o),r&&t(n,r),e}();return c.type="backend",c}));
|
266
node_modules/i18next-xhr-backend/i18nextXHRBackend.js
generated
vendored
Normal file
266
node_modules/i18next-xhr-backend/i18nextXHRBackend.js
generated
vendored
Normal file
@@ -0,0 +1,266 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, global.i18nextXHRBackend = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function _defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) _defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
}
|
||||
|
||||
function _defineProperty(obj, key, value) {
|
||||
if (key in obj) {
|
||||
Object.defineProperty(obj, key, {
|
||||
value: value,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
} else {
|
||||
obj[key] = value;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
var arr = [];
|
||||
var each = arr.forEach;
|
||||
var slice = arr.slice;
|
||||
function defaults(obj) {
|
||||
each.call(slice.call(arguments, 1), function (source) {
|
||||
if (source) {
|
||||
for (var prop in source) {
|
||||
if (obj[prop] === undefined) obj[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); }
|
||||
|
||||
function _typeof(obj) {
|
||||
if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
|
||||
_typeof = function _typeof(obj) {
|
||||
return _typeof2(obj);
|
||||
};
|
||||
} else {
|
||||
_typeof = function _typeof(obj) {
|
||||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
|
||||
};
|
||||
}
|
||||
|
||||
return _typeof(obj);
|
||||
}
|
||||
|
||||
function addQueryString(url, params) {
|
||||
if (params && _typeof(params) === 'object') {
|
||||
var queryString = '',
|
||||
e = encodeURIComponent; // Must encode data
|
||||
|
||||
for (var paramName in params) {
|
||||
queryString += '&' + e(paramName) + '=' + e(params[paramName]);
|
||||
}
|
||||
|
||||
if (!queryString) {
|
||||
return url;
|
||||
}
|
||||
|
||||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1);
|
||||
}
|
||||
|
||||
return url;
|
||||
} // https://gist.github.com/Xeoncross/7663273
|
||||
|
||||
|
||||
function ajax(url, options, callback, data, cache) {
|
||||
if (data && _typeof(data) === 'object') {
|
||||
if (!cache) {
|
||||
data['_t'] = new Date();
|
||||
} // URL encoded form data must be in querystring format
|
||||
|
||||
|
||||
data = addQueryString('', data).slice(1);
|
||||
}
|
||||
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
|
||||
try {
|
||||
var x;
|
||||
|
||||
if (XMLHttpRequest) {
|
||||
x = new XMLHttpRequest();
|
||||
} else {
|
||||
x = new ActiveXObject('MSXML2.XMLHTTP.3.0');
|
||||
}
|
||||
|
||||
x.open(data ? 'POST' : 'GET', url, 1);
|
||||
|
||||
if (!options.crossDomain) {
|
||||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
}
|
||||
|
||||
x.withCredentials = !!options.withCredentials;
|
||||
|
||||
if (data) {
|
||||
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
|
||||
if (x.overrideMimeType) {
|
||||
x.overrideMimeType("application/json");
|
||||
}
|
||||
|
||||
var h = options.customHeaders;
|
||||
h = typeof h === 'function' ? h() : h;
|
||||
|
||||
if (h) {
|
||||
for (var i in h) {
|
||||
x.setRequestHeader(i, h[i]);
|
||||
}
|
||||
}
|
||||
|
||||
x.onreadystatechange = function () {
|
||||
x.readyState > 3 && callback && callback(x.responseText, x);
|
||||
};
|
||||
|
||||
x.send(data);
|
||||
} catch (e) {
|
||||
console && console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
allowMultiLoading: false,
|
||||
parse: JSON.parse,
|
||||
parsePayload: function parsePayload(namespace, key, fallbackValue) {
|
||||
return _defineProperty({}, key, fallbackValue || '');
|
||||
},
|
||||
crossDomain: false,
|
||||
ajax: ajax
|
||||
};
|
||||
}
|
||||
|
||||
var Backend =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Backend(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, Backend);
|
||||
|
||||
this.init(services, options);
|
||||
this.type = 'backend';
|
||||
}
|
||||
|
||||
_createClass(Backend, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
this.services = services;
|
||||
this.options = defaults(options, this.options || {}, getDefaults());
|
||||
}
|
||||
}, {
|
||||
key: "readMulti",
|
||||
value: function readMulti(languages, namespaces, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath(languages, namespaces);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, {
|
||||
lng: languages.join('+'),
|
||||
ns: namespaces.join('+')
|
||||
});
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: "read",
|
||||
value: function read(language, namespace, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath([language], [namespace]);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, {
|
||||
lng: language,
|
||||
ns: namespace
|
||||
});
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: "loadUrl",
|
||||
value: function loadUrl(url, callback) {
|
||||
var _this = this;
|
||||
|
||||
this.options.ajax(url, this.options, function (data, xhr) {
|
||||
if (xhr.status >= 500 && xhr.status < 600) return callback('failed loading ' + url, true
|
||||
/* retry */
|
||||
);
|
||||
if (xhr.status >= 400 && xhr.status < 500) return callback('failed loading ' + url, false
|
||||
/* no retry */
|
||||
);
|
||||
var ret, err;
|
||||
|
||||
try {
|
||||
ret = _this.options.parse(data, url);
|
||||
} catch (e) {
|
||||
err = 'failed parsing ' + url + ' to json';
|
||||
}
|
||||
|
||||
if (err) return callback(err, false);
|
||||
callback(null, ret);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "create",
|
||||
value: function create(languages, namespace, key, fallbackValue) {
|
||||
var _this2 = this;
|
||||
|
||||
if (typeof languages === 'string') languages = [languages];
|
||||
var payload = this.options.parsePayload(namespace, key, fallbackValue);
|
||||
languages.forEach(function (lng) {
|
||||
var url = _this2.services.interpolator.interpolate(_this2.options.addPath, {
|
||||
lng: lng,
|
||||
ns: namespace
|
||||
});
|
||||
|
||||
_this2.options.ajax(url, _this2.options, function (data, xhr) {//const statusCode = xhr.status.toString();
|
||||
// TODO: if statusCode === 4xx do log
|
||||
}, payload);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Backend;
|
||||
}();
|
||||
|
||||
Backend.type = 'backend';
|
||||
|
||||
return Backend;
|
||||
|
||||
})));
|
1
node_modules/i18next-xhr-backend/i18nextXHRBackend.min.js
generated
vendored
Normal file
1
node_modules/i18next-xhr-backend/i18nextXHRBackend.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).i18nextXHRBackend=e()}(this,(function(){"use strict";function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var e=[],n=e.forEach,o=e.slice;function i(t){return n.call(o.call(arguments,1),(function(e){if(e)for(var n in e)void 0===t[n]&&(t[n]=e[n])})),t}function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(t){return(a="function"==typeof Symbol&&"symbol"===r(Symbol.iterator)?function(t){return r(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":r(t)})(t)}function s(t,e){if(e&&"object"===a(e)){var n="",o=encodeURIComponent;for(var i in e)n+="&"+o(i)+"="+o(e[i]);if(!n)return t;t=t+(-1!==t.indexOf("?")?"&":"?")+n.slice(1)}return t}function l(t,e,n,o,i){o&&"object"===a(o)&&(i||(o._t=new Date),o=s("",o).slice(1)),e.queryStringParams&&(t=s(t,e.queryStringParams));try{var r;(r=XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0")).open(o?"POST":"GET",t,1),e.crossDomain||r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.withCredentials=!!e.withCredentials,o&&r.setRequestHeader("Content-type","application/x-www-form-urlencoded"),r.overrideMimeType&&r.overrideMimeType("application/json");var l=e.customHeaders;if(l="function"==typeof l?l():l)for(var u in l)r.setRequestHeader(u,l[u]);r.onreadystatechange=function(){r.readyState>3&&n&&n(r.responseText,r)},r.send(o)}catch(t){console&&console.log(t)}}function u(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"/locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:JSON.parse,parsePayload:function(t,e,n){return function(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}({},e,n||"")},crossDomain:!1,ajax:l}}var c=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.init(t,n),this.type="backend"}var n,o,r;return n=e,(o=[{key:"init",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.services=t,this.options=i(e,this.options||{},u())}},{key:"readMulti",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath(t,e));var i=this.services.interpolator.interpolate(o,{lng:t.join("+"),ns:e.join("+")});this.loadUrl(i,n)}},{key:"read",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath([t],[e]));var i=this.services.interpolator.interpolate(o,{lng:t,ns:e});this.loadUrl(i,n)}},{key:"loadUrl",value:function(t,e){var n=this;this.options.ajax(t,this.options,(function(o,i){if(i.status>=500&&i.status<600)return e("failed loading "+t,!0);if(i.status>=400&&i.status<500)return e("failed loading "+t,!1);var r,a;try{r=n.options.parse(o,t)}catch(e){a="failed parsing "+t+" to json"}if(a)return e(a,!1);e(null,r)}))}},{key:"create",value:function(t,e,n,o){var i=this;"string"==typeof t&&(t=[t]);var r=this.options.parsePayload(e,n,o);t.forEach((function(t){var n=i.services.interpolator.interpolate(i.options.addPath,{lng:t,ns:e});i.options.ajax(n,i.options,(function(t,e){}),r)}))}}])&&t(n.prototype,o),r&&t(n,r),e}();return c.type="backend",c}));
|
77
node_modules/i18next-xhr-backend/index.d.ts
generated
vendored
Normal file
77
node_modules/i18next-xhr-backend/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
import { BackendModule, ReadCallback } from 'i18next';
|
||||
|
||||
type LoadPathOption = string | ((lngs: string[], namespaces: string[]) => string);
|
||||
|
||||
interface BackendOptions {
|
||||
/**
|
||||
* path where resources get loaded from, or a function
|
||||
* returning a path:
|
||||
* function(lngs, namespaces) { return customPath; }
|
||||
* the returned path will interpolate lng, ns if provided like giving a static path
|
||||
*/
|
||||
loadPath?: LoadPathOption;
|
||||
/**
|
||||
* path to post missing resources
|
||||
*/
|
||||
addPath?: string;
|
||||
/**
|
||||
* your backend server supports multiLoading
|
||||
* locales/resources.json?lng=de+en&ns=ns1+ns2
|
||||
* set loadPath: '/locales/resources.json?lng={{lng}}&ns={{ns}}' to adapt to multiLoading
|
||||
*/
|
||||
allowMultiLoading?: boolean;
|
||||
/**
|
||||
* parse data after it has been fetched
|
||||
* in example use https://www.npmjs.com/package/json5
|
||||
* here it removes the letter a from the json (bad idea)
|
||||
*/
|
||||
parse?(data: string): string;
|
||||
/**
|
||||
* parse data before it has been sent by addPath
|
||||
*/
|
||||
parsePayload?(namespace: string, key: string, fallbackValue?: string): { [key: string]: any };
|
||||
/**
|
||||
* allow cross domain requests
|
||||
*/
|
||||
crossDomain?: boolean;
|
||||
/**
|
||||
* allow credentials on cross domain requests
|
||||
*/
|
||||
withCredentials?: boolean;
|
||||
/**
|
||||
* define a custom xhr function
|
||||
* can be used to support XDomainRequest in IE 8 and 9
|
||||
*/
|
||||
ajax?(
|
||||
url: string,
|
||||
options: BackendOptions,
|
||||
callback: AjaxRequestCallback,
|
||||
data: {} | string,
|
||||
cache: boolean,
|
||||
): void;
|
||||
/**
|
||||
* adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5'
|
||||
*/
|
||||
queryStringParams?: { [key: string]: string };
|
||||
|
||||
/**
|
||||
* @see https://github.com/i18next/i18next-xhr-backend/blob/281c7e235e1157b33122adacef1957252e5700f1/src/ajax.js#L52
|
||||
*/
|
||||
customHeaders?: { [key: string]: string };
|
||||
}
|
||||
|
||||
type AjaxRequestCallback = (response: string, x: XMLHttpRequest) => void;
|
||||
|
||||
// type LoadCallback = (error: any, result: string | false) => void;
|
||||
|
||||
export default class I18NextXhrBackend implements BackendModule<BackendOptions> {
|
||||
constructor(services?: any, options?: BackendOptions);
|
||||
init(services?: any, options?: BackendOptions): void;
|
||||
readMulti(languages: string[], namespaces: string[], callback: ReadCallback): void;
|
||||
read(language: string, namespace: string, callback: ReadCallback): void;
|
||||
loadUrl(url: string, callback: ReadCallback): void;
|
||||
create(languages: string | string[], namespace: string, key: string, fallbackValue: string): void;
|
||||
type: 'backend';
|
||||
services: any;
|
||||
options: BackendOptions;
|
||||
}
|
5
node_modules/i18next-xhr-backend/index.js
generated
vendored
Normal file
5
node_modules/i18next-xhr-backend/index.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/* eslint no-var: 0 */
|
||||
var main = require('./dist/cjs/i18nextXHRBackend.js').default;
|
||||
|
||||
module.exports = main;
|
||||
module.exports.default = main;
|
105
node_modules/i18next-xhr-backend/package.json
generated
vendored
Normal file
105
node_modules/i18next-xhr-backend/package.json
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
{
|
||||
"_from": "i18next-xhr-backend@^3.2.2",
|
||||
"_id": "i18next-xhr-backend@3.2.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-OtRf2Vo3IqAxsttQbpjYnmMML12IMB5e0fc5B7qKJFLScitYaXa1OhMX0n0X/3vrfFlpHL9Ro/H+ps4Ej2j7QQ==",
|
||||
"_location": "/i18next-xhr-backend",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "i18next-xhr-backend@^3.2.2",
|
||||
"name": "i18next-xhr-backend",
|
||||
"escapedName": "i18next-xhr-backend",
|
||||
"rawSpec": "^3.2.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^3.2.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/i18next-xhr-backend/-/i18next-xhr-backend-3.2.2.tgz",
|
||||
"_shasum": "769124441461b085291f539d91864e3691199178",
|
||||
"_spec": "i18next-xhr-backend@^3.2.2",
|
||||
"_where": "D:\\Projects\\siag\\vanillajs-seed",
|
||||
"author": {
|
||||
"name": "Jan Mühlemann",
|
||||
"email": "jan.muehlemann@gmail.com",
|
||||
"url": "https://github.com/jamuhl"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/i18next/i18next-xhr-backend/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.5.5"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "backend layer for i18next using browsers xhr",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.5.5",
|
||||
"@babel/plugin-transform-runtime": "^7.5.5",
|
||||
"@babel/preset-env": "^7.5.5",
|
||||
"babel-eslint": "^10.0.2",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"babelify": "^10.0.0",
|
||||
"browserify": "16.3.0",
|
||||
"browserify-istanbul": "3.0.1",
|
||||
"chai": "4.2.0",
|
||||
"coveralls": "3.0.5",
|
||||
"cpy-cli": "^2.0.0",
|
||||
"dtslint": "^0.9.0",
|
||||
"eslint": "6.1.0",
|
||||
"eslint-config-airbnb": "17.1.1",
|
||||
"i18next": "^19.0.0",
|
||||
"istanbul": "github:gotwarlost/istanbul#source-map",
|
||||
"json5": "2.1.0",
|
||||
"karma": "4.2.0",
|
||||
"karma-browserify": "6.1.0",
|
||||
"karma-chai": "0.1.0",
|
||||
"karma-chrome-launcher": "3.0.0",
|
||||
"karma-cli": "2.0.0",
|
||||
"karma-coverage": "github:douglasduteil/karma-coverage#next",
|
||||
"karma-coveralls": "2.1.0",
|
||||
"karma-expect": "1.1.3",
|
||||
"karma-mocha": "1.3.0",
|
||||
"karma-phantomjs-launcher": "1.0.4",
|
||||
"karma-sinon": "1.0.5",
|
||||
"karma-spec-reporter": "0.0.32",
|
||||
"mocha": "6.2.0",
|
||||
"phantomjs-prebuilt": "2.1.16",
|
||||
"rimraf": "2.6.3",
|
||||
"rollup": "^1.18.0",
|
||||
"rollup-plugin-babel": "^4.3.3",
|
||||
"rollup-plugin-node-resolve": "^5.2.0",
|
||||
"rollup-plugin-terser": "^5.1.1",
|
||||
"sinon": "7.3.2",
|
||||
"tslint": "^5.18.0",
|
||||
"typescript": "^3.5.3"
|
||||
},
|
||||
"homepage": "https://github.com/i18next/i18next-xhr-backend",
|
||||
"keywords": [
|
||||
"i18next",
|
||||
"i18next-backend"
|
||||
],
|
||||
"license": "MIT",
|
||||
"lock": false,
|
||||
"main": "./dist/cjs/i18nextXHRBackend.js",
|
||||
"module": "./dist/esm/i18nextXHRBackend.js",
|
||||
"name": "i18next-xhr-backend",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/i18next/i18next-xhr-backend.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rimraf dist && rollup -c && cpy \"./dist/umd/*.js\" ./",
|
||||
"postversion": "git push && git push --tags",
|
||||
"pretest": "npm run test:typescript",
|
||||
"preversion": "npm run test && npm run build && git push",
|
||||
"tdd": "karma start karma.conf.js",
|
||||
"test": "karma start karma.conf.js --singleRun",
|
||||
"test:typescript": "tslint --project tsconfig.json"
|
||||
},
|
||||
"types": "./index.d.ts",
|
||||
"version": "3.2.2"
|
||||
}
|
55
node_modules/i18next-xhr-backend/rollup.config.js
generated
vendored
Normal file
55
node_modules/i18next-xhr-backend/rollup.config.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
import babel from 'rollup-plugin-babel';
|
||||
import nodeResolve from 'rollup-plugin-node-resolve';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
import pkg from './package.json';
|
||||
|
||||
const getBabelOptions = ({ useESModules }) => ({
|
||||
exclude: /node_modules/,
|
||||
runtimeHelpers: true,
|
||||
plugins: [
|
||||
['@babel/transform-runtime', { useESModules }]
|
||||
]
|
||||
});
|
||||
|
||||
const input = './src/index.js';
|
||||
const name = 'i18nextXHRBackend'
|
||||
// check relative and absolute paths for windows and unix
|
||||
const external = id => !id.startsWith('.') && !id.startsWith('/') && !id.includes(':');
|
||||
|
||||
export default [
|
||||
{
|
||||
input,
|
||||
output: { format: 'cjs', file: pkg.main },
|
||||
external,
|
||||
plugins: [
|
||||
babel(getBabelOptions({ useESModules: false }))
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
input,
|
||||
output: { format: 'esm', file: pkg.module },
|
||||
external,
|
||||
plugins: [
|
||||
babel(getBabelOptions({ useESModules: true }))
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
input,
|
||||
output: { format: 'umd', name, file: `dist/umd/${name}.js` },
|
||||
plugins: [
|
||||
babel(getBabelOptions({ useESModules: true })),
|
||||
nodeResolve()
|
||||
],
|
||||
},
|
||||
{
|
||||
input,
|
||||
output: { format: 'umd', name, file: `dist/umd/${name}.min.js` },
|
||||
plugins: [
|
||||
babel(getBabelOptions({ useESModules: true })),
|
||||
nodeResolve(),
|
||||
terser()
|
||||
],
|
||||
}
|
||||
]
|
15
node_modules/i18next-xhr-backend/tsconfig.json
generated
vendored
Normal file
15
node_modules/i18next-xhr-backend/tsconfig.json
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": ["es6", "dom"],
|
||||
"jsx": "react",
|
||||
"moduleResolution": "node",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"baseUrl": ".",
|
||||
"paths": { "i18next-xhr-backend": ["./index.d.ts"] }
|
||||
},
|
||||
"include": ["./index.d.ts", "./test/**/*.ts*"]
|
||||
}
|
8
node_modules/i18next-xhr-backend/tslint.json
generated
vendored
Normal file
8
node_modules/i18next-xhr-backend/tslint.json
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"defaultSeverity": "error",
|
||||
"extends": "dtslint/dtslint.json",
|
||||
"rules": {
|
||||
"semicolon": false,
|
||||
"no-null-undefined-union": false
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user