Socket
Socket
Sign inDemoInstall

next-language-detector

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-language-detector - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

index.d.mts

162

dist/umd/i18nextNextLanguageDetector.js

@@ -62,2 +62,28 @@ (function (global, factory) {

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 _toPrimitive(input, hint) {
if (_typeof(input) !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (_typeof(res) !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return _typeof(key) === "symbol" ? key : String(key);
}
function _defineProperties(target, props) {

@@ -69,6 +95,5 @@ for (var i = 0; i < props.length; i++) {

if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {

@@ -99,3 +124,2 @@ if (protoProps) _defineProperties(Constructor.prototype, protoProps);

var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
var serializeCookie = function serializeCookie(name, val, options) {

@@ -105,10 +129,8 @@ var opt = options || {};

var value = encodeURIComponent(val);
var str = name + '=' + value;
var str = "".concat(name, "=").concat(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 (Number.isNaN(maxAge)) throw new Error('maxAge should be a Number');
str += "; Max-Age=".concat(Math.floor(maxAge));
}
if (opt.domain) {

@@ -118,6 +140,4 @@ if (!fieldContentRegExp.test(opt.domain)) {

}
str += '; Domain=' + opt.domain;
str += "; Domain=".concat(opt.domain);
}
if (opt.path) {

@@ -127,6 +147,4 @@ if (!fieldContentRegExp.test(opt.path)) {

}
str += '; Path=' + opt.path;
str += "; Path=".concat(opt.path);
}
if (opt.expires) {

@@ -136,12 +154,8 @@ if (typeof opt.expires.toUTCString !== 'function') {

}
str += '; Expires=' + opt.expires.toUTCString();
str += "; Expires=".concat(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) {

@@ -151,15 +165,11 @@ case true:

break;
case 'lax':
str += '; SameSite=Lax';
break;
case 'strict':
str += '; SameSite=Strict';
break;
case 'none':
str += '; SameSite=None';
break;
default:

@@ -169,6 +179,4 @@ throw new TypeError('option sameSite is invalid');

}
return str;
};
var cookie = {

@@ -180,3 +188,2 @@ create: function create(name, value, minutes, domain) {

};
if (minutes) {

@@ -186,3 +193,2 @@ cookieOptions.expires = new Date();

}
if (domain) cookieOptions.domain = domain;

@@ -192,15 +198,9 @@ document.cookie = serializeCookie(name, encodeURIComponent(value), cookieOptions);

read: function read(name) {
var nameEQ = name + '=';
var nameEQ = "".concat(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);
}
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
}
return null;

@@ -216,3 +216,2 @@ },

var found;
if (options.lookupCookie && typeof document !== 'undefined') {

@@ -222,3 +221,2 @@ var c = cookie.read(options.lookupCookie);

}
return found;

@@ -237,13 +235,13 @@ },

var found;
if (typeof window !== 'undefined') {
var query = window.location.search.substring(1);
var search = window.location.search;
if (!window.location.search && window.location.hash && window.location.hash.indexOf('?') > -1) {
search = window.location.hash.substring(window.location.hash.indexOf('?'));
}
var query = 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) {

@@ -255,3 +253,2 @@ found = params[i].substring(pos + 1);

}
return found;

@@ -262,6 +259,4 @@ }

var hasLocalStorageSupport = null;
var localStorageAvailable = function localStorageAvailable() {
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
try {

@@ -275,6 +270,4 @@ hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null;

}
return hasLocalStorageSupport;
};
var localStorage = {

@@ -284,3 +277,2 @@ name: 'localStorage',

var found;
if (options.lookupLocalStorage && localStorageAvailable()) {

@@ -290,3 +282,2 @@ var lng = window.localStorage.getItem(options.lookupLocalStorage);

}
return found;

@@ -302,6 +293,4 @@ },

var hasSessionStorageSupport = null;
var sessionStorageAvailable = function sessionStorageAvailable() {
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
try {

@@ -315,6 +304,4 @@ hasSessionStorageSupport = window !== 'undefined' && window.sessionStorage !== null;

}
return hasSessionStorageSupport;
};
var sessionStorage = {

@@ -324,3 +311,2 @@ name: 'sessionStorage',

var found;
if (options.lookupSessionStorage && sessionStorageAvailable()) {

@@ -330,3 +316,2 @@ var lng = window.sessionStorage.getItem(options.lookupSessionStorage);

}
return found;

@@ -345,3 +330,2 @@ },

var found = [];
if (typeof navigator !== 'undefined') {

@@ -354,7 +338,5 @@ if (navigator.languages) {

}
if (navigator.userLanguage) {
found.push(navigator.userLanguage);
}
if (navigator.language) {

@@ -364,3 +346,2 @@ found.push(navigator.language);

}
return found.length > 0 ? found : undefined;

@@ -375,7 +356,5 @@ }

var htmlTag = options.htmlTag || (typeof document !== 'undefined' ? document.documentElement : null);
if (htmlTag && typeof htmlTag.getAttribute === 'function') {
found = htmlTag.getAttribute('lang');
}
return found;

@@ -389,6 +368,4 @@ }

var found;
if (typeof window !== 'undefined') {
var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
if (language instanceof Array) {

@@ -399,3 +376,2 @@ if (typeof options.lookupFromPathIndex === 'number') {

}
found = language[options.lookupFromPathIndex].replace('/', '');

@@ -407,3 +383,2 @@ } else {

}
return found;

@@ -416,17 +391,13 @@ }

lookup: function lookup(options) {
var found;
// If given get the subdomain index else 1
var lookupFromSubdomainIndex = typeof options.lookupFromSubdomainIndex === 'number' ? options.lookupFromSubdomainIndex + 1 : 1;
// get all matches if window.location. is existing
// first item of match is the match itself and the second is the first group macht which sould be the first subdomain match
// is the hostname no public domain get the or option of localhost
var language = typeof window !== 'undefined' && window.location && window.location.hostname && window.location.hostname.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i);
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;
// if there is no match (null) return undefined
if (!language) return undefined;
// return the given group match
return language[lookupFromSubdomainIndex];
}

@@ -444,14 +415,15 @@ };

caches: ['localStorage'],
excludeCacheFor: ['cimode'] //cookieMinutes: 10,
//cookieDomain: 'myDomain'
excludeCacheFor: ['cimode'],
// cookieMinutes: 10,
// cookieDomain: 'myDomain'
convertDetectedLanguage: function convertDetectedLanguage(l) {
return l;
}
};
}
var Browser = /*#__PURE__*/function () {
function Browser(services) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, Browser);
this.type = 'languageDetector';

@@ -461,3 +433,2 @@ this.detectors = {};

}
_createClass(Browser, [{

@@ -468,5 +439,13 @@ key: "init",

var i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
this.services = services;
this.options = defaults(options, this.options || {}, getDefaults()); // backwards compatibility
this.services = services || {
languageUtils: {}
}; // this way the language detector can be used without i18next
this.options = defaults(options, this.options || {}, getDefaults());
if (typeof this.options.convertDetectedLanguage === 'string' && this.options.convertDetectedLanguage.indexOf('15897') > -1) {
this.options.convertDetectedLanguage = function (l) {
return l.replace('-', '_');
};
}
// backwards compatibility
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;

@@ -492,3 +471,2 @@ this.i18nOptions = i18nOptions;

var _this = this;
if (!detectionOrder) detectionOrder = this.options.order;

@@ -499,3 +477,2 @@ var detected = [];

var lookup = _this.detectors[detectorName].lookup(_this.options);
if (lookup && typeof lookup === 'string') lookup = [lookup];

@@ -505,4 +482,6 @@ if (lookup) detected = detected.concat(lookup);

});
detected = detected.map(function (d) {
return _this.options.convertDetectedLanguage(d);
});
if (this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
return detected.length > 0 ? detected[0] : null; // a little backward compatibility

@@ -514,3 +493,2 @@ }

var _this2 = this;
if (!caches) caches = this.options.caches;

@@ -524,6 +502,4 @@ if (!caches) return;

}]);
return Browser;
}();
Browser.type = 'languageDetector';

@@ -530,0 +506,0 @@

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).i18nextNextLanguageDetector=t()}(this,(function(){"use strict";function e(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function t(e,t){if(null==e)return{};var o,n,r=function(e,t){if(null==e)return{};var o,n,r={},i=Object.keys(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||(r[o]=e[o]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(r[o]=e[o])}return r}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var r=[],i=r.forEach,a=r.slice;function u(e){return i.call(a.call(arguments,1),(function(t){if(t)for(var o in t)void 0===e[o]&&(e[o]=t[o])})),e}var s=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/,c=function(e,t,o){var n=o||{};n.path=n.path||"/";var r=e+"="+encodeURIComponent(t);if(n.maxAge>0){var i=n.maxAge-0;if(isNaN(i))throw new Error("maxAge should be a Number");r+="; Max-Age="+Math.floor(i)}if(n.domain){if(!s.test(n.domain))throw new TypeError("option domain is invalid");r+="; Domain="+n.domain}if(n.path){if(!s.test(n.path))throw new TypeError("option path is invalid");r+="; Path="+n.path}if(n.expires){if("function"!=typeof n.expires.toUTCString)throw new TypeError("option expires is invalid");r+="; Expires="+n.expires.toUTCString()}if(n.httpOnly&&(r+="; HttpOnly"),n.secure&&(r+="; Secure"),n.sameSite)switch("string"==typeof n.sameSite?n.sameSite.toLowerCase():n.sameSite){case!0:r+="; SameSite=Strict";break;case"lax":r+="; SameSite=Lax";break;case"strict":r+="; SameSite=Strict";break;case"none":r+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}return r},l=function(e,t,o,n){var r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{path:"/",sameSite:"strict"};o&&(r.expires=new Date,r.expires.setTime(r.expires.getTime()+60*o*1e3)),n&&(r.domain=n),document.cookie=c(e,encodeURIComponent(t),r)},f=function(e){for(var t=e+"=",o=document.cookie.split(";"),n=0;n<o.length;n++){for(var r=o[n];" "===r.charAt(0);)r=r.substring(1,r.length);if(0===r.indexOf(t))return r.substring(t.length,r.length)}return null},p={name:"cookie",lookup:function(e){var t;if(e.lookupCookie&&"undefined"!=typeof document){var o=f(e.lookupCookie);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupCookie&&"undefined"!=typeof document&&l(t.lookupCookie,e,t.cookieMinutes,t.cookieDomain,t.cookieOptions)}},g={name:"querystring",lookup:function(e){var t;if("undefined"!=typeof window)for(var o=window.location.search.substring(1).split("&"),n=0;n<o.length;n++){var r=o[n].indexOf("=");if(r>0)o[n].substring(0,r)===e.lookupQuerystring&&(t=o[n].substring(r+1))}return t}},d=null,h=function(){if(null!==d)return d;try{d="undefined"!==window&&null!==window.localStorage;var e="i18next.translate.boo";window.localStorage.setItem(e,"foo"),window.localStorage.removeItem(e)}catch(e){d=!1}return d},m={name:"localStorage",lookup:function(e){var t;if(e.lookupLocalStorage&&h()){var o=window.localStorage.getItem(e.lookupLocalStorage);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupLocalStorage&&h()&&window.localStorage.setItem(t.lookupLocalStorage,e)}},v=null,w=function(){if(null!==v)return v;try{v="undefined"!==window&&null!==window.sessionStorage;var e="i18next.translate.boo";window.sessionStorage.setItem(e,"foo"),window.sessionStorage.removeItem(e)}catch(e){v=!1}return v},y={name:"sessionStorage",lookup:function(e){var t;if(e.lookupSessionStorage&&w()){var o=window.sessionStorage.getItem(e.lookupSessionStorage);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupSessionStorage&&w()&&window.sessionStorage.setItem(t.lookupSessionStorage,e)}},k={name:"navigator",lookup:function(e){var t=[];if("undefined"!=typeof navigator){if(navigator.languages)for(var o=0;o<navigator.languages.length;o++)t.push(navigator.languages[o]);navigator.userLanguage&&t.push(navigator.userLanguage),navigator.language&&t.push(navigator.language)}return t.length>0?t:void 0}},b={name:"htmlTag",lookup:function(e){var t,o=e.htmlTag||("undefined"!=typeof document?document.documentElement:null);return o&&"function"==typeof o.getAttribute&&(t=o.getAttribute("lang")),t}},S={name:"path",lookup:function(e){var t;if("undefined"!=typeof window){var o=window.location.pathname.match(/\/([a-zA-Z-]*)/g);if(o instanceof Array)if("number"==typeof e.lookupFromPathIndex){if("string"!=typeof o[e.lookupFromPathIndex])return;t=o[e.lookupFromPathIndex].replace("/","")}else t=o[0].replace("/","")}return t}},x={name:"subdomain",lookup:function(e){var t;if("undefined"!=typeof window){var o=window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);o instanceof Array&&(t="number"==typeof e.lookupFromSubdomainIndex?o[e.lookupFromSubdomainIndex].replace("http://","").replace("https://","").replace(".",""):o[0].replace("http://","").replace("https://","").replace(".",""))}return t}};var O=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,e),this.type="languageDetector",this.detectors={},this.init(t,n)}var t,r,i;return t=e,r=[{key:"init",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.services=e,this.options=u(t,this.options||{},{order:["querystring","cookie","localStorage","sessionStorage","navigator","htmlTag"],lookupQuerystring:"lng",lookupCookie:"i18next",lookupLocalStorage:"i18nextLng",lookupSessionStorage:"i18nextLng",caches:["localStorage"],excludeCacheFor:["cimode"]}),this.options.lookupFromUrlIndex&&(this.options.lookupFromPathIndex=this.options.lookupFromUrlIndex),this.i18nOptions=o,this.addDetector(p),this.addDetector(g),this.addDetector(m),this.addDetector(y),this.addDetector(k),this.addDetector(b),this.addDetector(S),this.addDetector(x)}},{key:"addDetector",value:function(e){this.detectors[e.name]=e}},{key:"detect",value:function(e){var t=this;e||(e=this.options.order);var o=[];return e.forEach((function(e){if(t.detectors[e]){var n=t.detectors[e].lookup(t.options);n&&"string"==typeof n&&(n=[n]),n&&(o=o.concat(n))}})),this.services.languageUtils.getBestMatchFromCodes?o:o.length>0?o[0]:null}},{key:"cacheUserLanguage",value:function(e,t){var o=this;t||(t=this.options.caches),t&&(this.options.excludeCacheFor&&this.options.excludeCacheFor.indexOf(e)>-1||t.forEach((function(t){o.detectors[t]&&o.detectors[t].cacheUserLanguage(e,o.options)})))}}],r&&n(t.prototype,r),i&&n(t,i),Object.defineProperty(t,"prototype",{writable:!1}),e}();O.type="languageDetector";var L=["supportedLngs","fallbackLng","order"];function C(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,n)}return o}function j(t){for(var o=1;o<arguments.length;o++){var n=null!=arguments[o]?arguments[o]:{};o%2?C(Object(n),!0).forEach((function(o){e(t,o,n[o])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):C(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var D=function(e){return e.charAt(0).toUpperCase()+e.slice(1)},I=function(e){if("string"==typeof e&&e.indexOf("-")>-1){var t=["hans","hant","latn","cyrl","cans","mong","arab"],o=e.split("-");return 2===o.length?(o[0]=o[0].toLowerCase(),o[1]=o[1].toUpperCase(),t.indexOf(o[1].toLowerCase())>-1&&(o[1]=D(o[1].toLowerCase()))):3===o.length&&(o[0]=o[0].toLowerCase(),2===o[1].length&&(o[1]=o[1].toUpperCase()),"sgn"!==o[0]&&2===o[2].length&&(o[2]=o[2].toUpperCase()),t.indexOf(o[1].toLowerCase())>-1&&(o[1]=D(o[1].toLowerCase())),t.indexOf(o[2].toLowerCase())>-1&&(o[2]=D(o[2].toLowerCase()))),o.join("-")}return e},P=function(e){var t=e.supportedLngs,o=e.fallbackLng;return function(e){if(!e)return null;var n,r=function(e){return!t||!t.length||t.indexOf(e)>-1};return e.forEach((function(e){if(!n){var o=I(e);t&&!r(o)||(n=o)}})),!n&&t&&e.forEach((function(e){if(!n){var o=function(e){if(!e||e.indexOf("-")<0)return e;var t=e.split("-");return I(t[0])}(e);n=r(o)?o:t.find((function(e){if(0===e.indexOf(o))return e}))}})),n||(n=o),n}};return function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=e.supportedLngs,n=e.fallbackLng,r=e.order,i=void 0===r?["querystring","cookie","localStorage","sessionStorage","navigator","htmlTag"]:r,a=t(e,L),u=P({supportedLngs:o,fallbackLng:n}),s=new O({languageUtils:{getBestMatchFromCodes:u}},j({order:i},a));return{detect:function(e){var t=s.detect(e);return u(t)},cache:function(e,t){return s.cacheUserLanguage(e,t)}}}}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).i18nextNextLanguageDetector=t()}(this,(function(){"use strict";function e(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function t(e,t){if(null==e)return{};var o,n,r=function(e,t){if(null==e)return{};var o,n,r={},i=Object.keys(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||(r[o]=e[o]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(r[o]=e[o])}return r}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e){var t=function(e,t){if("object"!==n(e)||null===e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var r=o.call(e,t||"default");if("object"!==n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===n(t)?t:String(t)}function i(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,r(n.key),n)}}var a=[],u=a.forEach,c=a.slice;function s(e){return u.call(c.call(arguments,1),(function(t){if(t)for(var o in t)void 0===e[o]&&(e[o]=t[o])})),e}var l=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/,f=function(e,t,o){var n=o||{};n.path=n.path||"/";var r=encodeURIComponent(t),i="".concat(e,"=").concat(r);if(n.maxAge>0){var a=n.maxAge-0;if(Number.isNaN(a))throw new Error("maxAge should be a Number");i+="; Max-Age=".concat(Math.floor(a))}if(n.domain){if(!l.test(n.domain))throw new TypeError("option domain is invalid");i+="; Domain=".concat(n.domain)}if(n.path){if(!l.test(n.path))throw new TypeError("option path is invalid");i+="; Path=".concat(n.path)}if(n.expires){if("function"!=typeof n.expires.toUTCString)throw new TypeError("option expires is invalid");i+="; Expires=".concat(n.expires.toUTCString())}if(n.httpOnly&&(i+="; HttpOnly"),n.secure&&(i+="; Secure"),n.sameSite)switch("string"==typeof n.sameSite?n.sameSite.toLowerCase():n.sameSite){case!0:i+="; SameSite=Strict";break;case"lax":i+="; SameSite=Lax";break;case"strict":i+="; SameSite=Strict";break;case"none":i+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}return i},g=function(e,t,o,n){var r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{path:"/",sameSite:"strict"};o&&(r.expires=new Date,r.expires.setTime(r.expires.getTime()+60*o*1e3)),n&&(r.domain=n),document.cookie=f(e,encodeURIComponent(t),r)},p=function(e){for(var t="".concat(e,"="),o=document.cookie.split(";"),n=0;n<o.length;n++){for(var r=o[n];" "===r.charAt(0);)r=r.substring(1,r.length);if(0===r.indexOf(t))return r.substring(t.length,r.length)}return null},d={name:"cookie",lookup:function(e){var t;if(e.lookupCookie&&"undefined"!=typeof document){var o=p(e.lookupCookie);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupCookie&&"undefined"!=typeof document&&g(t.lookupCookie,e,t.cookieMinutes,t.cookieDomain,t.cookieOptions)}},h={name:"querystring",lookup:function(e){var t;if("undefined"!=typeof window){var o=window.location.search;!window.location.search&&window.location.hash&&window.location.hash.indexOf("?")>-1&&(o=window.location.hash.substring(window.location.hash.indexOf("?")));for(var n=o.substring(1).split("&"),r=0;r<n.length;r++){var i=n[r].indexOf("=");if(i>0)n[r].substring(0,i)===e.lookupQuerystring&&(t=n[r].substring(i+1))}}return t}},m=null,v=function(){if(null!==m)return m;try{m="undefined"!==window&&null!==window.localStorage;var e="i18next.translate.boo";window.localStorage.setItem(e,"foo"),window.localStorage.removeItem(e)}catch(e){m=!1}return m},w={name:"localStorage",lookup:function(e){var t;if(e.lookupLocalStorage&&v()){var o=window.localStorage.getItem(e.lookupLocalStorage);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupLocalStorage&&v()&&window.localStorage.setItem(t.lookupLocalStorage,e)}},y=null,b=function(){if(null!==y)return y;try{y="undefined"!==window&&null!==window.sessionStorage;var e="i18next.translate.boo";window.sessionStorage.setItem(e,"foo"),window.sessionStorage.removeItem(e)}catch(e){y=!1}return y},S={name:"sessionStorage",lookup:function(e){var t;if(e.lookupSessionStorage&&b()){var o=window.sessionStorage.getItem(e.lookupSessionStorage);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupSessionStorage&&b()&&window.sessionStorage.setItem(t.lookupSessionStorage,e)}},k={name:"navigator",lookup:function(e){var t=[];if("undefined"!=typeof navigator){if(navigator.languages)for(var o=0;o<navigator.languages.length;o++)t.push(navigator.languages[o]);navigator.userLanguage&&t.push(navigator.userLanguage),navigator.language&&t.push(navigator.language)}return t.length>0?t:void 0}},x={name:"htmlTag",lookup:function(e){var t,o=e.htmlTag||("undefined"!=typeof document?document.documentElement:null);return o&&"function"==typeof o.getAttribute&&(t=o.getAttribute("lang")),t}},O={name:"path",lookup:function(e){var t;if("undefined"!=typeof window){var o=window.location.pathname.match(/\/([a-zA-Z-]*)/g);if(o instanceof Array)if("number"==typeof e.lookupFromPathIndex){if("string"!=typeof o[e.lookupFromPathIndex])return;t=o[e.lookupFromPathIndex].replace("/","")}else t=o[0].replace("/","")}return t}},L={name:"subdomain",lookup:function(e){var t="number"==typeof e.lookupFromSubdomainIndex?e.lookupFromSubdomainIndex+1:1,o="undefined"!=typeof window&&window.location&&window.location.hostname&&window.location.hostname.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i);if(o)return o[t]}};var C=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,e),this.type="languageDetector",this.detectors={},this.init(t,n)}var t,n,r;return t=e,n=[{key:"init",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.services=e||{languageUtils:{}},this.options=s(t,this.options||{},{order:["querystring","cookie","localStorage","sessionStorage","navigator","htmlTag"],lookupQuerystring:"lng",lookupCookie:"i18next",lookupLocalStorage:"i18nextLng",lookupSessionStorage:"i18nextLng",caches:["localStorage"],excludeCacheFor:["cimode"],convertDetectedLanguage:function(e){return e}}),"string"==typeof this.options.convertDetectedLanguage&&this.options.convertDetectedLanguage.indexOf("15897")>-1&&(this.options.convertDetectedLanguage=function(e){return e.replace("-","_")}),this.options.lookupFromUrlIndex&&(this.options.lookupFromPathIndex=this.options.lookupFromUrlIndex),this.i18nOptions=o,this.addDetector(d),this.addDetector(h),this.addDetector(w),this.addDetector(S),this.addDetector(k),this.addDetector(x),this.addDetector(O),this.addDetector(L)}},{key:"addDetector",value:function(e){this.detectors[e.name]=e}},{key:"detect",value:function(e){var t=this;e||(e=this.options.order);var o=[];return e.forEach((function(e){if(t.detectors[e]){var n=t.detectors[e].lookup(t.options);n&&"string"==typeof n&&(n=[n]),n&&(o=o.concat(n))}})),o=o.map((function(e){return t.options.convertDetectedLanguage(e)})),this.services.languageUtils.getBestMatchFromCodes?o:o.length>0?o[0]:null}},{key:"cacheUserLanguage",value:function(e,t){var o=this;t||(t=this.options.caches),t&&(this.options.excludeCacheFor&&this.options.excludeCacheFor.indexOf(e)>-1||t.forEach((function(t){o.detectors[t]&&o.detectors[t].cacheUserLanguage(e,o.options)})))}}],n&&i(t.prototype,n),r&&i(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();C.type="languageDetector";var D=["supportedLngs","fallbackLng","order"];function j(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,n)}return o}function P(t){for(var o=1;o<arguments.length;o++){var n=null!=arguments[o]?arguments[o]:{};o%2?j(Object(n),!0).forEach((function(o){e(t,o,n[o])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):j(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var I=function(e){return e.charAt(0).toUpperCase()+e.slice(1)},U=function(e){if("string"==typeof e&&e.indexOf("-")>-1){var t=["hans","hant","latn","cyrl","cans","mong","arab"],o=e.split("-");return 2===o.length?(o[0]=o[0].toLowerCase(),o[1]=o[1].toUpperCase(),t.indexOf(o[1].toLowerCase())>-1&&(o[1]=I(o[1].toLowerCase()))):3===o.length&&(o[0]=o[0].toLowerCase(),2===o[1].length&&(o[1]=o[1].toUpperCase()),"sgn"!==o[0]&&2===o[2].length&&(o[2]=o[2].toUpperCase()),t.indexOf(o[1].toLowerCase())>-1&&(o[1]=I(o[1].toLowerCase())),t.indexOf(o[2].toLowerCase())>-1&&(o[2]=I(o[2].toLowerCase()))),o.join("-")}return e},E=function(e){var t=e.supportedLngs,o=e.fallbackLng;return function(e){if(!e)return null;var n,r=function(e){return!t||!t.length||t.indexOf(e)>-1};return e.forEach((function(e){if(!n){var o=U(e);t&&!r(o)||(n=o)}})),!n&&t&&e.forEach((function(e){if(!n){var o=function(e){if(!e||e.indexOf("-")<0)return e;var t=e.split("-");return U(t[0])}(e);n=r(o)?o:t.find((function(e){if(0===e.indexOf(o))return e}))}})),n||(n=o),n}};return function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=e.supportedLngs,n=e.fallbackLng,r=e.order,i=void 0===r?["querystring","cookie","localStorage","sessionStorage","navigator","htmlTag"]:r,a=t(e,D),u=E({supportedLngs:o,fallbackLng:n}),c=new C({languageUtils:{getBestMatchFromCodes:u}},P({order:i},a));return{detect:function(e){var t=c.detect(e);return u(t)},cache:function(e,t){return c.cacheUserLanguage(e,t)}}}}));
{
"name": "next-language-detector",
"version": "1.0.2",
"version": "1.1.0",
"description": "This package helps to handle language detection in next.js when using static servers only.",

@@ -12,9 +12,9 @@ "keywords": [

],
"homepage": "https://github.com/adrai/next-language-detector",
"homepage": "https://github.com/i18next/next-language-detector",
"repository": {
"type": "git",
"url": "git@github.com:adrai/next-language-detector.git"
"url": "git@github.com:i18next/next-language-detector.git"
},
"bugs": {
"url": "https://github.com/adrai/next-language-detector/issues"
"url": "https://github.com/i18next/next-language-detector/issues"
},

@@ -25,6 +25,10 @@ "type": "module",

"browser": "./dist/umd/i18nextNextLanguageDetector.js",
"types": "./index.d.ts",
"types": "./index.d.mts",
"exports": {
"./package.json": "./package.json",
".": {
"types": {
"require": "./index.d.ts",
"import": "./index.d.mts"
},
"require": "./dist/cjs/index.js",

@@ -34,5 +38,7 @@ "default": "./dist/esm/index.js"

"./cjs": {
"types": "./index.d.ts",
"default": "./dist/cjs/index.js"
},
"./esm": {
"types": "./index.d.mts",
"default": "./dist/esm/index.js"

@@ -46,3 +52,3 @@ },

"lint:javascript": "eslint .",
"lint:typescript": "eslint -c .ts.eslintrc *.d.ts test/types/**/*.test-d.ts",
"lint:typescript": "eslint -c .ts.eslintrc *.d.ts *.d.mts test/types/**/*.test-d.ts",
"lint": "npm run lint:javascript && npm run lint:typescript",

@@ -59,3 +65,3 @@ "build": "rm -rf dist && rollup -c && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",

"@babel/runtime": "7.16.7",
"i18next-browser-languagedetector": "6.1.2"
"i18next-browser-languagedetector": "7.2.0"
},

@@ -62,0 +68,0 @@ "devDependencies": {

# Introduction
[![Actions](https://github.com/adrai/next-language-detector/workflows/node/badge.svg)](https://github.com/adrai/next-language-detector/actions?query=workflow%3Anode)
[![Actions](https://github.com/i18next/next-language-detector/workflows/node/badge.svg)](https://github.com/i18next/next-language-detector/actions?query=workflow%3Anode)
[![npm version](https://img.shields.io/npm/v/next-language-detector.svg?style=flat-square)](https://www.npmjs.com/package/next-language-detector)

@@ -23,5 +23,5 @@

**A complete example can be found [here](https://github.com/adrai/next-language-detector/tree/main/example).**
**A complete example can be found [here](https://github.com/i18next/next-language-detector/tree/main/examples/basic).**
**And for a step by step guide please have a look at [this tutorial](https://dev.to/adrai/static-html-export-with-i18n-compatibility-in-nextjs-8cd).**
**And for a step by step guide please have a look at [this tutorial](https://locize.com/blog/next-i18n-static/).**

@@ -28,0 +28,0 @@ ```js

@@ -11,4 +11,5 @@ {

"/test/types/*.test-d.ts",
"/*.d.ts"
"/*.d.ts",
"/*.d.mts"
]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc