Add internationalization support with astro-i18next integration
- Implemented astro-i18next for multi-language support, including English, Dutch, and Italian. - Configured default locale and language fallback settings. - Defined routes for localized content in the configuration. - Updated package.json and package-lock.json to include new dependencies for i18next and related plugins.
This commit is contained in:
88
node_modules/i18next-http-backend/CHANGELOG.md
generated
vendored
Normal file
88
node_modules/i18next-http-backend/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
### 2.7.3
|
||||
|
||||
- optimize fetchApi selector [backported]
|
||||
|
||||
### 2.7.1
|
||||
|
||||
- same as 2.6.2
|
||||
|
||||
### 2.7.0
|
||||
|
||||
- deprecated, same as v3.0.0
|
||||
|
||||
### 2.6.2
|
||||
|
||||
- improve network error detection across browsers [152](https://github.com/i18next/i18next-http-backend/pull/152)
|
||||
|
||||
### 2.6.1
|
||||
|
||||
- optimize "Failed to fetch" retry case [147](https://github.com/i18next/i18next-http-backend/issues/147)
|
||||
|
||||
### 2.6.0
|
||||
|
||||
- fix "Failed to fetch" retry case [147](https://github.com/i18next/i18next-http-backend/issues/147)
|
||||
|
||||
### 2.5.2
|
||||
|
||||
- dereference timers in node.js so that the process may exit when finished [139](https://github.com/i18next/i18next-http-backend/pull/139)
|
||||
|
||||
### 2.5.1
|
||||
|
||||
- fix: remove typeof window.document === 'undefined' check which deopt bundle optimization [137](https://github.com/i18next/i18next-http-backend/pull/137)
|
||||
|
||||
### 2.5.0
|
||||
|
||||
- added fetch interceptor to the Backend Options [133](https://github.com/i18next/i18next-http-backend/pull/133)
|
||||
|
||||
### 2.4.3
|
||||
|
||||
- fix: overriding options
|
||||
|
||||
### 2.4.2
|
||||
|
||||
- fix: mjs typings export
|
||||
|
||||
### 2.4.1
|
||||
|
||||
- fix: separate cjs and mjs typings
|
||||
|
||||
### 2.3.1
|
||||
|
||||
- fix for browser usage
|
||||
|
||||
### 2.3.0
|
||||
|
||||
- update deps
|
||||
|
||||
### 2.2.2
|
||||
|
||||
- hack for debug mode in react-native
|
||||
|
||||
### 2.2.1
|
||||
|
||||
- fix for types moduleResolution "node16"
|
||||
|
||||
### 2.2.0
|
||||
|
||||
- parseLoadPayload for POST request [110](https://github.com/i18next/i18next-http-backend/pull/110)
|
||||
|
||||
### 2.1.1
|
||||
|
||||
- regression fix for saveMissing signature [1890](https://github.com/i18next/i18next/issues/1890)
|
||||
|
||||
### 2.1.0
|
||||
|
||||
- typescript: export the backend options type [105](https://github.com/i18next/i18next-http-backend/pull/105)
|
||||
|
||||
### 2.0.2
|
||||
|
||||
- typescript: static type prop
|
||||
|
||||
### 2.0.1
|
||||
|
||||
- fix if url starts with file:// [100](https://github.com/i18next/i18next-http-backend/issues/100)
|
||||
|
||||
### 2.0.0
|
||||
|
||||
- typescript: update for major i18next version
|
||||
|
246
node_modules/i18next-http-backend/README.md
generated
vendored
Normal file
246
node_modules/i18next-http-backend/README.md
generated
vendored
Normal file
@@ -0,0 +1,246 @@
|
||||
# Introduction
|
||||
|
||||
[](https://github.com/i18next/i18next-http-backend/actions?query=workflow%3Anode)
|
||||
[](https://github.com/i18next/i18next-http-backend/actions?query=workflow%3Adeno)
|
||||
[](https://www.npmjs.com/package/i18next-http-backend)
|
||||
|
||||
This is a simple i18next backend to be used in Node.js, in the browser and for Deno. It will load resources from a backend server using the XMLHttpRequest or the fetch API.
|
||||
|
||||
Get a first idea on how it is used in [this i18next crash course video](https://youtu.be/SA_9i4TtxLQ?t=953).
|
||||
|
||||
It's based on the deprecated [i18next-xhr-backend](https://github.com/i18next/i18next-xhr-backend) and can mostly be used as a drop-in replacement.
|
||||
|
||||
*[Why i18next-xhr-backend was deprecated?](https://github.com/i18next/i18next-xhr-backend/issues/348#issuecomment-663060275)*
|
||||
|
||||
## Advice:
|
||||
|
||||
If you don't like to manage your translation files manually or are simply looking for a [better management solution](https://locize.com), take a look at [i18next-locize-backend](https://github.com/locize/i18next-locize-backend). The i18next [backed plugin](https://www.i18next.com/overview/plugins-and-utils#backends) for 🌐 [locize](https://locize.com) ☁️.
|
||||
|
||||
*To see [i18next-locize-backend](https://github.com/locize/i18next-locize-backend) in a working app example, check out:*
|
||||
|
||||
- *[this react-tutorial](https://github.com/locize/react-tutorial) starting from [Step 2](https://github.com/locize/react-tutorial#step-2---use-the-locize-cdn)*
|
||||
- *[this guide](https://locize.com/blog/react-i18next/) starting from the step of [replacing i18next-http-backend with i18next-locize-backend](https://locize.com/blog/react-i18next/#how-look)*
|
||||
- *[this Angular blog post](https://locize.com/blog/angular-i18next/) [introducing i18next-locize-backend](https://locize.com/blog/angular-i18next/#how-look)*
|
||||
- *[the code integration part](https://www.youtube.com/watch?v=TFV_vhJs5DY&t=294s) in this [YouTube video](https://www.youtube.com/watch?v=TFV_vhJs5DY)*
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Make sure you set the `debug` option of i18next to `true`. This will maybe log more information in the developer console.
|
||||
|
||||
**Seeing failed http requests, like 404?**
|
||||
|
||||
Are you using a [language detector](https://github.com/i18next/i18next-browser-languageDetector) plugin that detects region specific languages you are not providing? i.e. you provide `'en'` translations but you see a `'en-US'` request first?
|
||||
|
||||
This is because of the default `load` [option](https://www.i18next.com/overview/configuration-options) set to `'all'`.
|
||||
|
||||
Try to set the `load` [option](https://www.i18next.com/overview/configuration-options) to `'languageOnly'`
|
||||
|
||||
```javascript
|
||||
i18next.init({
|
||||
load: 'languageOnly',
|
||||
// other options
|
||||
})
|
||||
```
|
||||
|
||||
# Getting started
|
||||
|
||||
Source can be loaded via [npm](https://www.npmjs.com/package/i18next-http-backend) or [downloaded](https://github.com/i18next/i18next-http-backend/blob/master/i18nextHttpBackend.min.js) from this repo.
|
||||
|
||||
There's also the possibility to directly import it via a CDN like [jsdelivr](https://cdn.jsdelivr.net/npm/i18next-http-backend@1.3.1/i18nextHttpBackend.min.js) or [unpkg](https://unpkg.com/i18next-http-backend@1.3.1/i18nextHttpBackend.min.js) or similar.
|
||||
|
||||
```bash
|
||||
# npm package
|
||||
$ npm install i18next-http-backend
|
||||
```
|
||||
|
||||
Wiring up:
|
||||
|
||||
```js
|
||||
import i18next from 'i18next';
|
||||
import HttpApi from 'i18next-http-backend';
|
||||
|
||||
i18next.use(HttpApi).init(i18nextOptions);
|
||||
```
|
||||
|
||||
for Deno:
|
||||
|
||||
```js
|
||||
import i18next from 'https://deno.land/x/i18next/index.js'
|
||||
import Backend from 'https://deno.land/x/i18next_http_backend/index.js'
|
||||
|
||||
i18next.use(Backend).init(i18nextOptions);
|
||||
```
|
||||
|
||||
for plain browser:
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/i18next-http-backend@1.3.1/i18nextHttpBackend.min.js"></script>
|
||||
<!-- an example can be found in example/jquery/index.html -->
|
||||
```
|
||||
|
||||
```js
|
||||
i18next.use(i18nextHttpBackend).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.i18nextHttpBackend`
|
||||
|
||||
## 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
|
||||
// the function might return a promise
|
||||
// returning falsy will abort the download
|
||||
//
|
||||
// If not used with i18next-multiload-backend-adapter, lngs and namespaces will have only one element each,
|
||||
// If used with i18next-multiload-backend-adapter, lngs and namespaces can have multiple elements
|
||||
// and also your server needs to support 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
|
||||
// }
|
||||
// }
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
|
||||
// path to post missing resources, or a function
|
||||
// function(lng, namespace) { return customPath; }
|
||||
// the returned path will interpolate lng, ns if provided like giving a static path
|
||||
//
|
||||
// note that this only works when initialized with { saveMissing: true }
|
||||
// (see https://www.i18next.com/overview/configuration-options)
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
|
||||
// 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: fallbackValue || "" } },
|
||||
|
||||
// parse data before it has been sent by loadPath
|
||||
// if value returned it will send a POST request
|
||||
parseLoadPayload: function(languages, namespaces) { return undefined },
|
||||
|
||||
// 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',
|
||||
// ...
|
||||
},
|
||||
// can also be a function, that returns the headers
|
||||
customHeaders: () => ({
|
||||
authorization: 'foo',
|
||||
// ...
|
||||
}),
|
||||
|
||||
requestOptions: { // used for fetch, can also be a function (payload) => ({ method: 'GET' })
|
||||
mode: 'cors',
|
||||
credentials: 'same-origin',
|
||||
cache: 'default'
|
||||
},
|
||||
|
||||
// define a custom request function
|
||||
// can be used to support XDomainRequest in IE 8 and 9
|
||||
//
|
||||
// 'options' will be this entire options object
|
||||
// 'url' will be passed the value of 'loadPath'
|
||||
// 'payload' will be a key:value object used when saving missing translations
|
||||
// 'callback' is a function that takes two parameters, 'err' and 'res'.
|
||||
// 'err' should be an error
|
||||
// 'res' should be an object with a 'status' property and a 'data' property containing a stringified object instance beeing the key:value translation pairs for the
|
||||
// requested language and namespace, or null in case of an error.
|
||||
request: function (options, url, payload, callback) {},
|
||||
|
||||
// adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5'
|
||||
queryStringParams: { v: '1.3.5' },
|
||||
|
||||
reloadInterval: false // can be used to reload resources in a specific interval (milliseconds) (useful in server environments)
|
||||
}
|
||||
```
|
||||
|
||||
Options can be passed in:
|
||||
|
||||
**preferred** - by setting options.backend in i18next.init:
|
||||
|
||||
```js
|
||||
import i18next from 'i18next';
|
||||
import HttpApi from 'i18next-http-backend';
|
||||
|
||||
i18next.use(HttpApi).init({
|
||||
backend: options,
|
||||
});
|
||||
```
|
||||
|
||||
on construction:
|
||||
|
||||
```js
|
||||
import HttpApi from 'i18next-http-backend';
|
||||
const HttpApi = new HttpApi(null, options);
|
||||
```
|
||||
|
||||
via calling init:
|
||||
|
||||
```js
|
||||
import HttpApi from 'i18next-http-backend';
|
||||
const HttpApi = new HttpApi();
|
||||
HttpApi.init(null, options);
|
||||
```
|
||||
|
||||
## TypeScript
|
||||
|
||||
To properly type the backend options, you can import the `HttpBackendOptions` interface and use it as a generic type parameter to the i18next's `init` method, e.g.:
|
||||
|
||||
```ts
|
||||
import i18n from 'i18next'
|
||||
import HttpBackend, { HttpBackendOptions } from 'i18next-http-backend'
|
||||
|
||||
i18n
|
||||
.use(HttpBackend)
|
||||
.init<HttpBackendOptions>({
|
||||
backend: {
|
||||
// http backend options
|
||||
},
|
||||
|
||||
// other i18next options
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
<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>
|
||||
|
||||
---
|
||||
|
||||
**From the creators of i18next: localization as a service - locize.com**
|
||||
|
||||
A translation management system built around the i18next ecosystem - [locize.com](https://locize.com).
|
||||
|
||||

|
||||
|
||||
With using [locize](http://locize.com/?utm_source=react_i18next_readme&utm_medium=github) you directly support the future of i18next.
|
||||
|
||||
---
|
13
node_modules/i18next-http-backend/cjs/getFetch.js
generated
vendored
Normal file
13
node_modules/i18next-http-backend/cjs/getFetch.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
var fetchApi = typeof fetch === 'function' ? fetch : undefined
|
||||
if (typeof global !== 'undefined' && global.fetch) {
|
||||
fetchApi = global.fetch
|
||||
} else if (typeof window !== 'undefined' && window.fetch) {
|
||||
fetchApi = window.fetch
|
||||
}
|
||||
|
||||
if (typeof require !== 'undefined' && typeof window === 'undefined') {
|
||||
var f = fetchApi || require('cross-fetch')
|
||||
if (f.default) f = f.default
|
||||
exports.default = f
|
||||
module.exports = exports.default
|
||||
}
|
140
node_modules/i18next-http-backend/cjs/index.d.ts
generated
vendored
Normal file
140
node_modules/i18next-http-backend/cjs/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
import { BackendModule, MultiReadCallback, ReadCallback, ResourceKey } from "i18next";
|
||||
|
||||
type LoadPathOption =
|
||||
| string
|
||||
| ((lngs: string[], namespaces: string[]) => string)
|
||||
| ((lngs: string[], namespaces: string[]) => Promise<string>);
|
||||
|
||||
type AddPathOption =
|
||||
| string
|
||||
| ((lng: string, namespace: string) => string);
|
||||
|
||||
type FetchFunction = (input: string, init: RequestInit) => Promise<Response> | void
|
||||
|
||||
export interface HttpBackendOptions {
|
||||
/**
|
||||
* Use an alternative fetch function that acts like an interecept, (usefull for low level mocks/simulations)
|
||||
*
|
||||
* This option is not called if:
|
||||
*
|
||||
* 1. There is an custom value set for the "request" property in this options object.
|
||||
* 2. The backend selected xmlHttpRequest over fetch
|
||||
*
|
||||
* If the function is called and it returns anything BUT a promise the fetch or xmlHttpRequest will be subsequentially called
|
||||
*
|
||||
*/
|
||||
alternateFetch?: FetchFunction;
|
||||
/**
|
||||
* 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, must be `string` or a `function` returning a path:
|
||||
* function(lng, namespace) { return customPath; }
|
||||
*/
|
||||
addPath?: AddPathOption;
|
||||
/**
|
||||
* 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,
|
||||
languages?: string | string[],
|
||||
namespaces?: string | string[]
|
||||
): { [key: string]: any };
|
||||
/**
|
||||
* parse data before it has been sent by addPath
|
||||
*/
|
||||
parsePayload?(
|
||||
namespace: string,
|
||||
key: string,
|
||||
fallbackValue?: string
|
||||
): { [key: string]: any };
|
||||
/**
|
||||
* parse data before it has been sent by loadPath
|
||||
* if value returned it will send a POST request
|
||||
*/
|
||||
parseLoadPayload?(
|
||||
languages: string[],
|
||||
namespaces: string[]
|
||||
): { [key: string]: any } | undefined;
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
request?(
|
||||
options: HttpBackendOptions,
|
||||
url: string,
|
||||
payload: {} | string,
|
||||
callback: RequestCallback
|
||||
): void;
|
||||
/**
|
||||
* adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5'
|
||||
*/
|
||||
queryStringParams?: { [key: string]: string };
|
||||
|
||||
/**
|
||||
* allows an object containing custom headers or a function that when called returns
|
||||
* an object of custom headers
|
||||
*/
|
||||
customHeaders?: { [key: string]: string } | (() => { [key: string]: string });
|
||||
|
||||
/**
|
||||
* can be used to reload resources in a specific
|
||||
* interval (useful in server environments)
|
||||
*/
|
||||
reloadInterval?: false | number;
|
||||
|
||||
/**
|
||||
* fetch api request options, can be a function
|
||||
*/
|
||||
requestOptions?: RequestInit | ((payload: {} | string) => RequestInit);
|
||||
}
|
||||
|
||||
type RequestCallback = (error: any | undefined | null, response: RequestResponse | undefined | null) => void;
|
||||
|
||||
interface RequestResponse {
|
||||
status: number;
|
||||
data: ResourceKey;
|
||||
}
|
||||
|
||||
export default class I18NextHttpBackend
|
||||
implements BackendModule<HttpBackendOptions>
|
||||
{
|
||||
static type: "backend";
|
||||
constructor(services?: any, options?: HttpBackendOptions);
|
||||
init(services?: any, options?: HttpBackendOptions): void;
|
||||
readMulti?(
|
||||
languages: string[],
|
||||
namespaces: string[],
|
||||
callback: MultiReadCallback
|
||||
): void;
|
||||
read(language: string, namespace: string, callback: ReadCallback): void;
|
||||
loadUrl(
|
||||
url: string,
|
||||
callback: ReadCallback,
|
||||
languages?: string | string[],
|
||||
namespaces?: string | string[]
|
||||
): void;
|
||||
create?(
|
||||
languages: string[],
|
||||
namespace: string,
|
||||
key: string,
|
||||
fallbackValue: string
|
||||
): void;
|
||||
type: "backend";
|
||||
services: any;
|
||||
options: HttpBackendOptions;
|
||||
}
|
200
node_modules/i18next-http-backend/cjs/index.js
generated
vendored
Normal file
200
node_modules/i18next-http-backend/cjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,200 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _utils = require("./utils.js");
|
||||
var _request = _interopRequireDefault(require("./request.js"));
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
||||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
||||
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
||||
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
||||
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
||||
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
||||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
||||
var getDefaults = function getDefaults() {
|
||||
return {
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
parse: function parse(data) {
|
||||
return JSON.parse(data);
|
||||
},
|
||||
stringify: JSON.stringify,
|
||||
parsePayload: function parsePayload(namespace, key, fallbackValue) {
|
||||
return _defineProperty({}, key, fallbackValue || '');
|
||||
},
|
||||
parseLoadPayload: function parseLoadPayload(languages, namespaces) {
|
||||
return undefined;
|
||||
},
|
||||
request: _request.default,
|
||||
reloadInterval: typeof window !== 'undefined' ? false : 60 * 60 * 1000,
|
||||
customHeaders: {},
|
||||
queryStringParams: {},
|
||||
crossDomain: false,
|
||||
withCredentials: false,
|
||||
overrideMimeType: false,
|
||||
requestOptions: {
|
||||
mode: 'cors',
|
||||
credentials: 'same-origin',
|
||||
cache: 'default'
|
||||
}
|
||||
};
|
||||
};
|
||||
var Backend = function () {
|
||||
function Backend(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
_classCallCheck(this, Backend);
|
||||
this.services = services;
|
||||
this.options = options;
|
||||
this.allOptions = allOptions;
|
||||
this.type = 'backend';
|
||||
this.init(services, options, allOptions);
|
||||
}
|
||||
return _createClass(Backend, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var _this = this;
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
this.services = services;
|
||||
this.options = _objectSpread(_objectSpread(_objectSpread({}, getDefaults()), this.options || {}), options);
|
||||
this.allOptions = allOptions;
|
||||
if (this.services && this.options.reloadInterval) {
|
||||
var timer = setInterval(function () {
|
||||
return _this.reload();
|
||||
}, this.options.reloadInterval);
|
||||
if (_typeof(timer) === 'object' && typeof timer.unref === 'function') timer.unref();
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "readMulti",
|
||||
value: function readMulti(languages, namespaces, callback) {
|
||||
this._readAny(languages, languages, namespaces, namespaces, callback);
|
||||
}
|
||||
}, {
|
||||
key: "read",
|
||||
value: function read(language, namespace, callback) {
|
||||
this._readAny([language], language, [namespace], namespace, callback);
|
||||
}
|
||||
}, {
|
||||
key: "_readAny",
|
||||
value: function _readAny(languages, loadUrlLanguages, namespaces, loadUrlNamespaces, callback) {
|
||||
var _this2 = this;
|
||||
var loadPath = this.options.loadPath;
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath(languages, namespaces);
|
||||
}
|
||||
loadPath = (0, _utils.makePromise)(loadPath);
|
||||
loadPath.then(function (resolvedLoadPath) {
|
||||
if (!resolvedLoadPath) return callback(null, {});
|
||||
var url = _this2.services.interpolator.interpolate(resolvedLoadPath, {
|
||||
lng: languages.join('+'),
|
||||
ns: namespaces.join('+')
|
||||
});
|
||||
_this2.loadUrl(url, callback, loadUrlLanguages, loadUrlNamespaces);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "loadUrl",
|
||||
value: function loadUrl(url, callback, languages, namespaces) {
|
||||
var _this3 = this;
|
||||
var lng = typeof languages === 'string' ? [languages] : languages;
|
||||
var ns = typeof namespaces === 'string' ? [namespaces] : namespaces;
|
||||
var payload = this.options.parseLoadPayload(lng, ns);
|
||||
this.options.request(this.options, url, payload, function (err, res) {
|
||||
if (res && (res.status >= 500 && res.status < 600 || !res.status)) return callback('failed loading ' + url + '; status code: ' + res.status, true);
|
||||
if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url + '; status code: ' + res.status, false);
|
||||
if (!res && err && err.message) {
|
||||
var errorMessage = err.message.toLowerCase();
|
||||
var isNetworkError = ['failed', 'fetch', 'network', 'load'].find(function (term) {
|
||||
return errorMessage.indexOf(term) > -1;
|
||||
});
|
||||
if (isNetworkError) {
|
||||
return callback('failed loading ' + url + ': ' + err.message, true);
|
||||
}
|
||||
}
|
||||
if (err) return callback(err, false);
|
||||
var ret, parseErr;
|
||||
try {
|
||||
if (typeof res.data === 'string') {
|
||||
ret = _this3.options.parse(res.data, languages, namespaces);
|
||||
} else {
|
||||
ret = res.data;
|
||||
}
|
||||
} catch (e) {
|
||||
parseErr = 'failed parsing ' + url + ' to json';
|
||||
}
|
||||
if (parseErr) return callback(parseErr, false);
|
||||
callback(null, ret);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "create",
|
||||
value: function create(languages, namespace, key, fallbackValue, callback) {
|
||||
var _this4 = this;
|
||||
if (!this.options.addPath) return;
|
||||
if (typeof languages === 'string') languages = [languages];
|
||||
var payload = this.options.parsePayload(namespace, key, fallbackValue);
|
||||
var finished = 0;
|
||||
var dataArray = [];
|
||||
var resArray = [];
|
||||
languages.forEach(function (lng) {
|
||||
var addPath = _this4.options.addPath;
|
||||
if (typeof _this4.options.addPath === 'function') {
|
||||
addPath = _this4.options.addPath(lng, namespace);
|
||||
}
|
||||
var url = _this4.services.interpolator.interpolate(addPath, {
|
||||
lng: lng,
|
||||
ns: namespace
|
||||
});
|
||||
_this4.options.request(_this4.options, url, payload, function (data, res) {
|
||||
finished += 1;
|
||||
dataArray.push(data);
|
||||
resArray.push(res);
|
||||
if (finished === languages.length) {
|
||||
if (typeof callback === 'function') callback(dataArray, resArray);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "reload",
|
||||
value: function reload() {
|
||||
var _this5 = this;
|
||||
var _this$services = this.services,
|
||||
backendConnector = _this$services.backendConnector,
|
||||
languageUtils = _this$services.languageUtils,
|
||||
logger = _this$services.logger;
|
||||
var currentLanguage = backendConnector.language;
|
||||
if (currentLanguage && currentLanguage.toLowerCase() === 'cimode') return;
|
||||
var toLoad = [];
|
||||
var append = function append(lng) {
|
||||
var lngs = languageUtils.toResolveHierarchy(lng);
|
||||
lngs.forEach(function (l) {
|
||||
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
||||
});
|
||||
};
|
||||
append(currentLanguage);
|
||||
if (this.allOptions.preload) this.allOptions.preload.forEach(function (l) {
|
||||
return append(l);
|
||||
});
|
||||
toLoad.forEach(function (lng) {
|
||||
_this5.allOptions.ns.forEach(function (ns) {
|
||||
backendConnector.read(lng, ns, 'read', null, null, function (err, data) {
|
||||
if (err) logger.warn("loading namespace ".concat(ns, " for language ").concat(lng, " failed"), err);
|
||||
if (!err && data) logger.log("loaded namespace ".concat(ns, " for language ").concat(lng), data);
|
||||
backendConnector.loaded("".concat(lng, "|").concat(ns), err, data);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}]);
|
||||
}();
|
||||
Backend.type = 'backend';
|
||||
var _default = exports.default = Backend;
|
||||
module.exports = exports.default;
|
1
node_modules/i18next-http-backend/cjs/package.json
generated
vendored
Normal file
1
node_modules/i18next-http-backend/cjs/package.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"type":"commonjs"}
|
169
node_modules/i18next-http-backend/cjs/request.js
generated
vendored
Normal file
169
node_modules/i18next-http-backend/cjs/request.js
generated
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _utils = require("./utils.js");
|
||||
var fetchNode = _interopRequireWildcard(require("./getFetch.js"));
|
||||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
||||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
||||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
||||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
||||
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
||||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
var fetchApi = typeof fetch === 'function' ? fetch : undefined;
|
||||
if (typeof global !== 'undefined' && global.fetch) {
|
||||
fetchApi = global.fetch;
|
||||
} else if (typeof window !== 'undefined' && window.fetch) {
|
||||
fetchApi = window.fetch;
|
||||
}
|
||||
var XmlHttpRequestApi;
|
||||
if ((0, _utils.hasXMLHttpRequest)()) {
|
||||
if (typeof global !== 'undefined' && global.XMLHttpRequest) {
|
||||
XmlHttpRequestApi = global.XMLHttpRequest;
|
||||
} else if (typeof window !== 'undefined' && window.XMLHttpRequest) {
|
||||
XmlHttpRequestApi = window.XMLHttpRequest;
|
||||
}
|
||||
}
|
||||
var ActiveXObjectApi;
|
||||
if (typeof ActiveXObject === 'function') {
|
||||
if (typeof global !== 'undefined' && global.ActiveXObject) {
|
||||
ActiveXObjectApi = global.ActiveXObject;
|
||||
} else if (typeof window !== 'undefined' && window.ActiveXObject) {
|
||||
ActiveXObjectApi = window.ActiveXObject;
|
||||
}
|
||||
}
|
||||
if (!fetchApi && fetchNode && !XmlHttpRequestApi && !ActiveXObjectApi) fetchApi = fetchNode.default || fetchNode;
|
||||
if (typeof fetchApi !== 'function') fetchApi = undefined;
|
||||
var addQueryString = function addQueryString(url, params) {
|
||||
if (params && _typeof(params) === 'object') {
|
||||
var queryString = '';
|
||||
for (var paramName in params) {
|
||||
queryString += '&' + encodeURIComponent(paramName) + '=' + encodeURIComponent(params[paramName]);
|
||||
}
|
||||
if (!queryString) return url;
|
||||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1);
|
||||
}
|
||||
return url;
|
||||
};
|
||||
var fetchIt = function fetchIt(url, fetchOptions, callback, altFetch) {
|
||||
var resolver = function resolver(response) {
|
||||
if (!response.ok) return callback(response.statusText || 'Error', {
|
||||
status: response.status
|
||||
});
|
||||
response.text().then(function (data) {
|
||||
callback(null, {
|
||||
status: response.status,
|
||||
data: data
|
||||
});
|
||||
}).catch(callback);
|
||||
};
|
||||
if (altFetch) {
|
||||
var altResponse = altFetch(url, fetchOptions);
|
||||
if (altResponse instanceof Promise) {
|
||||
altResponse.then(resolver).catch(callback);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (typeof fetch === 'function') {
|
||||
fetch(url, fetchOptions).then(resolver).catch(callback);
|
||||
} else {
|
||||
fetchApi(url, fetchOptions).then(resolver).catch(callback);
|
||||
}
|
||||
};
|
||||
var omitFetchOptions = false;
|
||||
var requestWithFetch = function requestWithFetch(options, url, payload, callback) {
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
var headers = _objectSpread({}, typeof options.customHeaders === 'function' ? options.customHeaders() : options.customHeaders);
|
||||
if (typeof window === 'undefined' && typeof global !== 'undefined' && typeof global.process !== 'undefined' && global.process.versions && global.process.versions.node) {
|
||||
headers['User-Agent'] = "i18next-http-backend (node/".concat(global.process.version, "; ").concat(global.process.platform, " ").concat(global.process.arch, ")");
|
||||
}
|
||||
if (payload) headers['Content-Type'] = 'application/json';
|
||||
var reqOptions = typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions;
|
||||
var fetchOptions = _objectSpread({
|
||||
method: payload ? 'POST' : 'GET',
|
||||
body: payload ? options.stringify(payload) : undefined,
|
||||
headers: headers
|
||||
}, omitFetchOptions ? {} : reqOptions);
|
||||
var altFetch = typeof options.alternateFetch === 'function' && options.alternateFetch.length >= 1 ? options.alternateFetch : undefined;
|
||||
try {
|
||||
fetchIt(url, fetchOptions, callback, altFetch);
|
||||
} catch (e) {
|
||||
if (!reqOptions || Object.keys(reqOptions).length === 0 || !e.message || e.message.indexOf('not implemented') < 0) {
|
||||
return callback(e);
|
||||
}
|
||||
try {
|
||||
Object.keys(reqOptions).forEach(function (opt) {
|
||||
delete fetchOptions[opt];
|
||||
});
|
||||
fetchIt(url, fetchOptions, callback, altFetch);
|
||||
omitFetchOptions = true;
|
||||
} catch (err) {
|
||||
callback(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
var requestWithXmlHttpRequest = function requestWithXmlHttpRequest(options, url, payload, callback) {
|
||||
if (payload && _typeof(payload) === 'object') {
|
||||
payload = addQueryString('', payload).slice(1);
|
||||
}
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
try {
|
||||
var x;
|
||||
if (XmlHttpRequestApi) {
|
||||
x = new XmlHttpRequestApi();
|
||||
} else {
|
||||
x = new ActiveXObjectApi('MSXML2.XMLHTTP.3.0');
|
||||
}
|
||||
x.open(payload ? 'POST' : 'GET', url, 1);
|
||||
if (!options.crossDomain) {
|
||||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
}
|
||||
x.withCredentials = !!options.withCredentials;
|
||||
if (payload) {
|
||||
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(x.status >= 400 ? x.statusText : null, {
|
||||
status: x.status,
|
||||
data: x.responseText
|
||||
});
|
||||
};
|
||||
x.send(payload);
|
||||
} catch (e) {
|
||||
console && console.log(e);
|
||||
}
|
||||
};
|
||||
var request = function request(options, url, payload, callback) {
|
||||
if (typeof payload === 'function') {
|
||||
callback = payload;
|
||||
payload = undefined;
|
||||
}
|
||||
callback = callback || function () {};
|
||||
if (fetchApi && url.indexOf('file:') !== 0) {
|
||||
return requestWithFetch(options, url, payload, callback);
|
||||
}
|
||||
if ((0, _utils.hasXMLHttpRequest)() || typeof ActiveXObject === 'function') {
|
||||
return requestWithXmlHttpRequest(options, url, payload, callback);
|
||||
}
|
||||
callback(new Error('No fetch and no xhr implementation found!'));
|
||||
};
|
||||
var _default = exports.default = request;
|
||||
module.exports = exports.default;
|
34
node_modules/i18next-http-backend/cjs/utils.js
generated
vendored
Normal file
34
node_modules/i18next-http-backend/cjs/utils.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.defaults = defaults;
|
||||
exports.hasXMLHttpRequest = hasXMLHttpRequest;
|
||||
exports.makePromise = makePromise;
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
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 hasXMLHttpRequest() {
|
||||
return typeof XMLHttpRequest === 'function' || (typeof XMLHttpRequest === "undefined" ? "undefined" : _typeof(XMLHttpRequest)) === 'object';
|
||||
}
|
||||
function isPromise(maybePromise) {
|
||||
return !!maybePromise && typeof maybePromise.then === 'function';
|
||||
}
|
||||
function makePromise(maybePromise) {
|
||||
if (isPromise(maybePromise)) {
|
||||
return maybePromise;
|
||||
}
|
||||
return Promise.resolve(maybePromise);
|
||||
}
|
13
node_modules/i18next-http-backend/esm/getFetch.cjs
generated
vendored
Normal file
13
node_modules/i18next-http-backend/esm/getFetch.cjs
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
var fetchApi = typeof fetch === 'function' ? fetch : undefined
|
||||
if (typeof global !== 'undefined' && global.fetch) {
|
||||
fetchApi = global.fetch
|
||||
} else if (typeof window !== 'undefined' && window.fetch) {
|
||||
fetchApi = window.fetch
|
||||
}
|
||||
|
||||
if (typeof require !== 'undefined' && typeof window === 'undefined') {
|
||||
var f = fetchApi || require('cross-fetch')
|
||||
if (f.default) f = f.default
|
||||
exports.default = f
|
||||
module.exports = exports.default
|
||||
}
|
9
node_modules/i18next-http-backend/esm/index.d.mts
generated
vendored
Normal file
9
node_modules/i18next-http-backend/esm/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as index from './index.js';
|
||||
|
||||
export default index.default;
|
||||
|
||||
export type HttpBackendOptions = index.HttpBackendOptions;
|
||||
export type RequestCallback = index.RequestCallback;
|
||||
export type LoadPathOption = index.LoadPathOption;
|
||||
export type AddPathOption = index.AddPathOption;
|
||||
export type RequestResponse = index.RequestResponse;
|
140
node_modules/i18next-http-backend/esm/index.d.ts
generated
vendored
Normal file
140
node_modules/i18next-http-backend/esm/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
import { BackendModule, MultiReadCallback, ReadCallback, ResourceKey } from "i18next";
|
||||
|
||||
type LoadPathOption =
|
||||
| string
|
||||
| ((lngs: string[], namespaces: string[]) => string)
|
||||
| ((lngs: string[], namespaces: string[]) => Promise<string>);
|
||||
|
||||
type AddPathOption =
|
||||
| string
|
||||
| ((lng: string, namespace: string) => string);
|
||||
|
||||
type FetchFunction = (input: string, init: RequestInit) => Promise<Response> | void
|
||||
|
||||
export interface HttpBackendOptions {
|
||||
/**
|
||||
* Use an alternative fetch function that acts like an interecept, (usefull for low level mocks/simulations)
|
||||
*
|
||||
* This option is not called if:
|
||||
*
|
||||
* 1. There is an custom value set for the "request" property in this options object.
|
||||
* 2. The backend selected xmlHttpRequest over fetch
|
||||
*
|
||||
* If the function is called and it returns anything BUT a promise the fetch or xmlHttpRequest will be subsequentially called
|
||||
*
|
||||
*/
|
||||
alternateFetch?: FetchFunction;
|
||||
/**
|
||||
* 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, must be `string` or a `function` returning a path:
|
||||
* function(lng, namespace) { return customPath; }
|
||||
*/
|
||||
addPath?: AddPathOption;
|
||||
/**
|
||||
* 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,
|
||||
languages?: string | string[],
|
||||
namespaces?: string | string[]
|
||||
): { [key: string]: any };
|
||||
/**
|
||||
* parse data before it has been sent by addPath
|
||||
*/
|
||||
parsePayload?(
|
||||
namespace: string,
|
||||
key: string,
|
||||
fallbackValue?: string
|
||||
): { [key: string]: any };
|
||||
/**
|
||||
* parse data before it has been sent by loadPath
|
||||
* if value returned it will send a POST request
|
||||
*/
|
||||
parseLoadPayload?(
|
||||
languages: string[],
|
||||
namespaces: string[]
|
||||
): { [key: string]: any } | undefined;
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
request?(
|
||||
options: HttpBackendOptions,
|
||||
url: string,
|
||||
payload: {} | string,
|
||||
callback: RequestCallback
|
||||
): void;
|
||||
/**
|
||||
* adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5'
|
||||
*/
|
||||
queryStringParams?: { [key: string]: string };
|
||||
|
||||
/**
|
||||
* allows an object containing custom headers or a function that when called returns
|
||||
* an object of custom headers
|
||||
*/
|
||||
customHeaders?: { [key: string]: string } | (() => { [key: string]: string });
|
||||
|
||||
/**
|
||||
* can be used to reload resources in a specific
|
||||
* interval (useful in server environments)
|
||||
*/
|
||||
reloadInterval?: false | number;
|
||||
|
||||
/**
|
||||
* fetch api request options, can be a function
|
||||
*/
|
||||
requestOptions?: RequestInit | ((payload: {} | string) => RequestInit);
|
||||
}
|
||||
|
||||
type RequestCallback = (error: any | undefined | null, response: RequestResponse | undefined | null) => void;
|
||||
|
||||
interface RequestResponse {
|
||||
status: number;
|
||||
data: ResourceKey;
|
||||
}
|
||||
|
||||
export default class I18NextHttpBackend
|
||||
implements BackendModule<HttpBackendOptions>
|
||||
{
|
||||
static type: "backend";
|
||||
constructor(services?: any, options?: HttpBackendOptions);
|
||||
init(services?: any, options?: HttpBackendOptions): void;
|
||||
readMulti?(
|
||||
languages: string[],
|
||||
namespaces: string[],
|
||||
callback: MultiReadCallback
|
||||
): void;
|
||||
read(language: string, namespace: string, callback: ReadCallback): void;
|
||||
loadUrl(
|
||||
url: string,
|
||||
callback: ReadCallback,
|
||||
languages?: string | string[],
|
||||
namespaces?: string | string[]
|
||||
): void;
|
||||
create?(
|
||||
languages: string[],
|
||||
namespace: string,
|
||||
key: string,
|
||||
fallbackValue: string
|
||||
): void;
|
||||
type: "backend";
|
||||
services: any;
|
||||
options: HttpBackendOptions;
|
||||
}
|
192
node_modules/i18next-http-backend/esm/index.js
generated
vendored
Normal file
192
node_modules/i18next-http-backend/esm/index.js
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
||||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
||||
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
||||
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
||||
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
||||
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
||||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
||||
import { makePromise } from './utils.js';
|
||||
import request from './request.js';
|
||||
var getDefaults = function getDefaults() {
|
||||
return {
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
parse: function parse(data) {
|
||||
return JSON.parse(data);
|
||||
},
|
||||
stringify: JSON.stringify,
|
||||
parsePayload: function parsePayload(namespace, key, fallbackValue) {
|
||||
return _defineProperty({}, key, fallbackValue || '');
|
||||
},
|
||||
parseLoadPayload: function parseLoadPayload(languages, namespaces) {
|
||||
return undefined;
|
||||
},
|
||||
request: request,
|
||||
reloadInterval: typeof window !== 'undefined' ? false : 60 * 60 * 1000,
|
||||
customHeaders: {},
|
||||
queryStringParams: {},
|
||||
crossDomain: false,
|
||||
withCredentials: false,
|
||||
overrideMimeType: false,
|
||||
requestOptions: {
|
||||
mode: 'cors',
|
||||
credentials: 'same-origin',
|
||||
cache: 'default'
|
||||
}
|
||||
};
|
||||
};
|
||||
var Backend = function () {
|
||||
function Backend(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
_classCallCheck(this, Backend);
|
||||
this.services = services;
|
||||
this.options = options;
|
||||
this.allOptions = allOptions;
|
||||
this.type = 'backend';
|
||||
this.init(services, options, allOptions);
|
||||
}
|
||||
return _createClass(Backend, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var _this = this;
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
this.services = services;
|
||||
this.options = _objectSpread(_objectSpread(_objectSpread({}, getDefaults()), this.options || {}), options);
|
||||
this.allOptions = allOptions;
|
||||
if (this.services && this.options.reloadInterval) {
|
||||
var timer = setInterval(function () {
|
||||
return _this.reload();
|
||||
}, this.options.reloadInterval);
|
||||
if (_typeof(timer) === 'object' && typeof timer.unref === 'function') timer.unref();
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "readMulti",
|
||||
value: function readMulti(languages, namespaces, callback) {
|
||||
this._readAny(languages, languages, namespaces, namespaces, callback);
|
||||
}
|
||||
}, {
|
||||
key: "read",
|
||||
value: function read(language, namespace, callback) {
|
||||
this._readAny([language], language, [namespace], namespace, callback);
|
||||
}
|
||||
}, {
|
||||
key: "_readAny",
|
||||
value: function _readAny(languages, loadUrlLanguages, namespaces, loadUrlNamespaces, callback) {
|
||||
var _this2 = this;
|
||||
var loadPath = this.options.loadPath;
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath(languages, namespaces);
|
||||
}
|
||||
loadPath = makePromise(loadPath);
|
||||
loadPath.then(function (resolvedLoadPath) {
|
||||
if (!resolvedLoadPath) return callback(null, {});
|
||||
var url = _this2.services.interpolator.interpolate(resolvedLoadPath, {
|
||||
lng: languages.join('+'),
|
||||
ns: namespaces.join('+')
|
||||
});
|
||||
_this2.loadUrl(url, callback, loadUrlLanguages, loadUrlNamespaces);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "loadUrl",
|
||||
value: function loadUrl(url, callback, languages, namespaces) {
|
||||
var _this3 = this;
|
||||
var lng = typeof languages === 'string' ? [languages] : languages;
|
||||
var ns = typeof namespaces === 'string' ? [namespaces] : namespaces;
|
||||
var payload = this.options.parseLoadPayload(lng, ns);
|
||||
this.options.request(this.options, url, payload, function (err, res) {
|
||||
if (res && (res.status >= 500 && res.status < 600 || !res.status)) return callback('failed loading ' + url + '; status code: ' + res.status, true);
|
||||
if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url + '; status code: ' + res.status, false);
|
||||
if (!res && err && err.message) {
|
||||
var errorMessage = err.message.toLowerCase();
|
||||
var isNetworkError = ['failed', 'fetch', 'network', 'load'].find(function (term) {
|
||||
return errorMessage.indexOf(term) > -1;
|
||||
});
|
||||
if (isNetworkError) {
|
||||
return callback('failed loading ' + url + ': ' + err.message, true);
|
||||
}
|
||||
}
|
||||
if (err) return callback(err, false);
|
||||
var ret, parseErr;
|
||||
try {
|
||||
if (typeof res.data === 'string') {
|
||||
ret = _this3.options.parse(res.data, languages, namespaces);
|
||||
} else {
|
||||
ret = res.data;
|
||||
}
|
||||
} catch (e) {
|
||||
parseErr = 'failed parsing ' + url + ' to json';
|
||||
}
|
||||
if (parseErr) return callback(parseErr, false);
|
||||
callback(null, ret);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "create",
|
||||
value: function create(languages, namespace, key, fallbackValue, callback) {
|
||||
var _this4 = this;
|
||||
if (!this.options.addPath) return;
|
||||
if (typeof languages === 'string') languages = [languages];
|
||||
var payload = this.options.parsePayload(namespace, key, fallbackValue);
|
||||
var finished = 0;
|
||||
var dataArray = [];
|
||||
var resArray = [];
|
||||
languages.forEach(function (lng) {
|
||||
var addPath = _this4.options.addPath;
|
||||
if (typeof _this4.options.addPath === 'function') {
|
||||
addPath = _this4.options.addPath(lng, namespace);
|
||||
}
|
||||
var url = _this4.services.interpolator.interpolate(addPath, {
|
||||
lng: lng,
|
||||
ns: namespace
|
||||
});
|
||||
_this4.options.request(_this4.options, url, payload, function (data, res) {
|
||||
finished += 1;
|
||||
dataArray.push(data);
|
||||
resArray.push(res);
|
||||
if (finished === languages.length) {
|
||||
if (typeof callback === 'function') callback(dataArray, resArray);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "reload",
|
||||
value: function reload() {
|
||||
var _this5 = this;
|
||||
var _this$services = this.services,
|
||||
backendConnector = _this$services.backendConnector,
|
||||
languageUtils = _this$services.languageUtils,
|
||||
logger = _this$services.logger;
|
||||
var currentLanguage = backendConnector.language;
|
||||
if (currentLanguage && currentLanguage.toLowerCase() === 'cimode') return;
|
||||
var toLoad = [];
|
||||
var append = function append(lng) {
|
||||
var lngs = languageUtils.toResolveHierarchy(lng);
|
||||
lngs.forEach(function (l) {
|
||||
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
||||
});
|
||||
};
|
||||
append(currentLanguage);
|
||||
if (this.allOptions.preload) this.allOptions.preload.forEach(function (l) {
|
||||
return append(l);
|
||||
});
|
||||
toLoad.forEach(function (lng) {
|
||||
_this5.allOptions.ns.forEach(function (ns) {
|
||||
backendConnector.read(lng, ns, 'read', null, null, function (err, data) {
|
||||
if (err) logger.warn("loading namespace ".concat(ns, " for language ").concat(lng, " failed"), err);
|
||||
if (!err && data) logger.log("loaded namespace ".concat(ns, " for language ").concat(lng), data);
|
||||
backendConnector.loaded("".concat(lng, "|").concat(ns), err, data);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}]);
|
||||
}();
|
||||
Backend.type = 'backend';
|
||||
export default Backend;
|
160
node_modules/i18next-http-backend/esm/request.js
generated
vendored
Normal file
160
node_modules/i18next-http-backend/esm/request.js
generated
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
||||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
||||
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
||||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
import { hasXMLHttpRequest } from './utils.js';
|
||||
import * as fetchNode from './getFetch.cjs';
|
||||
var fetchApi = typeof fetch === 'function' ? fetch : undefined;
|
||||
if (typeof global !== 'undefined' && global.fetch) {
|
||||
fetchApi = global.fetch;
|
||||
} else if (typeof window !== 'undefined' && window.fetch) {
|
||||
fetchApi = window.fetch;
|
||||
}
|
||||
var XmlHttpRequestApi;
|
||||
if (hasXMLHttpRequest()) {
|
||||
if (typeof global !== 'undefined' && global.XMLHttpRequest) {
|
||||
XmlHttpRequestApi = global.XMLHttpRequest;
|
||||
} else if (typeof window !== 'undefined' && window.XMLHttpRequest) {
|
||||
XmlHttpRequestApi = window.XMLHttpRequest;
|
||||
}
|
||||
}
|
||||
var ActiveXObjectApi;
|
||||
if (typeof ActiveXObject === 'function') {
|
||||
if (typeof global !== 'undefined' && global.ActiveXObject) {
|
||||
ActiveXObjectApi = global.ActiveXObject;
|
||||
} else if (typeof window !== 'undefined' && window.ActiveXObject) {
|
||||
ActiveXObjectApi = window.ActiveXObject;
|
||||
}
|
||||
}
|
||||
if (!fetchApi && fetchNode && !XmlHttpRequestApi && !ActiveXObjectApi) fetchApi = fetchNode.default || fetchNode;
|
||||
if (typeof fetchApi !== 'function') fetchApi = undefined;
|
||||
var addQueryString = function addQueryString(url, params) {
|
||||
if (params && _typeof(params) === 'object') {
|
||||
var queryString = '';
|
||||
for (var paramName in params) {
|
||||
queryString += '&' + encodeURIComponent(paramName) + '=' + encodeURIComponent(params[paramName]);
|
||||
}
|
||||
if (!queryString) return url;
|
||||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1);
|
||||
}
|
||||
return url;
|
||||
};
|
||||
var fetchIt = function fetchIt(url, fetchOptions, callback, altFetch) {
|
||||
var resolver = function resolver(response) {
|
||||
if (!response.ok) return callback(response.statusText || 'Error', {
|
||||
status: response.status
|
||||
});
|
||||
response.text().then(function (data) {
|
||||
callback(null, {
|
||||
status: response.status,
|
||||
data: data
|
||||
});
|
||||
}).catch(callback);
|
||||
};
|
||||
if (altFetch) {
|
||||
var altResponse = altFetch(url, fetchOptions);
|
||||
if (altResponse instanceof Promise) {
|
||||
altResponse.then(resolver).catch(callback);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (typeof fetch === 'function') {
|
||||
fetch(url, fetchOptions).then(resolver).catch(callback);
|
||||
} else {
|
||||
fetchApi(url, fetchOptions).then(resolver).catch(callback);
|
||||
}
|
||||
};
|
||||
var omitFetchOptions = false;
|
||||
var requestWithFetch = function requestWithFetch(options, url, payload, callback) {
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
var headers = _objectSpread({}, typeof options.customHeaders === 'function' ? options.customHeaders() : options.customHeaders);
|
||||
if (typeof window === 'undefined' && typeof global !== 'undefined' && typeof global.process !== 'undefined' && global.process.versions && global.process.versions.node) {
|
||||
headers['User-Agent'] = "i18next-http-backend (node/".concat(global.process.version, "; ").concat(global.process.platform, " ").concat(global.process.arch, ")");
|
||||
}
|
||||
if (payload) headers['Content-Type'] = 'application/json';
|
||||
var reqOptions = typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions;
|
||||
var fetchOptions = _objectSpread({
|
||||
method: payload ? 'POST' : 'GET',
|
||||
body: payload ? options.stringify(payload) : undefined,
|
||||
headers: headers
|
||||
}, omitFetchOptions ? {} : reqOptions);
|
||||
var altFetch = typeof options.alternateFetch === 'function' && options.alternateFetch.length >= 1 ? options.alternateFetch : undefined;
|
||||
try {
|
||||
fetchIt(url, fetchOptions, callback, altFetch);
|
||||
} catch (e) {
|
||||
if (!reqOptions || Object.keys(reqOptions).length === 0 || !e.message || e.message.indexOf('not implemented') < 0) {
|
||||
return callback(e);
|
||||
}
|
||||
try {
|
||||
Object.keys(reqOptions).forEach(function (opt) {
|
||||
delete fetchOptions[opt];
|
||||
});
|
||||
fetchIt(url, fetchOptions, callback, altFetch);
|
||||
omitFetchOptions = true;
|
||||
} catch (err) {
|
||||
callback(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
var requestWithXmlHttpRequest = function requestWithXmlHttpRequest(options, url, payload, callback) {
|
||||
if (payload && _typeof(payload) === 'object') {
|
||||
payload = addQueryString('', payload).slice(1);
|
||||
}
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
try {
|
||||
var x;
|
||||
if (XmlHttpRequestApi) {
|
||||
x = new XmlHttpRequestApi();
|
||||
} else {
|
||||
x = new ActiveXObjectApi('MSXML2.XMLHTTP.3.0');
|
||||
}
|
||||
x.open(payload ? 'POST' : 'GET', url, 1);
|
||||
if (!options.crossDomain) {
|
||||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
}
|
||||
x.withCredentials = !!options.withCredentials;
|
||||
if (payload) {
|
||||
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(x.status >= 400 ? x.statusText : null, {
|
||||
status: x.status,
|
||||
data: x.responseText
|
||||
});
|
||||
};
|
||||
x.send(payload);
|
||||
} catch (e) {
|
||||
console && console.log(e);
|
||||
}
|
||||
};
|
||||
var request = function request(options, url, payload, callback) {
|
||||
if (typeof payload === 'function') {
|
||||
callback = payload;
|
||||
payload = undefined;
|
||||
}
|
||||
callback = callback || function () {};
|
||||
if (fetchApi && url.indexOf('file:') !== 0) {
|
||||
return requestWithFetch(options, url, payload, callback);
|
||||
}
|
||||
if (hasXMLHttpRequest() || typeof ActiveXObject === 'function') {
|
||||
return requestWithXmlHttpRequest(options, url, payload, callback);
|
||||
}
|
||||
callback(new Error('No fetch and no xhr implementation found!'));
|
||||
};
|
||||
export default request;
|
26
node_modules/i18next-http-backend/esm/utils.js
generated
vendored
Normal file
26
node_modules/i18next-http-backend/esm/utils.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
var arr = [];
|
||||
var each = arr.forEach;
|
||||
var slice = arr.slice;
|
||||
export 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;
|
||||
}
|
||||
export function hasXMLHttpRequest() {
|
||||
return typeof XMLHttpRequest === 'function' || (typeof XMLHttpRequest === "undefined" ? "undefined" : _typeof(XMLHttpRequest)) === 'object';
|
||||
}
|
||||
function isPromise(maybePromise) {
|
||||
return !!maybePromise && typeof maybePromise.then === 'function';
|
||||
}
|
||||
export function makePromise(maybePromise) {
|
||||
if (isPromise(maybePromise)) {
|
||||
return maybePromise;
|
||||
}
|
||||
return Promise.resolve(maybePromise);
|
||||
}
|
429
node_modules/i18next-http-backend/i18nextHttpBackend.js
generated
vendored
Normal file
429
node_modules/i18next-http-backend/i18nextHttpBackend.js
generated
vendored
Normal file
@@ -0,0 +1,429 @@
|
||||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.i18nextHttpBackend = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
||||
(function (global){(function (){
|
||||
var fetchApi = typeof fetch === 'function' ? fetch : undefined
|
||||
if (typeof global !== 'undefined' && global.fetch) {
|
||||
fetchApi = global.fetch
|
||||
} else if (typeof window !== 'undefined' && window.fetch) {
|
||||
fetchApi = window.fetch
|
||||
}
|
||||
|
||||
if (typeof require !== 'undefined' && typeof window === 'undefined') {
|
||||
var f = fetchApi || require('cross-fetch')
|
||||
if (f.default) f = f.default
|
||||
exports.default = f
|
||||
module.exports = exports.default
|
||||
}
|
||||
|
||||
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
},{"cross-fetch":5}],2:[function(require,module,exports){
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _utils = require("./utils.js");
|
||||
var _request = _interopRequireDefault(require("./request.js"));
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
||||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
||||
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
||||
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
||||
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
||||
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
||||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
||||
var getDefaults = function getDefaults() {
|
||||
return {
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
parse: function parse(data) {
|
||||
return JSON.parse(data);
|
||||
},
|
||||
stringify: JSON.stringify,
|
||||
parsePayload: function parsePayload(namespace, key, fallbackValue) {
|
||||
return _defineProperty({}, key, fallbackValue || '');
|
||||
},
|
||||
parseLoadPayload: function parseLoadPayload(languages, namespaces) {
|
||||
return undefined;
|
||||
},
|
||||
request: _request.default,
|
||||
reloadInterval: typeof window !== 'undefined' ? false : 60 * 60 * 1000,
|
||||
customHeaders: {},
|
||||
queryStringParams: {},
|
||||
crossDomain: false,
|
||||
withCredentials: false,
|
||||
overrideMimeType: false,
|
||||
requestOptions: {
|
||||
mode: 'cors',
|
||||
credentials: 'same-origin',
|
||||
cache: 'default'
|
||||
}
|
||||
};
|
||||
};
|
||||
var Backend = function () {
|
||||
function Backend(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
_classCallCheck(this, Backend);
|
||||
this.services = services;
|
||||
this.options = options;
|
||||
this.allOptions = allOptions;
|
||||
this.type = 'backend';
|
||||
this.init(services, options, allOptions);
|
||||
}
|
||||
return _createClass(Backend, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var _this = this;
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
this.services = services;
|
||||
this.options = _objectSpread(_objectSpread(_objectSpread({}, getDefaults()), this.options || {}), options);
|
||||
this.allOptions = allOptions;
|
||||
if (this.services && this.options.reloadInterval) {
|
||||
var timer = setInterval(function () {
|
||||
return _this.reload();
|
||||
}, this.options.reloadInterval);
|
||||
if (_typeof(timer) === 'object' && typeof timer.unref === 'function') timer.unref();
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "readMulti",
|
||||
value: function readMulti(languages, namespaces, callback) {
|
||||
this._readAny(languages, languages, namespaces, namespaces, callback);
|
||||
}
|
||||
}, {
|
||||
key: "read",
|
||||
value: function read(language, namespace, callback) {
|
||||
this._readAny([language], language, [namespace], namespace, callback);
|
||||
}
|
||||
}, {
|
||||
key: "_readAny",
|
||||
value: function _readAny(languages, loadUrlLanguages, namespaces, loadUrlNamespaces, callback) {
|
||||
var _this2 = this;
|
||||
var loadPath = this.options.loadPath;
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath(languages, namespaces);
|
||||
}
|
||||
loadPath = (0, _utils.makePromise)(loadPath);
|
||||
loadPath.then(function (resolvedLoadPath) {
|
||||
if (!resolvedLoadPath) return callback(null, {});
|
||||
var url = _this2.services.interpolator.interpolate(resolvedLoadPath, {
|
||||
lng: languages.join('+'),
|
||||
ns: namespaces.join('+')
|
||||
});
|
||||
_this2.loadUrl(url, callback, loadUrlLanguages, loadUrlNamespaces);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "loadUrl",
|
||||
value: function loadUrl(url, callback, languages, namespaces) {
|
||||
var _this3 = this;
|
||||
var lng = typeof languages === 'string' ? [languages] : languages;
|
||||
var ns = typeof namespaces === 'string' ? [namespaces] : namespaces;
|
||||
var payload = this.options.parseLoadPayload(lng, ns);
|
||||
this.options.request(this.options, url, payload, function (err, res) {
|
||||
if (res && (res.status >= 500 && res.status < 600 || !res.status)) return callback('failed loading ' + url + '; status code: ' + res.status, true);
|
||||
if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url + '; status code: ' + res.status, false);
|
||||
if (!res && err && err.message) {
|
||||
var errorMessage = err.message.toLowerCase();
|
||||
var isNetworkError = ['failed', 'fetch', 'network', 'load'].find(function (term) {
|
||||
return errorMessage.indexOf(term) > -1;
|
||||
});
|
||||
if (isNetworkError) {
|
||||
return callback('failed loading ' + url + ': ' + err.message, true);
|
||||
}
|
||||
}
|
||||
if (err) return callback(err, false);
|
||||
var ret, parseErr;
|
||||
try {
|
||||
if (typeof res.data === 'string') {
|
||||
ret = _this3.options.parse(res.data, languages, namespaces);
|
||||
} else {
|
||||
ret = res.data;
|
||||
}
|
||||
} catch (e) {
|
||||
parseErr = 'failed parsing ' + url + ' to json';
|
||||
}
|
||||
if (parseErr) return callback(parseErr, false);
|
||||
callback(null, ret);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "create",
|
||||
value: function create(languages, namespace, key, fallbackValue, callback) {
|
||||
var _this4 = this;
|
||||
if (!this.options.addPath) return;
|
||||
if (typeof languages === 'string') languages = [languages];
|
||||
var payload = this.options.parsePayload(namespace, key, fallbackValue);
|
||||
var finished = 0;
|
||||
var dataArray = [];
|
||||
var resArray = [];
|
||||
languages.forEach(function (lng) {
|
||||
var addPath = _this4.options.addPath;
|
||||
if (typeof _this4.options.addPath === 'function') {
|
||||
addPath = _this4.options.addPath(lng, namespace);
|
||||
}
|
||||
var url = _this4.services.interpolator.interpolate(addPath, {
|
||||
lng: lng,
|
||||
ns: namespace
|
||||
});
|
||||
_this4.options.request(_this4.options, url, payload, function (data, res) {
|
||||
finished += 1;
|
||||
dataArray.push(data);
|
||||
resArray.push(res);
|
||||
if (finished === languages.length) {
|
||||
if (typeof callback === 'function') callback(dataArray, resArray);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "reload",
|
||||
value: function reload() {
|
||||
var _this5 = this;
|
||||
var _this$services = this.services,
|
||||
backendConnector = _this$services.backendConnector,
|
||||
languageUtils = _this$services.languageUtils,
|
||||
logger = _this$services.logger;
|
||||
var currentLanguage = backendConnector.language;
|
||||
if (currentLanguage && currentLanguage.toLowerCase() === 'cimode') return;
|
||||
var toLoad = [];
|
||||
var append = function append(lng) {
|
||||
var lngs = languageUtils.toResolveHierarchy(lng);
|
||||
lngs.forEach(function (l) {
|
||||
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
||||
});
|
||||
};
|
||||
append(currentLanguage);
|
||||
if (this.allOptions.preload) this.allOptions.preload.forEach(function (l) {
|
||||
return append(l);
|
||||
});
|
||||
toLoad.forEach(function (lng) {
|
||||
_this5.allOptions.ns.forEach(function (ns) {
|
||||
backendConnector.read(lng, ns, 'read', null, null, function (err, data) {
|
||||
if (err) logger.warn("loading namespace ".concat(ns, " for language ").concat(lng, " failed"), err);
|
||||
if (!err && data) logger.log("loaded namespace ".concat(ns, " for language ").concat(lng), data);
|
||||
backendConnector.loaded("".concat(lng, "|").concat(ns), err, data);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}]);
|
||||
}();
|
||||
Backend.type = 'backend';
|
||||
var _default = exports.default = Backend;
|
||||
module.exports = exports.default;
|
||||
},{"./request.js":3,"./utils.js":4}],3:[function(require,module,exports){
|
||||
(function (global){(function (){
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _utils = require("./utils.js");
|
||||
var fetchNode = _interopRequireWildcard(require("./getFetch.js"));
|
||||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
||||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
||||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
||||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
||||
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
||||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
var fetchApi = typeof fetch === 'function' ? fetch : undefined;
|
||||
if (typeof global !== 'undefined' && global.fetch) {
|
||||
fetchApi = global.fetch;
|
||||
} else if (typeof window !== 'undefined' && window.fetch) {
|
||||
fetchApi = window.fetch;
|
||||
}
|
||||
var XmlHttpRequestApi;
|
||||
if ((0, _utils.hasXMLHttpRequest)()) {
|
||||
if (typeof global !== 'undefined' && global.XMLHttpRequest) {
|
||||
XmlHttpRequestApi = global.XMLHttpRequest;
|
||||
} else if (typeof window !== 'undefined' && window.XMLHttpRequest) {
|
||||
XmlHttpRequestApi = window.XMLHttpRequest;
|
||||
}
|
||||
}
|
||||
var ActiveXObjectApi;
|
||||
if (typeof ActiveXObject === 'function') {
|
||||
if (typeof global !== 'undefined' && global.ActiveXObject) {
|
||||
ActiveXObjectApi = global.ActiveXObject;
|
||||
} else if (typeof window !== 'undefined' && window.ActiveXObject) {
|
||||
ActiveXObjectApi = window.ActiveXObject;
|
||||
}
|
||||
}
|
||||
if (!fetchApi && fetchNode && !XmlHttpRequestApi && !ActiveXObjectApi) fetchApi = fetchNode.default || fetchNode;
|
||||
if (typeof fetchApi !== 'function') fetchApi = undefined;
|
||||
var addQueryString = function addQueryString(url, params) {
|
||||
if (params && _typeof(params) === 'object') {
|
||||
var queryString = '';
|
||||
for (var paramName in params) {
|
||||
queryString += '&' + encodeURIComponent(paramName) + '=' + encodeURIComponent(params[paramName]);
|
||||
}
|
||||
if (!queryString) return url;
|
||||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1);
|
||||
}
|
||||
return url;
|
||||
};
|
||||
var fetchIt = function fetchIt(url, fetchOptions, callback, altFetch) {
|
||||
var resolver = function resolver(response) {
|
||||
if (!response.ok) return callback(response.statusText || 'Error', {
|
||||
status: response.status
|
||||
});
|
||||
response.text().then(function (data) {
|
||||
callback(null, {
|
||||
status: response.status,
|
||||
data: data
|
||||
});
|
||||
}).catch(callback);
|
||||
};
|
||||
if (altFetch) {
|
||||
var altResponse = altFetch(url, fetchOptions);
|
||||
if (altResponse instanceof Promise) {
|
||||
altResponse.then(resolver).catch(callback);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (typeof fetch === 'function') {
|
||||
fetch(url, fetchOptions).then(resolver).catch(callback);
|
||||
} else {
|
||||
fetchApi(url, fetchOptions).then(resolver).catch(callback);
|
||||
}
|
||||
};
|
||||
var omitFetchOptions = false;
|
||||
var requestWithFetch = function requestWithFetch(options, url, payload, callback) {
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
var headers = _objectSpread({}, typeof options.customHeaders === 'function' ? options.customHeaders() : options.customHeaders);
|
||||
if (typeof window === 'undefined' && typeof global !== 'undefined' && typeof global.process !== 'undefined' && global.process.versions && global.process.versions.node) {
|
||||
headers['User-Agent'] = "i18next-http-backend (node/".concat(global.process.version, "; ").concat(global.process.platform, " ").concat(global.process.arch, ")");
|
||||
}
|
||||
if (payload) headers['Content-Type'] = 'application/json';
|
||||
var reqOptions = typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions;
|
||||
var fetchOptions = _objectSpread({
|
||||
method: payload ? 'POST' : 'GET',
|
||||
body: payload ? options.stringify(payload) : undefined,
|
||||
headers: headers
|
||||
}, omitFetchOptions ? {} : reqOptions);
|
||||
var altFetch = typeof options.alternateFetch === 'function' && options.alternateFetch.length >= 1 ? options.alternateFetch : undefined;
|
||||
try {
|
||||
fetchIt(url, fetchOptions, callback, altFetch);
|
||||
} catch (e) {
|
||||
if (!reqOptions || Object.keys(reqOptions).length === 0 || !e.message || e.message.indexOf('not implemented') < 0) {
|
||||
return callback(e);
|
||||
}
|
||||
try {
|
||||
Object.keys(reqOptions).forEach(function (opt) {
|
||||
delete fetchOptions[opt];
|
||||
});
|
||||
fetchIt(url, fetchOptions, callback, altFetch);
|
||||
omitFetchOptions = true;
|
||||
} catch (err) {
|
||||
callback(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
var requestWithXmlHttpRequest = function requestWithXmlHttpRequest(options, url, payload, callback) {
|
||||
if (payload && _typeof(payload) === 'object') {
|
||||
payload = addQueryString('', payload).slice(1);
|
||||
}
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
try {
|
||||
var x;
|
||||
if (XmlHttpRequestApi) {
|
||||
x = new XmlHttpRequestApi();
|
||||
} else {
|
||||
x = new ActiveXObjectApi('MSXML2.XMLHTTP.3.0');
|
||||
}
|
||||
x.open(payload ? 'POST' : 'GET', url, 1);
|
||||
if (!options.crossDomain) {
|
||||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
}
|
||||
x.withCredentials = !!options.withCredentials;
|
||||
if (payload) {
|
||||
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(x.status >= 400 ? x.statusText : null, {
|
||||
status: x.status,
|
||||
data: x.responseText
|
||||
});
|
||||
};
|
||||
x.send(payload);
|
||||
} catch (e) {
|
||||
console && console.log(e);
|
||||
}
|
||||
};
|
||||
var request = function request(options, url, payload, callback) {
|
||||
if (typeof payload === 'function') {
|
||||
callback = payload;
|
||||
payload = undefined;
|
||||
}
|
||||
callback = callback || function () {};
|
||||
if (fetchApi && url.indexOf('file:') !== 0) {
|
||||
return requestWithFetch(options, url, payload, callback);
|
||||
}
|
||||
if ((0, _utils.hasXMLHttpRequest)() || typeof ActiveXObject === 'function') {
|
||||
return requestWithXmlHttpRequest(options, url, payload, callback);
|
||||
}
|
||||
callback(new Error('No fetch and no xhr implementation found!'));
|
||||
};
|
||||
var _default = exports.default = request;
|
||||
module.exports = exports.default;
|
||||
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
},{"./getFetch.js":1,"./utils.js":4}],4:[function(require,module,exports){
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.defaults = defaults;
|
||||
exports.hasXMLHttpRequest = hasXMLHttpRequest;
|
||||
exports.makePromise = makePromise;
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
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 hasXMLHttpRequest() {
|
||||
return typeof XMLHttpRequest === 'function' || (typeof XMLHttpRequest === "undefined" ? "undefined" : _typeof(XMLHttpRequest)) === 'object';
|
||||
}
|
||||
function isPromise(maybePromise) {
|
||||
return !!maybePromise && typeof maybePromise.then === 'function';
|
||||
}
|
||||
function makePromise(maybePromise) {
|
||||
if (isPromise(maybePromise)) {
|
||||
return maybePromise;
|
||||
}
|
||||
return Promise.resolve(maybePromise);
|
||||
}
|
||||
},{}],5:[function(require,module,exports){
|
||||
|
||||
},{}]},{},[2])(2)
|
||||
});
|
1
node_modules/i18next-http-backend/i18nextHttpBackend.min.js
generated
vendored
Normal file
1
node_modules/i18next-http-backend/i18nextHttpBackend.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
9
node_modules/i18next-http-backend/index.d.mts
generated
vendored
Normal file
9
node_modules/i18next-http-backend/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as index from './index.js';
|
||||
|
||||
export default index.default;
|
||||
|
||||
export type HttpBackendOptions = index.HttpBackendOptions;
|
||||
export type RequestCallback = index.RequestCallback;
|
||||
export type LoadPathOption = index.LoadPathOption;
|
||||
export type AddPathOption = index.AddPathOption;
|
||||
export type RequestResponse = index.RequestResponse;
|
140
node_modules/i18next-http-backend/index.d.ts
generated
vendored
Normal file
140
node_modules/i18next-http-backend/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
import { BackendModule, MultiReadCallback, ReadCallback, ResourceKey } from "i18next";
|
||||
|
||||
type LoadPathOption =
|
||||
| string
|
||||
| ((lngs: string[], namespaces: string[]) => string)
|
||||
| ((lngs: string[], namespaces: string[]) => Promise<string>);
|
||||
|
||||
type AddPathOption =
|
||||
| string
|
||||
| ((lng: string, namespace: string) => string);
|
||||
|
||||
type FetchFunction = (input: string, init: RequestInit) => Promise<Response> | void
|
||||
|
||||
export interface HttpBackendOptions {
|
||||
/**
|
||||
* Use an alternative fetch function that acts like an interecept, (usefull for low level mocks/simulations)
|
||||
*
|
||||
* This option is not called if:
|
||||
*
|
||||
* 1. There is an custom value set for the "request" property in this options object.
|
||||
* 2. The backend selected xmlHttpRequest over fetch
|
||||
*
|
||||
* If the function is called and it returns anything BUT a promise the fetch or xmlHttpRequest will be subsequentially called
|
||||
*
|
||||
*/
|
||||
alternateFetch?: FetchFunction;
|
||||
/**
|
||||
* 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, must be `string` or a `function` returning a path:
|
||||
* function(lng, namespace) { return customPath; }
|
||||
*/
|
||||
addPath?: AddPathOption;
|
||||
/**
|
||||
* 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,
|
||||
languages?: string | string[],
|
||||
namespaces?: string | string[]
|
||||
): { [key: string]: any };
|
||||
/**
|
||||
* parse data before it has been sent by addPath
|
||||
*/
|
||||
parsePayload?(
|
||||
namespace: string,
|
||||
key: string,
|
||||
fallbackValue?: string
|
||||
): { [key: string]: any };
|
||||
/**
|
||||
* parse data before it has been sent by loadPath
|
||||
* if value returned it will send a POST request
|
||||
*/
|
||||
parseLoadPayload?(
|
||||
languages: string[],
|
||||
namespaces: string[]
|
||||
): { [key: string]: any } | undefined;
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
request?(
|
||||
options: HttpBackendOptions,
|
||||
url: string,
|
||||
payload: {} | string,
|
||||
callback: RequestCallback
|
||||
): void;
|
||||
/**
|
||||
* adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5'
|
||||
*/
|
||||
queryStringParams?: { [key: string]: string };
|
||||
|
||||
/**
|
||||
* allows an object containing custom headers or a function that when called returns
|
||||
* an object of custom headers
|
||||
*/
|
||||
customHeaders?: { [key: string]: string } | (() => { [key: string]: string });
|
||||
|
||||
/**
|
||||
* can be used to reload resources in a specific
|
||||
* interval (useful in server environments)
|
||||
*/
|
||||
reloadInterval?: false | number;
|
||||
|
||||
/**
|
||||
* fetch api request options, can be a function
|
||||
*/
|
||||
requestOptions?: RequestInit | ((payload: {} | string) => RequestInit);
|
||||
}
|
||||
|
||||
type RequestCallback = (error: any | undefined | null, response: RequestResponse | undefined | null) => void;
|
||||
|
||||
interface RequestResponse {
|
||||
status: number;
|
||||
data: ResourceKey;
|
||||
}
|
||||
|
||||
export default class I18NextHttpBackend
|
||||
implements BackendModule<HttpBackendOptions>
|
||||
{
|
||||
static type: "backend";
|
||||
constructor(services?: any, options?: HttpBackendOptions);
|
||||
init(services?: any, options?: HttpBackendOptions): void;
|
||||
readMulti?(
|
||||
languages: string[],
|
||||
namespaces: string[],
|
||||
callback: MultiReadCallback
|
||||
): void;
|
||||
read(language: string, namespace: string, callback: ReadCallback): void;
|
||||
loadUrl(
|
||||
url: string,
|
||||
callback: ReadCallback,
|
||||
languages?: string | string[],
|
||||
namespaces?: string | string[]
|
||||
): void;
|
||||
create?(
|
||||
languages: string[],
|
||||
namespace: string,
|
||||
key: string,
|
||||
fallbackValue: string
|
||||
): void;
|
||||
type: "backend";
|
||||
services: any;
|
||||
options: HttpBackendOptions;
|
||||
}
|
2
node_modules/i18next-http-backend/index.js
generated
vendored
Normal file
2
node_modules/i18next-http-backend/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import backend from './lib/index.js'
|
||||
export default backend
|
14
node_modules/i18next-http-backend/lib/getFetch.cjs
generated
vendored
Normal file
14
node_modules/i18next-http-backend/lib/getFetch.cjs
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
/* eslint-disable no-var, no-undef */
|
||||
var fetchApi = typeof fetch === 'function' ? fetch : undefined
|
||||
if (typeof global !== 'undefined' && global.fetch) {
|
||||
fetchApi = global.fetch
|
||||
} else if (typeof window !== 'undefined' && window.fetch) {
|
||||
fetchApi = window.fetch
|
||||
}
|
||||
|
||||
if (typeof require !== 'undefined' && typeof window === 'undefined') {
|
||||
var f = fetchApi || require('cross-fetch')
|
||||
if (f.default) f = f.default
|
||||
exports.default = f
|
||||
module.exports = exports.default
|
||||
}
|
169
node_modules/i18next-http-backend/lib/index.js
generated
vendored
Normal file
169
node_modules/i18next-http-backend/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
import { makePromise } from './utils.js'
|
||||
import request from './request.js'
|
||||
|
||||
const getDefaults = () => {
|
||||
return {
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
parse: data => JSON.parse(data),
|
||||
stringify: JSON.stringify,
|
||||
parsePayload: (namespace, key, fallbackValue) => ({ [key]: fallbackValue || '' }),
|
||||
parseLoadPayload: (languages, namespaces) => undefined,
|
||||
request,
|
||||
reloadInterval: typeof window !== 'undefined' ? false : 60 * 60 * 1000,
|
||||
customHeaders: {},
|
||||
queryStringParams: {},
|
||||
crossDomain: false, // used for XmlHttpRequest
|
||||
withCredentials: false, // used for XmlHttpRequest
|
||||
overrideMimeType: false, // used for XmlHttpRequest
|
||||
requestOptions: { // used for fetch
|
||||
mode: 'cors',
|
||||
credentials: 'same-origin',
|
||||
cache: 'default'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Backend {
|
||||
constructor (services, options = {}, allOptions = {}) {
|
||||
this.services = services
|
||||
this.options = options
|
||||
this.allOptions = allOptions
|
||||
this.type = 'backend'
|
||||
this.init(services, options, allOptions)
|
||||
}
|
||||
|
||||
init (services, options = {}, allOptions = {}) {
|
||||
this.services = services
|
||||
this.options = { ...getDefaults(), ...(this.options || {}), ...options }
|
||||
this.allOptions = allOptions
|
||||
if (this.services && this.options.reloadInterval) {
|
||||
const timer = setInterval(() => this.reload(), this.options.reloadInterval)
|
||||
if (typeof timer === 'object' && typeof timer.unref === 'function') timer.unref()
|
||||
}
|
||||
}
|
||||
|
||||
readMulti (languages, namespaces, callback) {
|
||||
this._readAny(languages, languages, namespaces, namespaces, callback)
|
||||
}
|
||||
|
||||
read (language, namespace, callback) {
|
||||
this._readAny([language], language, [namespace], namespace, callback)
|
||||
}
|
||||
|
||||
_readAny (languages, loadUrlLanguages, namespaces, loadUrlNamespaces, callback) {
|
||||
let loadPath = this.options.loadPath
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath(languages, namespaces)
|
||||
}
|
||||
|
||||
loadPath = makePromise(loadPath)
|
||||
|
||||
loadPath.then(resolvedLoadPath => {
|
||||
if (!resolvedLoadPath) return callback(null, {})
|
||||
const url = this.services.interpolator.interpolate(resolvedLoadPath, { lng: languages.join('+'), ns: namespaces.join('+') })
|
||||
this.loadUrl(url, callback, loadUrlLanguages, loadUrlNamespaces)
|
||||
})
|
||||
}
|
||||
|
||||
loadUrl (url, callback, languages, namespaces) {
|
||||
const lng = (typeof languages === 'string') ? [languages] : languages
|
||||
const ns = (typeof namespaces === 'string') ? [namespaces] : namespaces
|
||||
// parseLoadPayload — default undefined
|
||||
const payload = this.options.parseLoadPayload(lng, ns)
|
||||
this.options.request(this.options, url, payload, (err, res) => {
|
||||
if (res && ((res.status >= 500 && res.status < 600) || !res.status)) return callback('failed loading ' + url + '; status code: ' + res.status, true /* retry */)
|
||||
if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url + '; status code: ' + res.status, false /* no retry */)
|
||||
if (!res && err && err.message) {
|
||||
const errorMessage = err.message.toLowerCase()
|
||||
// for example:
|
||||
// Chrome: "Failed to fetch"
|
||||
// Firefox: "NetworkError when attempting to fetch resource."
|
||||
// Safari: "Load failed"
|
||||
const isNetworkError = [
|
||||
'failed',
|
||||
'fetch',
|
||||
'network',
|
||||
'load'
|
||||
].find((term) => errorMessage.indexOf(term) > -1)
|
||||
if (isNetworkError) {
|
||||
return callback('failed loading ' + url + ': ' + err.message, true /* retry */)
|
||||
}
|
||||
}
|
||||
if (err) return callback(err, false)
|
||||
|
||||
let ret, parseErr
|
||||
try {
|
||||
if (typeof res.data === 'string') {
|
||||
ret = this.options.parse(res.data, languages, namespaces)
|
||||
} else { // fallback, which omits calling the parse function
|
||||
ret = res.data
|
||||
}
|
||||
} catch (e) {
|
||||
parseErr = 'failed parsing ' + url + ' to json'
|
||||
}
|
||||
if (parseErr) return callback(parseErr, false)
|
||||
callback(null, ret)
|
||||
})
|
||||
}
|
||||
|
||||
create (languages, namespace, key, fallbackValue, callback) {
|
||||
// If there is a falsey addPath, then abort -- this has been disabled.
|
||||
if (!this.options.addPath) return
|
||||
if (typeof languages === 'string') languages = [languages]
|
||||
const payload = this.options.parsePayload(namespace, key, fallbackValue)
|
||||
let finished = 0
|
||||
const dataArray = []
|
||||
const resArray = []
|
||||
languages.forEach(lng => {
|
||||
let addPath = this.options.addPath
|
||||
if (typeof this.options.addPath === 'function') {
|
||||
addPath = this.options.addPath(lng, namespace)
|
||||
}
|
||||
const url = this.services.interpolator.interpolate(addPath, { lng, ns: namespace })
|
||||
|
||||
this.options.request(this.options, url, payload, (data, res) => {
|
||||
// TODO: if res.status === 4xx do log
|
||||
finished += 1
|
||||
dataArray.push(data)
|
||||
resArray.push(res)
|
||||
if (finished === languages.length) {
|
||||
if (typeof callback === 'function') callback(dataArray, resArray)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
reload () {
|
||||
const { backendConnector, languageUtils, logger } = this.services
|
||||
const currentLanguage = backendConnector.language
|
||||
if (currentLanguage && currentLanguage.toLowerCase() === 'cimode') return // avoid loading resources for cimode
|
||||
|
||||
const toLoad = []
|
||||
const append = (lng) => {
|
||||
const lngs = languageUtils.toResolveHierarchy(lng)
|
||||
lngs.forEach(l => {
|
||||
if (toLoad.indexOf(l) < 0) toLoad.push(l)
|
||||
})
|
||||
}
|
||||
|
||||
append(currentLanguage)
|
||||
|
||||
if (this.allOptions.preload) this.allOptions.preload.forEach((l) => append(l))
|
||||
|
||||
toLoad.forEach(lng => {
|
||||
this.allOptions.ns.forEach(ns => {
|
||||
backendConnector.read(lng, ns, 'read', null, null, (err, data) => {
|
||||
if (err) logger.warn(`loading namespace ${ns} for language ${lng} failed`, err)
|
||||
if (!err && data) logger.log(`loaded namespace ${ns} for language ${lng}`, data)
|
||||
|
||||
backendConnector.loaded(`${lng}|${ns}`, err, data)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Backend.type = 'backend'
|
||||
|
||||
export default Backend
|
171
node_modules/i18next-http-backend/lib/request.js
generated
vendored
Normal file
171
node_modules/i18next-http-backend/lib/request.js
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
import { hasXMLHttpRequest } from './utils.js'
|
||||
import * as fetchNode from './getFetch.cjs'
|
||||
|
||||
let fetchApi = typeof fetch === 'function' ? fetch : undefined
|
||||
if (typeof global !== 'undefined' && global.fetch) {
|
||||
fetchApi = global.fetch
|
||||
} else if (typeof window !== 'undefined' && window.fetch) {
|
||||
fetchApi = window.fetch
|
||||
}
|
||||
let XmlHttpRequestApi
|
||||
if (hasXMLHttpRequest()) {
|
||||
if (typeof global !== 'undefined' && global.XMLHttpRequest) {
|
||||
XmlHttpRequestApi = global.XMLHttpRequest
|
||||
} else if (typeof window !== 'undefined' && window.XMLHttpRequest) {
|
||||
XmlHttpRequestApi = window.XMLHttpRequest
|
||||
}
|
||||
}
|
||||
let ActiveXObjectApi
|
||||
if (typeof ActiveXObject === 'function') {
|
||||
if (typeof global !== 'undefined' && global.ActiveXObject) {
|
||||
ActiveXObjectApi = global.ActiveXObject
|
||||
} else if (typeof window !== 'undefined' && window.ActiveXObject) {
|
||||
ActiveXObjectApi = window.ActiveXObject
|
||||
}
|
||||
}
|
||||
if (!fetchApi && fetchNode && !XmlHttpRequestApi && !ActiveXObjectApi) fetchApi = fetchNode.default || fetchNode // because of strange export
|
||||
if (typeof fetchApi !== 'function') fetchApi = undefined
|
||||
|
||||
const addQueryString = (url, params) => {
|
||||
if (params && typeof params === 'object') {
|
||||
let queryString = ''
|
||||
// Must encode data
|
||||
for (const paramName in params) {
|
||||
queryString += '&' + encodeURIComponent(paramName) + '=' + encodeURIComponent(params[paramName])
|
||||
}
|
||||
if (!queryString) return url
|
||||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1)
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
const fetchIt = (url, fetchOptions, callback, altFetch) => {
|
||||
const resolver = (response) => {
|
||||
if (!response.ok) return callback(response.statusText || 'Error', { status: response.status })
|
||||
response.text().then((data) => {
|
||||
callback(null, { status: response.status, data })
|
||||
}).catch(callback)
|
||||
}
|
||||
if (altFetch) {
|
||||
// already checked to have the proper signature
|
||||
const altResponse = altFetch(url, fetchOptions)
|
||||
if (altResponse instanceof Promise) {
|
||||
altResponse.then(resolver).catch(callback)
|
||||
return
|
||||
}
|
||||
// fall through
|
||||
}
|
||||
if (typeof fetch === 'function') { // react-native debug mode needs the fetch function to be called directly (no alias)
|
||||
fetch(url, fetchOptions).then(resolver).catch(callback)
|
||||
} else {
|
||||
fetchApi(url, fetchOptions).then(resolver).catch(callback)
|
||||
}
|
||||
}
|
||||
|
||||
let omitFetchOptions = false
|
||||
|
||||
// fetch api stuff
|
||||
const requestWithFetch = (options, url, payload, callback) => {
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams)
|
||||
}
|
||||
const headers = {
|
||||
...(typeof options.customHeaders === 'function' ? options.customHeaders() : options.customHeaders)
|
||||
}
|
||||
if (typeof window === 'undefined' && typeof global !== 'undefined' && typeof global.process !== 'undefined' && global.process.versions && global.process.versions.node) {
|
||||
headers['User-Agent'] = `i18next-http-backend (node/${global.process.version}; ${global.process.platform} ${global.process.arch})`
|
||||
}
|
||||
if (payload) headers['Content-Type'] = 'application/json'
|
||||
const reqOptions = typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions
|
||||
const fetchOptions = {
|
||||
method: payload ? 'POST' : 'GET',
|
||||
body: payload ? options.stringify(payload) : undefined,
|
||||
headers,
|
||||
...(omitFetchOptions ? {} : reqOptions)
|
||||
}
|
||||
const altFetch = typeof options.alternateFetch === 'function' && options.alternateFetch.length >= 1 ? options.alternateFetch : undefined
|
||||
try {
|
||||
fetchIt(url, fetchOptions, callback, altFetch)
|
||||
} catch (e) {
|
||||
if (!reqOptions || Object.keys(reqOptions).length === 0 || !e.message || e.message.indexOf('not implemented') < 0) {
|
||||
return callback(e)
|
||||
}
|
||||
try {
|
||||
Object.keys(reqOptions).forEach((opt) => {
|
||||
delete fetchOptions[opt]
|
||||
})
|
||||
fetchIt(url, fetchOptions, callback, altFetch)
|
||||
omitFetchOptions = true
|
||||
} catch (err) {
|
||||
callback(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// xml http request stuff
|
||||
const requestWithXmlHttpRequest = (options, url, payload, callback) => {
|
||||
if (payload && typeof payload === 'object') {
|
||||
// if (!cache) payload._t = Date.now()
|
||||
// URL encoded form payload must be in querystring format
|
||||
payload = addQueryString('', payload).slice(1)
|
||||
}
|
||||
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams)
|
||||
}
|
||||
|
||||
try {
|
||||
let x
|
||||
if (XmlHttpRequestApi) {
|
||||
x = new XmlHttpRequestApi()
|
||||
} else {
|
||||
x = new ActiveXObjectApi('MSXML2.XMLHTTP.3.0')
|
||||
}
|
||||
x.open(payload ? 'POST' : 'GET', url, 1)
|
||||
if (!options.crossDomain) {
|
||||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
|
||||
}
|
||||
x.withCredentials = !!options.withCredentials
|
||||
if (payload) {
|
||||
x.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
|
||||
}
|
||||
if (x.overrideMimeType) {
|
||||
x.overrideMimeType('application/json')
|
||||
}
|
||||
let h = options.customHeaders
|
||||
h = typeof h === 'function' ? h() : h
|
||||
if (h) {
|
||||
for (const i in h) {
|
||||
x.setRequestHeader(i, h[i])
|
||||
}
|
||||
}
|
||||
x.onreadystatechange = () => {
|
||||
x.readyState > 3 && callback(x.status >= 400 ? x.statusText : null, { status: x.status, data: x.responseText })
|
||||
}
|
||||
x.send(payload)
|
||||
} catch (e) {
|
||||
console && console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
const request = (options, url, payload, callback) => {
|
||||
if (typeof payload === 'function') {
|
||||
callback = payload
|
||||
payload = undefined
|
||||
}
|
||||
callback = callback || (() => {})
|
||||
|
||||
if (fetchApi && url.indexOf('file:') !== 0) {
|
||||
// use fetch api
|
||||
return requestWithFetch(options, url, payload, callback)
|
||||
}
|
||||
|
||||
if (hasXMLHttpRequest() || typeof ActiveXObject === 'function') {
|
||||
// use xml http request
|
||||
return requestWithXmlHttpRequest(options, url, payload, callback)
|
||||
}
|
||||
|
||||
callback(new Error('No fetch and no xhr implementation found!'))
|
||||
}
|
||||
|
||||
export default request
|
44
node_modules/i18next-http-backend/lib/utils.js
generated
vendored
Normal file
44
node_modules/i18next-http-backend/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
const arr = []
|
||||
const each = arr.forEach
|
||||
const slice = arr.slice
|
||||
|
||||
export function defaults (obj) {
|
||||
each.call(slice.call(arguments, 1), (source) => {
|
||||
if (source) {
|
||||
for (const prop in source) {
|
||||
if (obj[prop] === undefined) obj[prop] = source[prop]
|
||||
}
|
||||
}
|
||||
})
|
||||
return obj
|
||||
}
|
||||
|
||||
export function hasXMLHttpRequest () {
|
||||
return (typeof XMLHttpRequest === 'function' || typeof XMLHttpRequest === 'object')
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the given `maybePromise` is a Promise.
|
||||
*
|
||||
* @param {*} maybePromise
|
||||
*
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
function isPromise (maybePromise) {
|
||||
return !!maybePromise && typeof maybePromise.then === 'function'
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert any value to a Promise than will resolve to this value.
|
||||
*
|
||||
* @param {*} maybePromise
|
||||
*
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export function makePromise (maybePromise) {
|
||||
if (isPromise(maybePromise)) {
|
||||
return maybePromise
|
||||
}
|
||||
|
||||
return Promise.resolve(maybePromise)
|
||||
}
|
19
node_modules/i18next-http-backend/licence
generated
vendored
Normal file
19
node_modules/i18next-http-backend/licence
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2024 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.
|
91
node_modules/i18next-http-backend/package.json
generated
vendored
Normal file
91
node_modules/i18next-http-backend/package.json
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
{
|
||||
"name": "i18next-http-backend",
|
||||
"version": "2.7.3",
|
||||
"private": false,
|
||||
"type": "module",
|
||||
"main": "./cjs/index.js",
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
"types": {
|
||||
"require": "./cjs/index.d.ts",
|
||||
"import": "./esm/index.d.mts"
|
||||
},
|
||||
"module": "./esm/index.js",
|
||||
"import": "./esm/index.js",
|
||||
"require": "./cjs/index.js",
|
||||
"default": "./esm/index.js"
|
||||
},
|
||||
"./cjs": {
|
||||
"types": "./cjs/index.d.ts",
|
||||
"default": "./cjs/index.js"
|
||||
},
|
||||
"./esm": {
|
||||
"types": "./esm/index.d.ts",
|
||||
"default": "./esm/index.js"
|
||||
}
|
||||
},
|
||||
"module": "./esm/index.js",
|
||||
"dependencies": {
|
||||
"cross-fetch": "4.0.0"
|
||||
},
|
||||
"types": "./index.d.mts",
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.24.8",
|
||||
"@babel/core": "7.25.2",
|
||||
"@babel/preset-env": "7.25.3",
|
||||
"babel-plugin-add-module-exports": "1.0.4",
|
||||
"browserify": "17.0.0",
|
||||
"dtslint": "4.2.1",
|
||||
"eslint": "8.56.0",
|
||||
"eslint-config-standard": "17.1.0",
|
||||
"eslint-plugin-import": "2.29.1",
|
||||
"eslint-plugin-n": "16.6.2",
|
||||
"eslint-plugin-promise": "6.1.1",
|
||||
"eslint-plugin-require-path-exists": "1.1.9",
|
||||
"eslint-plugin-standard": "5.0.0",
|
||||
"expect.js": "0.3.1",
|
||||
"i18next": "23.14.0",
|
||||
"json-server": "0.17.4",
|
||||
"json5": "2.2.3",
|
||||
"mocha": "10.7.3",
|
||||
"tslint": "5.20.1",
|
||||
"tsd": "0.31.1",
|
||||
"typescript": "5.5.4",
|
||||
"uglify-js": "3.19.2",
|
||||
"xmlhttprequest": "1.8.0"
|
||||
},
|
||||
"description": "i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.",
|
||||
"keywords": [
|
||||
"i18next",
|
||||
"i18next-backend",
|
||||
"i18next-http-backend"
|
||||
],
|
||||
"homepage": "https://github.com/i18next/i18next-http-backend",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:i18next/i18next-http-backend.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/i18next/i18next-http-backend/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"compile:esm": "rm -rf esm && mkdir esm && BABEL_ENV=esm babel lib -d esm && cp index.d.mts esm/index.d.mts && cp index.d.ts esm/index.d.ts && cp lib/getFetch.cjs esm/getFetch.cjs && rm -f esm/getFetch.js && node -e \"fs.writeFileSync('esm/getFetch.cjs', fs.readFileSync('esm/getFetch.cjs').toString().replace('/* eslint-disable no-var, no-undef */\\n', ''))\"",
|
||||
"compile:cjs": "rm -rf cjs && mkdir cjs && BABEL_ENV=cjs babel lib -d cjs && cp index.d.ts cjs/index.d.ts && echo '{\"type\":\"commonjs\"}' > cjs/package.json && cp lib/getFetch.cjs cjs/getFetch.js && node -e \"fs.writeFileSync('cjs/getFetch.js', fs.readFileSync('cjs/getFetch.js').toString().replace('/* eslint-disable no-var, no-undef */\\n', ''))\" && node -e \"fs.writeFileSync('cjs/request.js', fs.readFileSync('cjs/request.js').toString().replace('getFetch.cjs', 'getFetch.js'))\"",
|
||||
"compile": "npm run compile:esm && npm run compile:cjs",
|
||||
"browser": "browserify --ignore cross-fetch --standalone i18nextHttpBackend cjs/index.js -o i18nextHttpBackend.js && uglifyjs i18nextHttpBackend.js --compress --mangle -o i18nextHttpBackend.min.js",
|
||||
"build": "npm run compile && npm run browser",
|
||||
"test:xmlhttpreq": "mocha test -R spec --require test/fixtures/xmlHttpRequest.cjs --experimental-modules",
|
||||
"test:fetch": "mocha test -R spec --experimental-modules",
|
||||
"test": "npm run lint && npm run build && npm run test:fetch && npm run test:xmlhttpreq && npm run test:typescript",
|
||||
"test:typescript": "tslint --project tsconfig.json && tsd",
|
||||
"test:deno": "deno test --allow-net test/deno/*.js",
|
||||
"_preversion": "npm run test && npm run build && git push",
|
||||
"_postversion": "git push && git push --tags"
|
||||
},
|
||||
"tsd": {
|
||||
"directory": "test/typescript"
|
||||
}
|
||||
}
|
7
node_modules/i18next-http-backend/tslint.json
generated
vendored
Normal file
7
node_modules/i18next-http-backend/tslint.json
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"defaultSeverity": "error",
|
||||
"extends": "dtslint/dtslint.json",
|
||||
"rules": {
|
||||
"semicolon": false
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user