first commit
This commit is contained in:
8
node_modules/i18next-browser-languagedetector/.prettierrc
generated
vendored
Normal file
8
node_modules/i18next-browser-languagedetector/.prettierrc
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"bracketSpacing": true,
|
||||
"jsxBracketSameLine": false,
|
||||
"printWidth": 100,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
109
node_modules/i18next-browser-languagedetector/CHANGELOG.md
generated
vendored
Normal file
109
node_modules/i18next-browser-languagedetector/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
### 6.0.1
|
||||
|
||||
- optimize check for local storage and session storage [222](https://github.com/i18next/i18next-browser-languageDetector/pull/222)
|
||||
|
||||
|
||||
### 6.0.0
|
||||
|
||||
- **BREAKING** rename lookupSessionStorage and add it to defaults [221](https://github.com/i18next/i18next-browser-languageDetector/pull/221)
|
||||
|
||||
### 5.0.1
|
||||
|
||||
- optimize cookie serialization and set sameSite to strict by default, to prepare for browser changes
|
||||
|
||||
### 5.0.0
|
||||
|
||||
- **BREAKING** needs i18next >= 19.5.0
|
||||
- let i18next figure out which detected lng is best match
|
||||
|
||||
### 4.3.1
|
||||
|
||||
- typescript Updated typescript typings for DetectorOptions to align with current options [216](https://github.com/i18next/i18next-browser-languageDetector/pull/216)
|
||||
|
||||
### 4.3.0
|
||||
|
||||
- sessionStorage support [215](https://github.com/i18next/i18next-browser-languageDetector/pull/215)
|
||||
|
||||
### 4.2.0
|
||||
|
||||
- Add config option checkForSimilarInWhitelist [211](https://github.com/i18next/i18next-browser-languageDetector/pull/211)
|
||||
|
||||
### 4.1.1
|
||||
|
||||
- fix: pass cookieOptions with the cacheUserLang [205](https://github.com/i18next/i18next-browser-languageDetector/pull/205)
|
||||
|
||||
### 4.1.0
|
||||
|
||||
- feat: add cookieOptions for setting cookies [203](https://github.com/i18next/i18next-browser-languageDetector/pull/203)
|
||||
|
||||
### 4.0.2
|
||||
|
||||
- update index file to reflect build changes done in 4.0.0
|
||||
|
||||
### 4.0.1
|
||||
|
||||
- typescript: Use updated ts export default from i18next [194](https://github.com/i18next/i18next-browser-languageDetector/pull/194)
|
||||
|
||||
### 4.0.0
|
||||
|
||||
- removes deprecated jsnext:main from package.json
|
||||
- Bundle all entry points with rollup bringing it up to same standard as [xhr-backend](https://github.com/i18next/i18next-xhr-backend/pull/314)
|
||||
- **note:** dist/es -> dist/esm, dist/commonjs -> dist/cjs (individual files -> one bundled file)
|
||||
- removes bower finally
|
||||
|
||||
### v3.1.1
|
||||
|
||||
- add default checkWhitelist: true
|
||||
|
||||
### v3.1.0
|
||||
|
||||
- Added option to prevent checking whitelist for detected languages `checkWhitelist: true` [190](https://github.com/i18next/i18next-browser-languageDetector/pull/190)
|
||||
|
||||
### v3.0.3
|
||||
|
||||
- Remove clutter from npm package [181](https://github.com/i18next/i18next-browser-languageDetector/pull/181)
|
||||
|
||||
### v3.0.2
|
||||
|
||||
- typescript: Fix types for `use()` module [180](https://github.com/i18next/i18next-browser-languageDetector/pull/180)
|
||||
|
||||
### v3.0.1
|
||||
|
||||
- typescript: fix types [165](https://github.com/i18next/i18next-browser-languageDetector/pull/165)
|
||||
|
||||
### v3.0.0
|
||||
|
||||
- typescript: add types [164](https://github.com/i18next/i18next-browser-languageDetector/pull/164)
|
||||
|
||||
### v2.2.4
|
||||
|
||||
- fix [157](https://github.com/i18next/i18next-browser-languageDetector/issues/157)
|
||||
|
||||
### v2.2.3
|
||||
|
||||
- fix [159](https://github.com/i18next/i18next-browser-languageDetector/pull/159)
|
||||
|
||||
### v2.2.2
|
||||
|
||||
- Lang by path: skip if language not found [159](https://github.com/i18next/i18next-browser-languageDetector/pull/159)
|
||||
|
||||
### v2.2.1
|
||||
|
||||
- fixes option validation in path lookup [158](https://github.com/i18next/i18next-browser-languageDetector/issues/158)
|
||||
- fixes lookup from href for subdomain [157](https://github.com/i18next/i18next-browser-languageDetector/issues/157)
|
||||
|
||||
### v2.2.0
|
||||
|
||||
- add detector for path and subdomain [PR153](https://github.com/i18next/i18next-browser-languageDetector/pull/153) and [PR152](https://github.com/i18next/i18next-browser-languageDetector/pull/152)
|
||||
|
||||
### v2.1.1
|
||||
|
||||
- support for fallback language in form of object [151](https://github.com/i18next/i18next-browser-languageDetector/issues/151)
|
||||
|
||||
### v2.1.0
|
||||
|
||||
- add .js for browser import implementation [PR147](https://github.com/i18next/i18next-browser-languageDetector/pull/147)
|
||||
|
||||
### v2.0.0
|
||||
|
||||
- [BREAKING] options.excludeCacheFor (array of language codes; default ['cimode']): if a language maps a value in that list the language will not be written to cache (eg. localStorage, cookie). If you use lng cimode in your tests and require it to be cached set the option to false or empty array
|
22
node_modules/i18next-browser-languagedetector/LICENSE
generated
vendored
Normal file
22
node_modules/i18next-browser-languagedetector/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 i18next
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
157
node_modules/i18next-browser-languagedetector/README.md
generated
vendored
Normal file
157
node_modules/i18next-browser-languagedetector/README.md
generated
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
# Introduction
|
||||
|
||||
[](https://www.npmjs.com/package/i18next-browser-languagedetector)
|
||||
[]()
|
||||
[](https://david-dm.org/i18next/i18next-browser-languagedetector)
|
||||
|
||||
This is a i18next language detection plugin use to detect user language in the browser with support for:
|
||||
|
||||
- cookie (set cookie i18next=LANGUAGE)
|
||||
- sessionStorage (set key i18nextLng=LANGUAGE)
|
||||
- localStorage (set key i18nextLng=LANGUAGE)
|
||||
- navigator (set browser language)
|
||||
- querystring (append `?lng=LANGUAGE` to URL)
|
||||
- htmlTag (add html language tag <html lang="LANGUAGE" ...)
|
||||
- path (http://my.site.com/LANGUAGE/...)
|
||||
- subdomain (http://LANGUAGE.site.com/...)
|
||||
|
||||
# Getting started
|
||||
|
||||
Source can be loaded via [npm](https://www.npmjs.com/package/i18next-browser-languagedetector), bower or [downloaded](https://github.com/i18next/i18next-browser-languagedetector/blob/master/i18nextBrowserLanguageDetector.min.js) from this repo.
|
||||
|
||||
```
|
||||
# npm package
|
||||
$ npm install i18next-browser-languagedetector
|
||||
|
||||
# bower
|
||||
$ bower install i18next-browser-languagedetector
|
||||
```
|
||||
|
||||
- If you don't use a module loader it will be added to `window.i18nextBrowserLanguageDetector`
|
||||
|
||||
Wiring up:
|
||||
|
||||
```js
|
||||
import i18next from 'i18next';
|
||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
|
||||
i18next.use(LanguageDetector).init(i18nextOptions);
|
||||
```
|
||||
|
||||
As with all modules you can either pass the constructor function (class) to the i18next.use or a concrete instance.
|
||||
|
||||
## Detector Options
|
||||
|
||||
```js
|
||||
{
|
||||
// order and from where user language should be detected
|
||||
order: ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag', 'path', 'subdomain'],
|
||||
|
||||
// keys or params to lookup language from
|
||||
lookupQuerystring: 'lng',
|
||||
lookupCookie: 'i18next',
|
||||
lookupLocalStorage: 'i18nextLng',
|
||||
lookupSessionStorage: 'i18nextLng',
|
||||
lookupFromPathIndex: 0,
|
||||
lookupFromSubdomainIndex: 0,
|
||||
|
||||
// cache user language on
|
||||
caches: ['localStorage', 'cookie'],
|
||||
excludeCacheFor: ['cimode'], // languages to not persist (cookie, localStorage)
|
||||
|
||||
// optional expire and domain for set cookie
|
||||
cookieMinutes: 10,
|
||||
cookieDomain: 'myDomain',
|
||||
|
||||
// optional htmlTag with lang attribute, the default is:
|
||||
htmlTag: document.documentElement,
|
||||
|
||||
// optional set cookie options, reference:[MDN Set-Cookie docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie)
|
||||
cookieOptions: { path: '/', sameSite: 'strict' }
|
||||
}
|
||||
```
|
||||
|
||||
Options can be passed in:
|
||||
|
||||
**preferred** - by setting options.detection in i18next.init:
|
||||
|
||||
```js
|
||||
import i18next from 'i18next';
|
||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
|
||||
i18next.use(LanguageDetector).init({
|
||||
detection: options,
|
||||
});
|
||||
```
|
||||
|
||||
on construction:
|
||||
|
||||
```js
|
||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
const languageDetector = new LanguageDetector(null, options);
|
||||
```
|
||||
|
||||
via calling init:
|
||||
|
||||
```js
|
||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
const languageDetector = new LanguageDetector();
|
||||
languageDetector.init(options);
|
||||
```
|
||||
|
||||
## Adding own detection functionality
|
||||
|
||||
### interface
|
||||
|
||||
```js
|
||||
export default {
|
||||
name: 'myDetectorsName',
|
||||
|
||||
lookup(options) {
|
||||
// options -> are passed in options
|
||||
return 'en';
|
||||
},
|
||||
|
||||
cacheUserLanguage(lng, options) {
|
||||
// options -> are passed in options
|
||||
// lng -> current language, will be called after init and on changeLanguage
|
||||
// store it
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### adding it
|
||||
|
||||
```js
|
||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
const languageDetector = new LanguageDetector();
|
||||
languageDetector.addDetector(myDetector);
|
||||
|
||||
i18next.use(languageDetector).init({
|
||||
detection: options,
|
||||
});
|
||||
```
|
||||
|
||||
Don't forget: You have to add the name of your detector (`myDetectorsName` in this case) to the `order` array in your `options` object. Without that, your detector won't be used. See the [Detector Options section for more](#detector-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>
|
||||
|
||||
---
|
||||
|
||||
**localization as a service - locize.com**
|
||||
|
||||
Needing a translation management? Want to edit your translations with an InContext Editor? Use the orginal provided to you by the maintainers of i18next!
|
||||
|
||||

|
||||
|
||||
With using [locize](http://locize.com/?utm_source=react_i18next_readme&utm_medium=github) you directly support the future of i18next and react-i18next.
|
||||
|
||||
---
|
420
node_modules/i18next-browser-languagedetector/dist/cjs/i18nextBrowserLanguageDetector.js
generated
vendored
Normal file
420
node_modules/i18next-browser-languagedetector/dist/cjs/i18nextBrowserLanguageDetector.js
generated
vendored
Normal file
@@ -0,0 +1,420 @@
|
||||
'use strict';
|
||||
|
||||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
||||
|
||||
var _classCallCheck = _interopDefault(require('@babel/runtime/helpers/classCallCheck'));
|
||||
var _createClass = _interopDefault(require('@babel/runtime/helpers/createClass'));
|
||||
|
||||
var 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;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
||||
|
||||
var serializeCookie = function serializeCookie(name, val, options) {
|
||||
var opt = options || {};
|
||||
opt.path = opt.path || '/';
|
||||
var value = encodeURIComponent(val);
|
||||
var str = name + '=' + value;
|
||||
|
||||
if (opt.maxAge > 0) {
|
||||
var maxAge = opt.maxAge - 0;
|
||||
if (isNaN(maxAge)) throw new Error('maxAge should be a Number');
|
||||
str += '; Max-Age=' + Math.floor(maxAge);
|
||||
}
|
||||
|
||||
if (opt.domain) {
|
||||
if (!fieldContentRegExp.test(opt.domain)) {
|
||||
throw new TypeError('option domain is invalid');
|
||||
}
|
||||
|
||||
str += '; Domain=' + opt.domain;
|
||||
}
|
||||
|
||||
if (opt.path) {
|
||||
if (!fieldContentRegExp.test(opt.path)) {
|
||||
throw new TypeError('option path is invalid');
|
||||
}
|
||||
|
||||
str += '; Path=' + opt.path;
|
||||
}
|
||||
|
||||
if (opt.expires) {
|
||||
if (typeof opt.expires.toUTCString !== 'function') {
|
||||
throw new TypeError('option expires is invalid');
|
||||
}
|
||||
|
||||
str += '; Expires=' + opt.expires.toUTCString();
|
||||
}
|
||||
|
||||
if (opt.httpOnly) str += '; HttpOnly';
|
||||
if (opt.secure) str += '; Secure';
|
||||
|
||||
if (opt.sameSite) {
|
||||
var sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite;
|
||||
|
||||
switch (sameSite) {
|
||||
case true:
|
||||
str += '; SameSite=Strict';
|
||||
break;
|
||||
|
||||
case 'lax':
|
||||
str += '; SameSite=Lax';
|
||||
break;
|
||||
|
||||
case 'strict':
|
||||
str += '; SameSite=Strict';
|
||||
break;
|
||||
|
||||
case 'none':
|
||||
str += '; SameSite=None';
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new TypeError('option sameSite is invalid');
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
var cookie = {
|
||||
create: function create(name, value, minutes, domain) {
|
||||
var cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
||||
path: '/',
|
||||
sameSite: 'strict'
|
||||
};
|
||||
|
||||
if (minutes) {
|
||||
cookieOptions.expires = new Date();
|
||||
cookieOptions.expires.setTime(cookieOptions.expires.getTime() + minutes * 60 * 1000);
|
||||
}
|
||||
|
||||
if (domain) cookieOptions.domain = domain;
|
||||
document.cookie = serializeCookie(name, encodeURIComponent(value), cookieOptions);
|
||||
},
|
||||
read: function read(name) {
|
||||
var nameEQ = name + '=';
|
||||
var ca = document.cookie.split(';');
|
||||
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
|
||||
while (c.charAt(0) === ' ') {
|
||||
c = c.substring(1, c.length);
|
||||
}
|
||||
|
||||
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
remove: function remove(name) {
|
||||
this.create(name, '', -1);
|
||||
}
|
||||
};
|
||||
var cookie$1 = {
|
||||
name: 'cookie',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (options.lookupCookie && typeof document !== 'undefined') {
|
||||
var c = cookie.read(options.lookupCookie);
|
||||
if (c) found = c;
|
||||
}
|
||||
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupCookie && typeof document !== 'undefined') {
|
||||
cookie.create(options.lookupCookie, lng, options.cookieMinutes, options.cookieDomain, options.cookieOptions);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var querystring = {
|
||||
name: 'querystring',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
var query = window.location.search.substring(1);
|
||||
var params = query.split('&');
|
||||
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var pos = params[i].indexOf('=');
|
||||
|
||||
if (pos > 0) {
|
||||
var key = params[i].substring(0, pos);
|
||||
|
||||
if (key === options.lookupQuerystring) {
|
||||
found = params[i].substring(pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var hasLocalStorageSupport = null;
|
||||
|
||||
var localStorageAvailable = function localStorageAvailable() {
|
||||
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
|
||||
|
||||
try {
|
||||
hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null;
|
||||
var testKey = 'i18next.translate.boo';
|
||||
window.localStorage.setItem(testKey, 'foo');
|
||||
window.localStorage.removeItem(testKey);
|
||||
} catch (e) {
|
||||
hasLocalStorageSupport = false;
|
||||
}
|
||||
|
||||
return hasLocalStorageSupport;
|
||||
};
|
||||
|
||||
var localStorage = {
|
||||
name: 'localStorage',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (options.lookupLocalStorage && localStorageAvailable()) {
|
||||
var lng = window.localStorage.getItem(options.lookupLocalStorage);
|
||||
if (lng) found = lng;
|
||||
}
|
||||
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupLocalStorage && localStorageAvailable()) {
|
||||
window.localStorage.setItem(options.lookupLocalStorage, lng);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var hasSessionStorageSupport = null;
|
||||
|
||||
var sessionStorageAvailable = function sessionStorageAvailable() {
|
||||
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
|
||||
|
||||
try {
|
||||
hasSessionStorageSupport = window !== 'undefined' && window.sessionStorage !== null;
|
||||
var testKey = 'i18next.translate.boo';
|
||||
window.sessionStorage.setItem(testKey, 'foo');
|
||||
window.sessionStorage.removeItem(testKey);
|
||||
} catch (e) {
|
||||
hasSessionStorageSupport = false;
|
||||
}
|
||||
|
||||
return hasSessionStorageSupport;
|
||||
};
|
||||
|
||||
var sessionStorage = {
|
||||
name: 'sessionStorage',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (options.lookupSessionStorage && sessionStorageAvailable()) {
|
||||
var lng = window.sessionStorage.getItem(options.lookupSessionStorage);
|
||||
if (lng) found = lng;
|
||||
}
|
||||
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupSessionStorage && sessionStorageAvailable()) {
|
||||
window.sessionStorage.setItem(options.lookupSessionStorage, lng);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var navigator$1 = {
|
||||
name: 'navigator',
|
||||
lookup: function lookup(options) {
|
||||
var found = [];
|
||||
|
||||
if (typeof navigator !== 'undefined') {
|
||||
if (navigator.languages) {
|
||||
// chrome only; not an array, so can't use .push.apply instead of iterating
|
||||
for (var i = 0; i < navigator.languages.length; i++) {
|
||||
found.push(navigator.languages[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (navigator.userLanguage) {
|
||||
found.push(navigator.userLanguage);
|
||||
}
|
||||
|
||||
if (navigator.language) {
|
||||
found.push(navigator.language);
|
||||
}
|
||||
}
|
||||
|
||||
return found.length > 0 ? found : undefined;
|
||||
}
|
||||
};
|
||||
|
||||
var htmlTag = {
|
||||
name: 'htmlTag',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
var htmlTag = options.htmlTag || (typeof document !== 'undefined' ? document.documentElement : null);
|
||||
|
||||
if (htmlTag && typeof htmlTag.getAttribute === 'function') {
|
||||
found = htmlTag.getAttribute('lang');
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var path = {
|
||||
name: 'path',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
|
||||
|
||||
if (language instanceof Array) {
|
||||
if (typeof options.lookupFromPathIndex === 'number') {
|
||||
if (typeof language[options.lookupFromPathIndex] !== 'string') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
found = language[options.lookupFromPathIndex].replace('/', '');
|
||||
} else {
|
||||
found = language[0].replace('/', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var subdomain = {
|
||||
name: 'subdomain',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
var language = window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);
|
||||
|
||||
if (language instanceof Array) {
|
||||
if (typeof options.lookupFromSubdomainIndex === 'number') {
|
||||
found = language[options.lookupFromSubdomainIndex].replace('http://', '').replace('https://', '').replace('.', '');
|
||||
} else {
|
||||
found = language[0].replace('http://', '').replace('https://', '').replace('.', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
order: ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag'],
|
||||
lookupQuerystring: 'lng',
|
||||
lookupCookie: 'i18next',
|
||||
lookupLocalStorage: 'i18nextLng',
|
||||
lookupSessionStorage: 'i18nextLng',
|
||||
// cache user language
|
||||
caches: ['localStorage'],
|
||||
excludeCacheFor: ['cimode'] //cookieMinutes: 10,
|
||||
//cookieDomain: 'myDomain'
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
var Browser =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Browser(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, Browser);
|
||||
|
||||
this.type = 'languageDetector';
|
||||
this.detectors = {};
|
||||
this.init(services, options);
|
||||
}
|
||||
|
||||
_createClass(Browser, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
this.services = services;
|
||||
this.options = defaults(options, this.options || {}, getDefaults()); // backwards compatibility
|
||||
|
||||
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
|
||||
this.i18nOptions = i18nOptions;
|
||||
this.addDetector(cookie$1);
|
||||
this.addDetector(querystring);
|
||||
this.addDetector(localStorage);
|
||||
this.addDetector(sessionStorage);
|
||||
this.addDetector(navigator$1);
|
||||
this.addDetector(htmlTag);
|
||||
this.addDetector(path);
|
||||
this.addDetector(subdomain);
|
||||
}
|
||||
}, {
|
||||
key: "addDetector",
|
||||
value: function addDetector(detector) {
|
||||
this.detectors[detector.name] = detector;
|
||||
}
|
||||
}, {
|
||||
key: "detect",
|
||||
value: function detect(detectionOrder) {
|
||||
var _this = this;
|
||||
|
||||
if (!detectionOrder) detectionOrder = this.options.order;
|
||||
var detected = [];
|
||||
detectionOrder.forEach(function (detectorName) {
|
||||
if (_this.detectors[detectorName]) {
|
||||
var lookup = _this.detectors[detectorName].lookup(_this.options);
|
||||
|
||||
if (lookup && typeof lookup === 'string') lookup = [lookup];
|
||||
if (lookup) detected = detected.concat(lookup);
|
||||
}
|
||||
});
|
||||
if (this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
|
||||
|
||||
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
|
||||
}
|
||||
}, {
|
||||
key: "cacheUserLanguage",
|
||||
value: function cacheUserLanguage(lng, caches) {
|
||||
var _this2 = this;
|
||||
|
||||
if (!caches) caches = this.options.caches;
|
||||
if (!caches) return;
|
||||
if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > -1) return;
|
||||
caches.forEach(function (cacheName) {
|
||||
if (_this2.detectors[cacheName]) _this2.detectors[cacheName].cacheUserLanguage(lng, _this2.options);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Browser;
|
||||
}();
|
||||
|
||||
Browser.type = 'languageDetector';
|
||||
|
||||
module.exports = Browser;
|
416
node_modules/i18next-browser-languagedetector/dist/esm/i18nextBrowserLanguageDetector.js
generated
vendored
Normal file
416
node_modules/i18next-browser-languagedetector/dist/esm/i18nextBrowserLanguageDetector.js
generated
vendored
Normal file
@@ -0,0 +1,416 @@
|
||||
import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
|
||||
import _createClass from '@babel/runtime/helpers/esm/createClass';
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
||||
|
||||
var serializeCookie = function serializeCookie(name, val, options) {
|
||||
var opt = options || {};
|
||||
opt.path = opt.path || '/';
|
||||
var value = encodeURIComponent(val);
|
||||
var str = name + '=' + value;
|
||||
|
||||
if (opt.maxAge > 0) {
|
||||
var maxAge = opt.maxAge - 0;
|
||||
if (isNaN(maxAge)) throw new Error('maxAge should be a Number');
|
||||
str += '; Max-Age=' + Math.floor(maxAge);
|
||||
}
|
||||
|
||||
if (opt.domain) {
|
||||
if (!fieldContentRegExp.test(opt.domain)) {
|
||||
throw new TypeError('option domain is invalid');
|
||||
}
|
||||
|
||||
str += '; Domain=' + opt.domain;
|
||||
}
|
||||
|
||||
if (opt.path) {
|
||||
if (!fieldContentRegExp.test(opt.path)) {
|
||||
throw new TypeError('option path is invalid');
|
||||
}
|
||||
|
||||
str += '; Path=' + opt.path;
|
||||
}
|
||||
|
||||
if (opt.expires) {
|
||||
if (typeof opt.expires.toUTCString !== 'function') {
|
||||
throw new TypeError('option expires is invalid');
|
||||
}
|
||||
|
||||
str += '; Expires=' + opt.expires.toUTCString();
|
||||
}
|
||||
|
||||
if (opt.httpOnly) str += '; HttpOnly';
|
||||
if (opt.secure) str += '; Secure';
|
||||
|
||||
if (opt.sameSite) {
|
||||
var sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite;
|
||||
|
||||
switch (sameSite) {
|
||||
case true:
|
||||
str += '; SameSite=Strict';
|
||||
break;
|
||||
|
||||
case 'lax':
|
||||
str += '; SameSite=Lax';
|
||||
break;
|
||||
|
||||
case 'strict':
|
||||
str += '; SameSite=Strict';
|
||||
break;
|
||||
|
||||
case 'none':
|
||||
str += '; SameSite=None';
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new TypeError('option sameSite is invalid');
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
var cookie = {
|
||||
create: function create(name, value, minutes, domain) {
|
||||
var cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
||||
path: '/',
|
||||
sameSite: 'strict'
|
||||
};
|
||||
|
||||
if (minutes) {
|
||||
cookieOptions.expires = new Date();
|
||||
cookieOptions.expires.setTime(cookieOptions.expires.getTime() + minutes * 60 * 1000);
|
||||
}
|
||||
|
||||
if (domain) cookieOptions.domain = domain;
|
||||
document.cookie = serializeCookie(name, encodeURIComponent(value), cookieOptions);
|
||||
},
|
||||
read: function read(name) {
|
||||
var nameEQ = name + '=';
|
||||
var ca = document.cookie.split(';');
|
||||
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
|
||||
while (c.charAt(0) === ' ') {
|
||||
c = c.substring(1, c.length);
|
||||
}
|
||||
|
||||
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
remove: function remove(name) {
|
||||
this.create(name, '', -1);
|
||||
}
|
||||
};
|
||||
var cookie$1 = {
|
||||
name: 'cookie',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (options.lookupCookie && typeof document !== 'undefined') {
|
||||
var c = cookie.read(options.lookupCookie);
|
||||
if (c) found = c;
|
||||
}
|
||||
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupCookie && typeof document !== 'undefined') {
|
||||
cookie.create(options.lookupCookie, lng, options.cookieMinutes, options.cookieDomain, options.cookieOptions);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var querystring = {
|
||||
name: 'querystring',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
var query = window.location.search.substring(1);
|
||||
var params = query.split('&');
|
||||
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var pos = params[i].indexOf('=');
|
||||
|
||||
if (pos > 0) {
|
||||
var key = params[i].substring(0, pos);
|
||||
|
||||
if (key === options.lookupQuerystring) {
|
||||
found = params[i].substring(pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var hasLocalStorageSupport = null;
|
||||
|
||||
var localStorageAvailable = function localStorageAvailable() {
|
||||
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
|
||||
|
||||
try {
|
||||
hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null;
|
||||
var testKey = 'i18next.translate.boo';
|
||||
window.localStorage.setItem(testKey, 'foo');
|
||||
window.localStorage.removeItem(testKey);
|
||||
} catch (e) {
|
||||
hasLocalStorageSupport = false;
|
||||
}
|
||||
|
||||
return hasLocalStorageSupport;
|
||||
};
|
||||
|
||||
var localStorage = {
|
||||
name: 'localStorage',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (options.lookupLocalStorage && localStorageAvailable()) {
|
||||
var lng = window.localStorage.getItem(options.lookupLocalStorage);
|
||||
if (lng) found = lng;
|
||||
}
|
||||
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupLocalStorage && localStorageAvailable()) {
|
||||
window.localStorage.setItem(options.lookupLocalStorage, lng);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var hasSessionStorageSupport = null;
|
||||
|
||||
var sessionStorageAvailable = function sessionStorageAvailable() {
|
||||
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
|
||||
|
||||
try {
|
||||
hasSessionStorageSupport = window !== 'undefined' && window.sessionStorage !== null;
|
||||
var testKey = 'i18next.translate.boo';
|
||||
window.sessionStorage.setItem(testKey, 'foo');
|
||||
window.sessionStorage.removeItem(testKey);
|
||||
} catch (e) {
|
||||
hasSessionStorageSupport = false;
|
||||
}
|
||||
|
||||
return hasSessionStorageSupport;
|
||||
};
|
||||
|
||||
var sessionStorage = {
|
||||
name: 'sessionStorage',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (options.lookupSessionStorage && sessionStorageAvailable()) {
|
||||
var lng = window.sessionStorage.getItem(options.lookupSessionStorage);
|
||||
if (lng) found = lng;
|
||||
}
|
||||
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupSessionStorage && sessionStorageAvailable()) {
|
||||
window.sessionStorage.setItem(options.lookupSessionStorage, lng);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var navigator$1 = {
|
||||
name: 'navigator',
|
||||
lookup: function lookup(options) {
|
||||
var found = [];
|
||||
|
||||
if (typeof navigator !== 'undefined') {
|
||||
if (navigator.languages) {
|
||||
// chrome only; not an array, so can't use .push.apply instead of iterating
|
||||
for (var i = 0; i < navigator.languages.length; i++) {
|
||||
found.push(navigator.languages[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (navigator.userLanguage) {
|
||||
found.push(navigator.userLanguage);
|
||||
}
|
||||
|
||||
if (navigator.language) {
|
||||
found.push(navigator.language);
|
||||
}
|
||||
}
|
||||
|
||||
return found.length > 0 ? found : undefined;
|
||||
}
|
||||
};
|
||||
|
||||
var htmlTag = {
|
||||
name: 'htmlTag',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
var htmlTag = options.htmlTag || (typeof document !== 'undefined' ? document.documentElement : null);
|
||||
|
||||
if (htmlTag && typeof htmlTag.getAttribute === 'function') {
|
||||
found = htmlTag.getAttribute('lang');
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var path = {
|
||||
name: 'path',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
|
||||
|
||||
if (language instanceof Array) {
|
||||
if (typeof options.lookupFromPathIndex === 'number') {
|
||||
if (typeof language[options.lookupFromPathIndex] !== 'string') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
found = language[options.lookupFromPathIndex].replace('/', '');
|
||||
} else {
|
||||
found = language[0].replace('/', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var subdomain = {
|
||||
name: 'subdomain',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
var language = window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);
|
||||
|
||||
if (language instanceof Array) {
|
||||
if (typeof options.lookupFromSubdomainIndex === 'number') {
|
||||
found = language[options.lookupFromSubdomainIndex].replace('http://', '').replace('https://', '').replace('.', '');
|
||||
} else {
|
||||
found = language[0].replace('http://', '').replace('https://', '').replace('.', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
order: ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag'],
|
||||
lookupQuerystring: 'lng',
|
||||
lookupCookie: 'i18next',
|
||||
lookupLocalStorage: 'i18nextLng',
|
||||
lookupSessionStorage: 'i18nextLng',
|
||||
// cache user language
|
||||
caches: ['localStorage'],
|
||||
excludeCacheFor: ['cimode'] //cookieMinutes: 10,
|
||||
//cookieDomain: 'myDomain'
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
var Browser =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Browser(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, Browser);
|
||||
|
||||
this.type = 'languageDetector';
|
||||
this.detectors = {};
|
||||
this.init(services, options);
|
||||
}
|
||||
|
||||
_createClass(Browser, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
this.services = services;
|
||||
this.options = defaults(options, this.options || {}, getDefaults()); // backwards compatibility
|
||||
|
||||
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
|
||||
this.i18nOptions = i18nOptions;
|
||||
this.addDetector(cookie$1);
|
||||
this.addDetector(querystring);
|
||||
this.addDetector(localStorage);
|
||||
this.addDetector(sessionStorage);
|
||||
this.addDetector(navigator$1);
|
||||
this.addDetector(htmlTag);
|
||||
this.addDetector(path);
|
||||
this.addDetector(subdomain);
|
||||
}
|
||||
}, {
|
||||
key: "addDetector",
|
||||
value: function addDetector(detector) {
|
||||
this.detectors[detector.name] = detector;
|
||||
}
|
||||
}, {
|
||||
key: "detect",
|
||||
value: function detect(detectionOrder) {
|
||||
var _this = this;
|
||||
|
||||
if (!detectionOrder) detectionOrder = this.options.order;
|
||||
var detected = [];
|
||||
detectionOrder.forEach(function (detectorName) {
|
||||
if (_this.detectors[detectorName]) {
|
||||
var lookup = _this.detectors[detectorName].lookup(_this.options);
|
||||
|
||||
if (lookup && typeof lookup === 'string') lookup = [lookup];
|
||||
if (lookup) detected = detected.concat(lookup);
|
||||
}
|
||||
});
|
||||
if (this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
|
||||
|
||||
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
|
||||
}
|
||||
}, {
|
||||
key: "cacheUserLanguage",
|
||||
value: function cacheUserLanguage(lng, caches) {
|
||||
var _this2 = this;
|
||||
|
||||
if (!caches) caches = this.options.caches;
|
||||
if (!caches) return;
|
||||
if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > -1) return;
|
||||
caches.forEach(function (cacheName) {
|
||||
if (_this2.detectors[cacheName]) _this2.detectors[cacheName].cacheUserLanguage(lng, _this2.options);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Browser;
|
||||
}();
|
||||
|
||||
Browser.type = 'languageDetector';
|
||||
|
||||
export default Browser;
|
443
node_modules/i18next-browser-languagedetector/dist/umd/i18nextBrowserLanguageDetector.js
generated
vendored
Normal file
443
node_modules/i18next-browser-languagedetector/dist/umd/i18nextBrowserLanguageDetector.js
generated
vendored
Normal file
@@ -0,0 +1,443 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, global.i18nextBrowserLanguageDetector = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function _defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) _defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
||||
|
||||
var serializeCookie = function serializeCookie(name, val, options) {
|
||||
var opt = options || {};
|
||||
opt.path = opt.path || '/';
|
||||
var value = encodeURIComponent(val);
|
||||
var str = name + '=' + value;
|
||||
|
||||
if (opt.maxAge > 0) {
|
||||
var maxAge = opt.maxAge - 0;
|
||||
if (isNaN(maxAge)) throw new Error('maxAge should be a Number');
|
||||
str += '; Max-Age=' + Math.floor(maxAge);
|
||||
}
|
||||
|
||||
if (opt.domain) {
|
||||
if (!fieldContentRegExp.test(opt.domain)) {
|
||||
throw new TypeError('option domain is invalid');
|
||||
}
|
||||
|
||||
str += '; Domain=' + opt.domain;
|
||||
}
|
||||
|
||||
if (opt.path) {
|
||||
if (!fieldContentRegExp.test(opt.path)) {
|
||||
throw new TypeError('option path is invalid');
|
||||
}
|
||||
|
||||
str += '; Path=' + opt.path;
|
||||
}
|
||||
|
||||
if (opt.expires) {
|
||||
if (typeof opt.expires.toUTCString !== 'function') {
|
||||
throw new TypeError('option expires is invalid');
|
||||
}
|
||||
|
||||
str += '; Expires=' + opt.expires.toUTCString();
|
||||
}
|
||||
|
||||
if (opt.httpOnly) str += '; HttpOnly';
|
||||
if (opt.secure) str += '; Secure';
|
||||
|
||||
if (opt.sameSite) {
|
||||
var sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite;
|
||||
|
||||
switch (sameSite) {
|
||||
case true:
|
||||
str += '; SameSite=Strict';
|
||||
break;
|
||||
|
||||
case 'lax':
|
||||
str += '; SameSite=Lax';
|
||||
break;
|
||||
|
||||
case 'strict':
|
||||
str += '; SameSite=Strict';
|
||||
break;
|
||||
|
||||
case 'none':
|
||||
str += '; SameSite=None';
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new TypeError('option sameSite is invalid');
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
var cookie = {
|
||||
create: function create(name, value, minutes, domain) {
|
||||
var cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
||||
path: '/',
|
||||
sameSite: 'strict'
|
||||
};
|
||||
|
||||
if (minutes) {
|
||||
cookieOptions.expires = new Date();
|
||||
cookieOptions.expires.setTime(cookieOptions.expires.getTime() + minutes * 60 * 1000);
|
||||
}
|
||||
|
||||
if (domain) cookieOptions.domain = domain;
|
||||
document.cookie = serializeCookie(name, encodeURIComponent(value), cookieOptions);
|
||||
},
|
||||
read: function read(name) {
|
||||
var nameEQ = name + '=';
|
||||
var ca = document.cookie.split(';');
|
||||
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
|
||||
while (c.charAt(0) === ' ') {
|
||||
c = c.substring(1, c.length);
|
||||
}
|
||||
|
||||
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
remove: function remove(name) {
|
||||
this.create(name, '', -1);
|
||||
}
|
||||
};
|
||||
var cookie$1 = {
|
||||
name: 'cookie',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (options.lookupCookie && typeof document !== 'undefined') {
|
||||
var c = cookie.read(options.lookupCookie);
|
||||
if (c) found = c;
|
||||
}
|
||||
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupCookie && typeof document !== 'undefined') {
|
||||
cookie.create(options.lookupCookie, lng, options.cookieMinutes, options.cookieDomain, options.cookieOptions);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var querystring = {
|
||||
name: 'querystring',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
var query = window.location.search.substring(1);
|
||||
var params = query.split('&');
|
||||
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var pos = params[i].indexOf('=');
|
||||
|
||||
if (pos > 0) {
|
||||
var key = params[i].substring(0, pos);
|
||||
|
||||
if (key === options.lookupQuerystring) {
|
||||
found = params[i].substring(pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var hasLocalStorageSupport = null;
|
||||
|
||||
var localStorageAvailable = function localStorageAvailable() {
|
||||
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
|
||||
|
||||
try {
|
||||
hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null;
|
||||
var testKey = 'i18next.translate.boo';
|
||||
window.localStorage.setItem(testKey, 'foo');
|
||||
window.localStorage.removeItem(testKey);
|
||||
} catch (e) {
|
||||
hasLocalStorageSupport = false;
|
||||
}
|
||||
|
||||
return hasLocalStorageSupport;
|
||||
};
|
||||
|
||||
var localStorage = {
|
||||
name: 'localStorage',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (options.lookupLocalStorage && localStorageAvailable()) {
|
||||
var lng = window.localStorage.getItem(options.lookupLocalStorage);
|
||||
if (lng) found = lng;
|
||||
}
|
||||
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupLocalStorage && localStorageAvailable()) {
|
||||
window.localStorage.setItem(options.lookupLocalStorage, lng);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var hasSessionStorageSupport = null;
|
||||
|
||||
var sessionStorageAvailable = function sessionStorageAvailable() {
|
||||
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
|
||||
|
||||
try {
|
||||
hasSessionStorageSupport = window !== 'undefined' && window.sessionStorage !== null;
|
||||
var testKey = 'i18next.translate.boo';
|
||||
window.sessionStorage.setItem(testKey, 'foo');
|
||||
window.sessionStorage.removeItem(testKey);
|
||||
} catch (e) {
|
||||
hasSessionStorageSupport = false;
|
||||
}
|
||||
|
||||
return hasSessionStorageSupport;
|
||||
};
|
||||
|
||||
var sessionStorage = {
|
||||
name: 'sessionStorage',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (options.lookupSessionStorage && sessionStorageAvailable()) {
|
||||
var lng = window.sessionStorage.getItem(options.lookupSessionStorage);
|
||||
if (lng) found = lng;
|
||||
}
|
||||
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupSessionStorage && sessionStorageAvailable()) {
|
||||
window.sessionStorage.setItem(options.lookupSessionStorage, lng);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var navigator$1 = {
|
||||
name: 'navigator',
|
||||
lookup: function lookup(options) {
|
||||
var found = [];
|
||||
|
||||
if (typeof navigator !== 'undefined') {
|
||||
if (navigator.languages) {
|
||||
// chrome only; not an array, so can't use .push.apply instead of iterating
|
||||
for (var i = 0; i < navigator.languages.length; i++) {
|
||||
found.push(navigator.languages[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (navigator.userLanguage) {
|
||||
found.push(navigator.userLanguage);
|
||||
}
|
||||
|
||||
if (navigator.language) {
|
||||
found.push(navigator.language);
|
||||
}
|
||||
}
|
||||
|
||||
return found.length > 0 ? found : undefined;
|
||||
}
|
||||
};
|
||||
|
||||
var htmlTag = {
|
||||
name: 'htmlTag',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
var htmlTag = options.htmlTag || (typeof document !== 'undefined' ? document.documentElement : null);
|
||||
|
||||
if (htmlTag && typeof htmlTag.getAttribute === 'function') {
|
||||
found = htmlTag.getAttribute('lang');
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var path = {
|
||||
name: 'path',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
|
||||
|
||||
if (language instanceof Array) {
|
||||
if (typeof options.lookupFromPathIndex === 'number') {
|
||||
if (typeof language[options.lookupFromPathIndex] !== 'string') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
found = language[options.lookupFromPathIndex].replace('/', '');
|
||||
} else {
|
||||
found = language[0].replace('/', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var subdomain = {
|
||||
name: 'subdomain',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
var language = window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);
|
||||
|
||||
if (language instanceof Array) {
|
||||
if (typeof options.lookupFromSubdomainIndex === 'number') {
|
||||
found = language[options.lookupFromSubdomainIndex].replace('http://', '').replace('https://', '').replace('.', '');
|
||||
} else {
|
||||
found = language[0].replace('http://', '').replace('https://', '').replace('.', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
order: ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag'],
|
||||
lookupQuerystring: 'lng',
|
||||
lookupCookie: 'i18next',
|
||||
lookupLocalStorage: 'i18nextLng',
|
||||
lookupSessionStorage: 'i18nextLng',
|
||||
// cache user language
|
||||
caches: ['localStorage'],
|
||||
excludeCacheFor: ['cimode'] //cookieMinutes: 10,
|
||||
//cookieDomain: 'myDomain'
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
var Browser =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Browser(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, Browser);
|
||||
|
||||
this.type = 'languageDetector';
|
||||
this.detectors = {};
|
||||
this.init(services, options);
|
||||
}
|
||||
|
||||
_createClass(Browser, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
this.services = services;
|
||||
this.options = defaults(options, this.options || {}, getDefaults()); // backwards compatibility
|
||||
|
||||
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
|
||||
this.i18nOptions = i18nOptions;
|
||||
this.addDetector(cookie$1);
|
||||
this.addDetector(querystring);
|
||||
this.addDetector(localStorage);
|
||||
this.addDetector(sessionStorage);
|
||||
this.addDetector(navigator$1);
|
||||
this.addDetector(htmlTag);
|
||||
this.addDetector(path);
|
||||
this.addDetector(subdomain);
|
||||
}
|
||||
}, {
|
||||
key: "addDetector",
|
||||
value: function addDetector(detector) {
|
||||
this.detectors[detector.name] = detector;
|
||||
}
|
||||
}, {
|
||||
key: "detect",
|
||||
value: function detect(detectionOrder) {
|
||||
var _this = this;
|
||||
|
||||
if (!detectionOrder) detectionOrder = this.options.order;
|
||||
var detected = [];
|
||||
detectionOrder.forEach(function (detectorName) {
|
||||
if (_this.detectors[detectorName]) {
|
||||
var lookup = _this.detectors[detectorName].lookup(_this.options);
|
||||
|
||||
if (lookup && typeof lookup === 'string') lookup = [lookup];
|
||||
if (lookup) detected = detected.concat(lookup);
|
||||
}
|
||||
});
|
||||
if (this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
|
||||
|
||||
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
|
||||
}
|
||||
}, {
|
||||
key: "cacheUserLanguage",
|
||||
value: function cacheUserLanguage(lng, caches) {
|
||||
var _this2 = this;
|
||||
|
||||
if (!caches) caches = this.options.caches;
|
||||
if (!caches) return;
|
||||
if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > -1) return;
|
||||
caches.forEach(function (cacheName) {
|
||||
if (_this2.detectors[cacheName]) _this2.detectors[cacheName].cacheUserLanguage(lng, _this2.options);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Browser;
|
||||
}();
|
||||
|
||||
Browser.type = 'languageDetector';
|
||||
|
||||
return Browser;
|
||||
|
||||
})));
|
1
node_modules/i18next-browser-languagedetector/dist/umd/i18nextBrowserLanguageDetector.min.js
generated
vendored
Normal file
1
node_modules/i18next-browser-languagedetector/dist/umd/i18nextBrowserLanguageDetector.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
443
node_modules/i18next-browser-languagedetector/i18nextBrowserLanguageDetector.js
generated
vendored
Normal file
443
node_modules/i18next-browser-languagedetector/i18nextBrowserLanguageDetector.js
generated
vendored
Normal file
@@ -0,0 +1,443 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, global.i18nextBrowserLanguageDetector = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function _defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) _defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
||||
|
||||
var serializeCookie = function serializeCookie(name, val, options) {
|
||||
var opt = options || {};
|
||||
opt.path = opt.path || '/';
|
||||
var value = encodeURIComponent(val);
|
||||
var str = name + '=' + value;
|
||||
|
||||
if (opt.maxAge > 0) {
|
||||
var maxAge = opt.maxAge - 0;
|
||||
if (isNaN(maxAge)) throw new Error('maxAge should be a Number');
|
||||
str += '; Max-Age=' + Math.floor(maxAge);
|
||||
}
|
||||
|
||||
if (opt.domain) {
|
||||
if (!fieldContentRegExp.test(opt.domain)) {
|
||||
throw new TypeError('option domain is invalid');
|
||||
}
|
||||
|
||||
str += '; Domain=' + opt.domain;
|
||||
}
|
||||
|
||||
if (opt.path) {
|
||||
if (!fieldContentRegExp.test(opt.path)) {
|
||||
throw new TypeError('option path is invalid');
|
||||
}
|
||||
|
||||
str += '; Path=' + opt.path;
|
||||
}
|
||||
|
||||
if (opt.expires) {
|
||||
if (typeof opt.expires.toUTCString !== 'function') {
|
||||
throw new TypeError('option expires is invalid');
|
||||
}
|
||||
|
||||
str += '; Expires=' + opt.expires.toUTCString();
|
||||
}
|
||||
|
||||
if (opt.httpOnly) str += '; HttpOnly';
|
||||
if (opt.secure) str += '; Secure';
|
||||
|
||||
if (opt.sameSite) {
|
||||
var sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite;
|
||||
|
||||
switch (sameSite) {
|
||||
case true:
|
||||
str += '; SameSite=Strict';
|
||||
break;
|
||||
|
||||
case 'lax':
|
||||
str += '; SameSite=Lax';
|
||||
break;
|
||||
|
||||
case 'strict':
|
||||
str += '; SameSite=Strict';
|
||||
break;
|
||||
|
||||
case 'none':
|
||||
str += '; SameSite=None';
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new TypeError('option sameSite is invalid');
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
var cookie = {
|
||||
create: function create(name, value, minutes, domain) {
|
||||
var cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
||||
path: '/',
|
||||
sameSite: 'strict'
|
||||
};
|
||||
|
||||
if (minutes) {
|
||||
cookieOptions.expires = new Date();
|
||||
cookieOptions.expires.setTime(cookieOptions.expires.getTime() + minutes * 60 * 1000);
|
||||
}
|
||||
|
||||
if (domain) cookieOptions.domain = domain;
|
||||
document.cookie = serializeCookie(name, encodeURIComponent(value), cookieOptions);
|
||||
},
|
||||
read: function read(name) {
|
||||
var nameEQ = name + '=';
|
||||
var ca = document.cookie.split(';');
|
||||
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
|
||||
while (c.charAt(0) === ' ') {
|
||||
c = c.substring(1, c.length);
|
||||
}
|
||||
|
||||
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
remove: function remove(name) {
|
||||
this.create(name, '', -1);
|
||||
}
|
||||
};
|
||||
var cookie$1 = {
|
||||
name: 'cookie',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (options.lookupCookie && typeof document !== 'undefined') {
|
||||
var c = cookie.read(options.lookupCookie);
|
||||
if (c) found = c;
|
||||
}
|
||||
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupCookie && typeof document !== 'undefined') {
|
||||
cookie.create(options.lookupCookie, lng, options.cookieMinutes, options.cookieDomain, options.cookieOptions);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var querystring = {
|
||||
name: 'querystring',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
var query = window.location.search.substring(1);
|
||||
var params = query.split('&');
|
||||
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var pos = params[i].indexOf('=');
|
||||
|
||||
if (pos > 0) {
|
||||
var key = params[i].substring(0, pos);
|
||||
|
||||
if (key === options.lookupQuerystring) {
|
||||
found = params[i].substring(pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var hasLocalStorageSupport = null;
|
||||
|
||||
var localStorageAvailable = function localStorageAvailable() {
|
||||
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
|
||||
|
||||
try {
|
||||
hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null;
|
||||
var testKey = 'i18next.translate.boo';
|
||||
window.localStorage.setItem(testKey, 'foo');
|
||||
window.localStorage.removeItem(testKey);
|
||||
} catch (e) {
|
||||
hasLocalStorageSupport = false;
|
||||
}
|
||||
|
||||
return hasLocalStorageSupport;
|
||||
};
|
||||
|
||||
var localStorage = {
|
||||
name: 'localStorage',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (options.lookupLocalStorage && localStorageAvailable()) {
|
||||
var lng = window.localStorage.getItem(options.lookupLocalStorage);
|
||||
if (lng) found = lng;
|
||||
}
|
||||
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupLocalStorage && localStorageAvailable()) {
|
||||
window.localStorage.setItem(options.lookupLocalStorage, lng);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var hasSessionStorageSupport = null;
|
||||
|
||||
var sessionStorageAvailable = function sessionStorageAvailable() {
|
||||
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
|
||||
|
||||
try {
|
||||
hasSessionStorageSupport = window !== 'undefined' && window.sessionStorage !== null;
|
||||
var testKey = 'i18next.translate.boo';
|
||||
window.sessionStorage.setItem(testKey, 'foo');
|
||||
window.sessionStorage.removeItem(testKey);
|
||||
} catch (e) {
|
||||
hasSessionStorageSupport = false;
|
||||
}
|
||||
|
||||
return hasSessionStorageSupport;
|
||||
};
|
||||
|
||||
var sessionStorage = {
|
||||
name: 'sessionStorage',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (options.lookupSessionStorage && sessionStorageAvailable()) {
|
||||
var lng = window.sessionStorage.getItem(options.lookupSessionStorage);
|
||||
if (lng) found = lng;
|
||||
}
|
||||
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupSessionStorage && sessionStorageAvailable()) {
|
||||
window.sessionStorage.setItem(options.lookupSessionStorage, lng);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var navigator$1 = {
|
||||
name: 'navigator',
|
||||
lookup: function lookup(options) {
|
||||
var found = [];
|
||||
|
||||
if (typeof navigator !== 'undefined') {
|
||||
if (navigator.languages) {
|
||||
// chrome only; not an array, so can't use .push.apply instead of iterating
|
||||
for (var i = 0; i < navigator.languages.length; i++) {
|
||||
found.push(navigator.languages[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (navigator.userLanguage) {
|
||||
found.push(navigator.userLanguage);
|
||||
}
|
||||
|
||||
if (navigator.language) {
|
||||
found.push(navigator.language);
|
||||
}
|
||||
}
|
||||
|
||||
return found.length > 0 ? found : undefined;
|
||||
}
|
||||
};
|
||||
|
||||
var htmlTag = {
|
||||
name: 'htmlTag',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
var htmlTag = options.htmlTag || (typeof document !== 'undefined' ? document.documentElement : null);
|
||||
|
||||
if (htmlTag && typeof htmlTag.getAttribute === 'function') {
|
||||
found = htmlTag.getAttribute('lang');
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var path = {
|
||||
name: 'path',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
|
||||
|
||||
if (language instanceof Array) {
|
||||
if (typeof options.lookupFromPathIndex === 'number') {
|
||||
if (typeof language[options.lookupFromPathIndex] !== 'string') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
found = language[options.lookupFromPathIndex].replace('/', '');
|
||||
} else {
|
||||
found = language[0].replace('/', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var subdomain = {
|
||||
name: 'subdomain',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
var language = window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);
|
||||
|
||||
if (language instanceof Array) {
|
||||
if (typeof options.lookupFromSubdomainIndex === 'number') {
|
||||
found = language[options.lookupFromSubdomainIndex].replace('http://', '').replace('https://', '').replace('.', '');
|
||||
} else {
|
||||
found = language[0].replace('http://', '').replace('https://', '').replace('.', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
order: ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag'],
|
||||
lookupQuerystring: 'lng',
|
||||
lookupCookie: 'i18next',
|
||||
lookupLocalStorage: 'i18nextLng',
|
||||
lookupSessionStorage: 'i18nextLng',
|
||||
// cache user language
|
||||
caches: ['localStorage'],
|
||||
excludeCacheFor: ['cimode'] //cookieMinutes: 10,
|
||||
//cookieDomain: 'myDomain'
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
var Browser =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Browser(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, Browser);
|
||||
|
||||
this.type = 'languageDetector';
|
||||
this.detectors = {};
|
||||
this.init(services, options);
|
||||
}
|
||||
|
||||
_createClass(Browser, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
this.services = services;
|
||||
this.options = defaults(options, this.options || {}, getDefaults()); // backwards compatibility
|
||||
|
||||
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
|
||||
this.i18nOptions = i18nOptions;
|
||||
this.addDetector(cookie$1);
|
||||
this.addDetector(querystring);
|
||||
this.addDetector(localStorage);
|
||||
this.addDetector(sessionStorage);
|
||||
this.addDetector(navigator$1);
|
||||
this.addDetector(htmlTag);
|
||||
this.addDetector(path);
|
||||
this.addDetector(subdomain);
|
||||
}
|
||||
}, {
|
||||
key: "addDetector",
|
||||
value: function addDetector(detector) {
|
||||
this.detectors[detector.name] = detector;
|
||||
}
|
||||
}, {
|
||||
key: "detect",
|
||||
value: function detect(detectionOrder) {
|
||||
var _this = this;
|
||||
|
||||
if (!detectionOrder) detectionOrder = this.options.order;
|
||||
var detected = [];
|
||||
detectionOrder.forEach(function (detectorName) {
|
||||
if (_this.detectors[detectorName]) {
|
||||
var lookup = _this.detectors[detectorName].lookup(_this.options);
|
||||
|
||||
if (lookup && typeof lookup === 'string') lookup = [lookup];
|
||||
if (lookup) detected = detected.concat(lookup);
|
||||
}
|
||||
});
|
||||
if (this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
|
||||
|
||||
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
|
||||
}
|
||||
}, {
|
||||
key: "cacheUserLanguage",
|
||||
value: function cacheUserLanguage(lng, caches) {
|
||||
var _this2 = this;
|
||||
|
||||
if (!caches) caches = this.options.caches;
|
||||
if (!caches) return;
|
||||
if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > -1) return;
|
||||
caches.forEach(function (cacheName) {
|
||||
if (_this2.detectors[cacheName]) _this2.detectors[cacheName].cacheUserLanguage(lng, _this2.options);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Browser;
|
||||
}();
|
||||
|
||||
Browser.type = 'languageDetector';
|
||||
|
||||
return Browser;
|
||||
|
||||
})));
|
1
node_modules/i18next-browser-languagedetector/i18nextBrowserLanguageDetector.min.js
generated
vendored
Normal file
1
node_modules/i18next-browser-languagedetector/i18nextBrowserLanguageDetector.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
71
node_modules/i18next-browser-languagedetector/index.d.ts
generated
vendored
Normal file
71
node_modules/i18next-browser-languagedetector/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
import * as i18next from 'i18next';
|
||||
|
||||
interface DetectorOptions {
|
||||
/**
|
||||
* order and from where user language should be detected
|
||||
*/
|
||||
order?: Array<
|
||||
'querystring' | 'cookie' | 'sessionStorage' | 'localStorage' | 'navigator' | 'htmlTag' | string
|
||||
>;
|
||||
|
||||
/**
|
||||
* keys or params to lookup language from
|
||||
*/
|
||||
lookupQuerystring?: string;
|
||||
lookupCookie?: string;
|
||||
lookupSessionStorage?: string;
|
||||
lookupLocalStorage?: string;
|
||||
lookupFromPathIndex?: number;
|
||||
lookupFromSubdomainIndex?: number;
|
||||
|
||||
/**
|
||||
* cache user language on
|
||||
*/
|
||||
caches?: string[];
|
||||
|
||||
/**
|
||||
* languages to not persist (cookie, localStorage)
|
||||
*/
|
||||
excludeCacheFor?: string[];
|
||||
|
||||
/**
|
||||
* optional expire and domain for set cookie
|
||||
* @default 10
|
||||
*/
|
||||
cookieMinutes?: number;
|
||||
cookieDomain?: string;
|
||||
|
||||
/**
|
||||
* optional htmlTag with lang attribute
|
||||
* @default document.documentElement
|
||||
*/
|
||||
htmlTag?: HTMLElement | null;
|
||||
}
|
||||
|
||||
interface CustomDetector {
|
||||
name: string;
|
||||
cacheUserLanguage?(lng: string, options: DetectorOptions): void;
|
||||
lookup(options: DetectorOptions): string | undefined;
|
||||
}
|
||||
|
||||
export default class I18nextBrowserLanguageDetector implements i18next.LanguageDetectorModule {
|
||||
constructor(services?: any, options?: DetectorOptions);
|
||||
/**
|
||||
* Adds detector.
|
||||
*/
|
||||
addDetector(detector: CustomDetector): I18nextBrowserLanguageDetector;
|
||||
|
||||
/**
|
||||
* Initializes detector.
|
||||
*/
|
||||
init(services?: any, options?: DetectorOptions): void;
|
||||
|
||||
detect(detectionOrder?: DetectorOptions['order']): string | undefined;
|
||||
|
||||
cacheUserLanguage(lng: string, caches?: string[]): void;
|
||||
|
||||
type: 'languageDetector';
|
||||
detectors: { [key: string]: any };
|
||||
services: any;
|
||||
i18nOptions: any;
|
||||
}
|
5
node_modules/i18next-browser-languagedetector/index.js
generated
vendored
Normal file
5
node_modules/i18next-browser-languagedetector/index.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/* eslint no-var: 0 */
|
||||
var main = require('./dist/cjs/i18nextBrowserLanguageDetector.js');
|
||||
|
||||
module.exports = main;
|
||||
module.exports.default = main;
|
92
node_modules/i18next-browser-languagedetector/package.json
generated
vendored
Normal file
92
node_modules/i18next-browser-languagedetector/package.json
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
{
|
||||
"_from": "i18next-browser-languagedetector@latest",
|
||||
"_id": "i18next-browser-languagedetector@6.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-3H+OsNQn3FciomUU0d4zPFHsvJv4X66lBelXk9hnIDYDsveIgT7dWZ3/VvcSlpKk9lvCK770blRZ/CwHMXZqWw==",
|
||||
"_location": "/i18next-browser-languagedetector",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "i18next-browser-languagedetector@latest",
|
||||
"name": "i18next-browser-languagedetector",
|
||||
"escapedName": "i18next-browser-languagedetector",
|
||||
"rawSpec": "latest",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/i18next-browser-languagedetector/-/i18next-browser-languagedetector-6.0.1.tgz",
|
||||
"_shasum": "83654bc87302be2a6a5a75146ffea97b4ca268cf",
|
||||
"_spec": "i18next-browser-languagedetector@latest",
|
||||
"_where": "D:\\Projects\\vanillajs-seed",
|
||||
"author": {
|
||||
"name": "Jan Mühlemann",
|
||||
"email": "jan.muehlemann@gmail.com",
|
||||
"url": "https://github.com/jamuhl"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/i18next/i18next-browser-languageDetector/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.5.5"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "language detector used in browser environment for i18next",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.5.5",
|
||||
"@babel/plugin-transform-runtime": "^7.5.5",
|
||||
"@babel/preset-env": "^7.5.5",
|
||||
"babel-eslint": "^10.0.2",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"babelify": "^10.0.0",
|
||||
"browserify": "16.3.0",
|
||||
"browserify-istanbul": "3.0.1",
|
||||
"chai": "4.2.0",
|
||||
"coveralls": "3.0.5",
|
||||
"cpy-cli": "^2.0.0",
|
||||
"dtslint": "^0.9.1",
|
||||
"eslint": "6.1.0",
|
||||
"eslint-config-airbnb": "17.1.1",
|
||||
"expect.js": "0.3.1",
|
||||
"i18next": "^19.0.0",
|
||||
"mkdirp": "0.5.1",
|
||||
"mocha": "7.1.2",
|
||||
"rimraf": "2.6.3",
|
||||
"rollup": "^1.18.0",
|
||||
"rollup-plugin-babel": "^4.3.3",
|
||||
"rollup-plugin-node-resolve": "^5.2.0",
|
||||
"rollup-plugin-terser": "^5.1.1",
|
||||
"tslint": "^5.18.0",
|
||||
"typescript": "^3.5.3",
|
||||
"yargs": "13.3.0"
|
||||
},
|
||||
"homepage": "https://github.com/i18next/i18next-browser-languageDetector",
|
||||
"keywords": [
|
||||
"i18next",
|
||||
"i18next-languageDetector"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./dist/cjs/i18nextBrowserLanguageDetector.js",
|
||||
"module": "./dist/esm/i18nextBrowserLanguageDetector.js",
|
||||
"name": "i18next-browser-languagedetector",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/i18next/i18next-browser-languageDetector.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rimraf dist && rollup -c && cpy \"./dist/umd/*.js\" ./",
|
||||
"postversion": "git push && git push --tags",
|
||||
"pretest": "npm run test:typescript && npm run test:typescript:noninterop",
|
||||
"preversion": "npm run build && git push",
|
||||
"test": "npm run build && mocha test -R spec --exit",
|
||||
"test:typescript": "tslint --project tsconfig.json",
|
||||
"test:typescript:noninterop": "tslint --project tsconfig.nonEsModuleInterop.json"
|
||||
},
|
||||
"types": "./index.d.ts",
|
||||
"version": "6.0.1"
|
||||
}
|
8
node_modules/i18next-browser-languagedetector/tsconfig.nonEsModuleInterop.json
generated
vendored
Normal file
8
node_modules/i18next-browser-languagedetector/tsconfig.nonEsModuleInterop.json
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
// typescript defaults to these
|
||||
"esModuleInterop": false,
|
||||
"allowSyntheticDefaultImports": false
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user