2 lines
7.1 KiB
JavaScript
2 lines
7.1 KiB
JavaScript
|
|
!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).i18nextBrowserLanguageDetector=t()}(this,(function(){"use strict";const{slice:e,forEach:t}=[];const o=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/,n={create(e,t,n,i){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{path:"/",sameSite:"strict"};n&&(r.expires=new Date,r.expires.setTime(r.expires.getTime()+60*n*1e3)),i&&(r.domain=i),document.cookie=function(e,t){const n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{path:"/"};let i=`${e}=${encodeURIComponent(t)}`;if(n.maxAge>0){const e=n.maxAge-0;if(Number.isNaN(e))throw new Error("maxAge should be a Number");i+=`; Max-Age=${Math.floor(e)}`}if(n.domain){if(!o.test(n.domain))throw new TypeError("option domain is invalid");i+=`; Domain=${n.domain}`}if(n.path){if(!o.test(n.path))throw new TypeError("option path is invalid");i+=`; Path=${n.path}`}if(n.expires){if("function"!=typeof n.expires.toUTCString)throw new TypeError("option expires is invalid");i+=`; Expires=${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 n.partitioned&&(i+="; Partitioned"),i}(e,t,r)},read(e){const t=`${e}=`,o=document.cookie.split(";");for(let e=0;e<o.length;e++){let n=o[e];for(;" "===n.charAt(0);)n=n.substring(1,n.length);if(0===n.indexOf(t))return n.substring(t.length,n.length)}return null},remove(e,t){this.create(e,"",-1,t)}};var i={name:"cookie",lookup(e){let{lookupCookie:t}=e;if(t&&"undefined"!=typeof document)return n.read(t)||void 0},cacheUserLanguage(e,t){let{lookupCookie:o,cookieMinutes:i,cookieDomain:r,cookieOptions:s}=t;o&&"undefined"!=typeof document&&n.create(o,e,i,r,s)}},r={name:"querystring",lookup(e){let t,{lookupQuerystring:o}=e;if("undefined"!=typeof window){let{search:e}=window.location;!window.location.search&&window.location.hash?.indexOf("?")>-1&&(e=window.location.hash.substring(window.location.hash.indexOf("?")));const n=e.substring(1).split("&");for(let e=0;e<n.length;e++){const i=n[e].indexOf("=");if(i>0){n[e].substring(0,i)===o&&(t=n[e].substring(i+1))}}}return t}},s={name:"hash",lookup(e){let t,{lookupHash:o,lookupFromHashIndex:n}=e;if("undefined"!=typeof window){const{hash:e}=window.location;if(e&&e.length>2){const i=e.substring(1);if(o){const e=i.split("&");for(let n=0;n<e.length;n++){const i=e[n].indexOf("=");if(i>0){e[n].substring(0,i)===o&&(t=e[n].substring(i+1))}}}if(t)return t;if(!t&&n>-1){const t=e.match(/\/([a-zA-Z-]*)/g);if(!Array.isArray(t))return;const o="number"==typeof n?n:0;return t[o]?.replace("/","")}}}return t}};let a=null;const l=()=>{if(null!==a)return a;try{if(a="undefined"!=typeof window&&null!==window.localStorage,!a)return!1;const e="i18next.translate.boo";window.localStorage.setItem(e,"foo"),window.localStorage.removeItem(e)}catch(e){a=!1}return a};var c={name:"localStorage",lookup(e){let{lookupLocalStorage:t}=e;if(t&&l())return window.localStorage.getItem(t)||void 0},cacheUserLanguage(e,t){let{lookupLocalStorage:o}=t;o&&l()&&window.localStorage.setItem(o,e)}};let u=null;const d=()=>{if(null!==u)return u;try{if(u="undefined"!=typeof window&&null!==window.sessionStorage,!u)return!1;const e="i18next.translate.boo";window.sessionStorage.setItem(e,"foo"),window.sessionStorage.removeItem(e)}catch(e){u=!1}return u};var h={name:"sessionStorage",lookup(e){let{lookupSessionStorage:t}=e;if(t&&d())return window.sessionStorage.getItem(t)||void 0},cacheUserLanguage(e,t){let{lookupSessionStorage:o}=t;o&&d()&&window.sessionStorage.setItem(o,e)}},g={name:"navigator",lookup(e){const t=[];if("undefined"!=typeof navigator){const{languages:e,userLanguage:o,language:n}=navigator;if(e)for(let o=0;o<e.length;o++)t.push(e[o]);o&&t.push(o),n
|