-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locizer.min.js
1 lines (1 loc) · 33.9 KB
/
locizer.min.js
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).locizer=t()}(this,(function(){"use strict";function e(t){return e="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},e(t)}function t(t){var o=function(t,o){if("object"!==e(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,o||"default");if("object"!==e(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===o?String:Number)(t)}(t,"string");return"symbol"===e(o)?o:String(o)}function o(e,o,n){return(o=t(o))in e?Object.defineProperty(e,o,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[o]=n,e}var n=[],i=n.forEach,r=n.slice;function s(e){return i.call(r.call(arguments,1),(function(t){if(t)for(var o in t)void 0===e[o]&&(e[o]=t[o])})),e}function a(e,t,o){function n(e){return e&&e.indexOf("###")>-1?e.replace(/###/g,"."):e}for(var i="string"!=typeof t?[].concat(t):t.split(".");i.length>1;){if(!e)return{};var r=n(i.shift());!e[r]&&o&&(e[r]=new o),e=e[r]}return e?{obj:e,k:n(i.shift())}:{}}function c(e,t,o){var n=a(e,t,Object);n.obj[n.k]=o}function u(e,t){var o=a(e,t),n=o.obj,i=o.k;if(n)return n[i]}var l,f=new RegExp("{{(.+?)}}","g");function d(e,t,o){var n,i,r;for(;n=f.exec(e);)"string"!=typeof(i=n[1].trim())&&(i=null==(r=i)?"":""+r),i||(i=""),i=i.replace(/\$/g,"$$$$"),e=e.replace(n[0],t[i]||i),f.lastIndex=0;return e}function p(e,t){return t.reduce((function(t,o){if(t)return t;if(!e||!e[o]||"string"!=typeof e[o]||!e[o].toLowerCase()===o.toLowerCase()){var n='i18next-locize-backend :: got "'.concat(e[o],'" in options for ').concat(o," which is invalid.");return console.warn(n),n}return!1}),!1)}function g(){var e,t,o=new Promise((function(o,n){e=o,t=n}));return o.resolve=e,o.reject=t,o}if("function"==typeof fetch&&(l="undefined"!=typeof global&&global.fetch?global.fetch:"undefined"!=typeof window&&window.fetch?window.fetch:fetch),"undefined"!=typeof require&&("undefined"==typeof window||void 0===window.document)){var h=l||require("cross-fetch");h.default&&(h=h.default),exports.default=h,module.exports=exports.default}var v,y,w,b=Object.freeze({__proto__:null});function m(e){return m="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},m(e)}"function"==typeof fetch&&(v="undefined"!=typeof global&&global.fetch?global.fetch:"undefined"!=typeof window&&window.fetch?window.fetch:fetch),"function"!=typeof XMLHttpRequest&&"object"!==("undefined"==typeof XMLHttpRequest?"undefined":m(XMLHttpRequest))||("undefined"!=typeof global&&global.XMLHttpRequest?y=global.XMLHttpRequest:"undefined"!=typeof window&&window.XMLHttpRequest&&(y=window.XMLHttpRequest)),"function"==typeof ActiveXObject&&("undefined"!=typeof global&&global.ActiveXObject?w=global.ActiveXObject:"undefined"!=typeof window&&window.ActiveXObject&&(w=window.ActiveXObject)),v||!b||y||w||(v=b),"function"!=typeof v&&(v=void 0);var L=function(e,t,o,n){return"function"==typeof o&&(n=o,o=void 0),n=n||function(){},v?function(e,t,o,n){var i={};"undefined"==typeof window&&"undefined"!=typeof global&&void 0!==global.process&&global.process.versions&&global.process.versions.node&&(i["User-Agent"]="i18next-locize-backend (node/".concat(global.process.version,"; ").concat(global.process.platform," ").concat(global.process.arch,")")),e.authorize&&e.apiKey&&(i.Authorization=e.apiKey),(o||e.setContentTypeJSON)&&(i["Content-Type"]="application/json");var r=function(e){var t=e.headers&&"Error from cloudfront"===e.headers.get("x-cache");if(!e.ok)return n(e.statusText||"Error",{status:e.status,resourceNotExisting:t});e.text().then((function(o){n(null,{status:e.status,data:o,resourceNotExisting:t})})).catch(n)};"function"==typeof fetch?fetch(t,{method:o?"POST":"GET",body:o?JSON.stringify(o):void 0,headers:i}).then(r).catch(n):v(t,{method:o?"POST":"GET",body:o?JSON.stringify(o):void 0,headers:i}).then(r).catch(n)}(e,t,o,n):"function"==typeof XMLHttpRequest||"object"===("undefined"==typeof XMLHttpRequest?"undefined":m(XMLHttpRequest))||"function"==typeof ActiveXObject?function(e,t,o,n){try{var i;(i=y?new y:new w("MSXML2.XMLHTTP.3.0")).open(o?"POST":"GET",t,1),e.crossDomain||i.setRequestHeader("X-Requested-With","XMLHttpRequest"),e.authorize&&e.apiKey&&i.setRequestHeader("Authorization",e.apiKey),(o||e.setContentTypeJSON)&&i.setRequestHeader("Content-Type","application/json"),i.onreadystatechange=function(){var e="Error from cloudfront"===i.getResponseHeader("x-cache");i.readyState>3&&n(i.status>=400?i.statusText:null,{status:i.status,data:i.responseText,resourceNotExisting:e})},i.send(JSON.stringify(o))}catch(e){console&&console.log(e)}}(e,t,o,n):void n(new Error("No fetch and no xhr implementation found!"))};function k(e){return k="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},k(e)}function j(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,(i=n.key,r=void 0,r=function(e,t){if("object"!==k(e)||null===e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var n=o.call(e,t||"default");if("object"!==k(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(i,"string"),"symbol"===k(r)?r:String(r)),n)}var i,r}var x;try{x="undefined"!=typeof window&&null!==window.localStorage;var S="notExistingLocizeProject";window.localStorage.setItem(S,"foo"),window.localStorage.removeItem(S)}catch(e){x=!1}var O=function(e,t,o){var n={};return t.authorize&&t.apiKey&&(n.Authorization=t.apiKey),(o||t.setContentTypeJSON)&&(n["Content-Type"]="application/json"),{method:o?"POST":"GET",url:e,headers:n,body:o}},E=function(e,t,o){if(1!==e.request.length)e.request(t,o);else try{var n=e.request(t);n&&"function"==typeof n.then?n.then((function(e){return o(null,e)})).catch(o):o(null,n)}catch(e){o(e)}},P=function(){function e(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3?arguments[3]:void 0;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.services=t,this.options=o,this.allOptions=n,this.type="backend",t&&t.projectId?this.init(null,t,n,o):this.init(t,o,n,i)}var t,o,n;return t=e,o=[{key:"init",value:function(e){var t=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3?arguments[3]:void 0;!o.referenceLng&&n.fallbackLng&&Array.isArray(n.fallbackLng)&&"dev"!==n.fallbackLng[0]&&(o.referenceLng=n.fallbackLng[0]),this.services=e;var r,a,c,u={loadPath:"https://api.locize.app/{{projectId}}/{{version}}/{{lng}}/{{ns}}",privatePath:"https://api.locize.app/private/{{projectId}}/{{version}}/{{lng}}/{{ns}}",getLanguagesPath:"https://api.locize.app/languages/{{projectId}}",addPath:"https://api.locize.app/missing/{{projectId}}/{{version}}/{{lng}}/{{ns}}",updatePath:"https://api.locize.app/update/{{projectId}}/{{version}}/{{lng}}/{{ns}}",referenceLng:"en",crossDomain:!0,setContentTypeJSON:!1,version:"latest",private:!1,translatedPercentageThreshold:.9,failLoadingOnEmptyJSON:!1,allowedAddOrUpdateHosts:["localhost"],onSaved:!1,reloadInterval:"undefined"==typeof window&&36e5,checkForProjectTimeout:3e3,storageExpiration:36e5,writeDebounce:5e3},l=s(o,this.options||{});l.reloadInterval&&l.reloadInterval<3e5&&(console.warn("Your configured reloadInterval option is to low."),l.reloadInterval=u.reloadInterval),this.options=s(o,this.options||{},u),this.allOptions=n,this.somethingLoaded=!1,this.isProjectNotExisting=!1,this.storage=(r=this.options.storageExpiration,a=function(){},c=function(){},x?(a=function(e){window.localStorage.setItem("notExistingLocizeProject_".concat(e),Date.now())},c=function(e){var t=window.localStorage.getItem("notExistingLocizeProject_".concat(e));return!(!t||Date.now()-t>r&&(window.localStorage.removeItem("notExistingLocizeProject_".concat(e)),1))}):"undefined"!=typeof document&&(a=function(e){var t=new Date;t.setTime(t.getTime()+r);var o="; expires=".concat(t.toGMTString()),n="notExistingLocizeProject_".concat(e);try{document.cookie="".concat(n,"=").concat(Date.now()).concat(o,";path=/")}catch(e){}},c=function(e){var t="notExistingLocizeProject_".concat(e),o="".concat(t,"=");try{for(var n=document.cookie.split(";"),i=0;i<n.length;i++){for(var r=n[i];" "===r.charAt(0);)r=r.substring(1,r.length);if(0===r.indexOf(o))return!0}}catch(e){}return!1}),{setProjectNotExisting:a,isProjectNotExisting:c}),this.options.pull&&console.warn('The pull API was removed use "private: true" option instead: https://docs.locize.com/integration/api#fetch-private-namespace-resources');var f,d,p,g,h="undefined"!=typeof window&&window.location&&window.location.hostname;h?(this.isAddOrUpdateAllowed="function"==typeof this.options.allowedAddOrUpdateHosts?this.options.allowedAddOrUpdateHosts(h):this.options.allowedAddOrUpdateHosts.indexOf(h)>-1,e&&e.logger&&(n.saveMissing||n.updateMissing)&&(this.isAddOrUpdateAllowed?"localhost"!==h&&e.logger.warn('locize-backend: you are using the save or update missings feature from this host "'.concat(h,'".\nMake sure you will not use it in production!\nhttps://docs.locize.com/guides-tips-and-tricks/going-production')):e.logger.warn("function"==typeof this.options.allowedAddOrUpdateHosts?'locize-backend: will not save or update missings because allowedAddOrUpdateHosts returned false for the host "'.concat(h,'".'):'locize-backend: will not save or update missings because the host "'.concat(h,'" was not in the list of allowedAddOrUpdateHosts: ').concat(this.options.allowedAddOrUpdateHosts.join(", ")," (matches need to be exact).")))):this.isAddOrUpdateAllowed=!0,"function"==typeof i&&this.getOptions((function(e,n,r){if(e)return i(e);t.options.referenceLng=o.referenceLng||n.referenceLng||t.options.referenceLng,i(null,n,r)})),this.queuedWrites={pending:{}},this.debouncedProcess=(f=this.process,d=this.options.writeDebounce,function(){var e=this,t=arguments,o=p&&!g;clearTimeout(g),g=setTimeout((function(){g=null,p||f.apply(e,t)}),d),o&&f.apply(e,t)}),this.interval&&clearInterval(this.interval),this.options.reloadInterval&&this.options.projectId&&(this.interval=setInterval((function(){return t.reload()}),this.options.reloadInterval))}},{key:"reload",value:function(){var e=this,t=this.services||{logger:console},o=t.backendConnector,n=t.languageUtils,i=t.logger;if(o){var r=o.language;if(!r||"cimode"!==r.toLowerCase()){var s=[],a=function(e){n.toResolveHierarchy(e).forEach((function(e){s.indexOf(e)<0&&s.push(e)}))};a(r),this.allOptions.preload&&this.allOptions.preload.forEach((function(e){return a(e)})),s.forEach((function(t){e.allOptions.ns.forEach((function(e){o.read(t,e,"read",null,null,(function(n,r){n&&i.warn("loading namespace ".concat(e," for language ").concat(t," failed"),n),!n&&r&&i.log("loaded namespace ".concat(e," for language ").concat(t),r),o.loaded("".concat(t,"|").concat(e),n,r)}))}))}))}}}},{key:"getLanguages",value:function(e){var t,o=this;e||(t=g(),e=function(e,o){if(e)return t.reject(e);t.resolve(o)});var n=p(this.options,["projectId"]);if(n)return e(new Error(n));var i=d(this.options.getLanguagesPath,{projectId:this.options.projectId});return!this.isProjectNotExisting&&this.storage.isProjectNotExisting(this.options.projectId)&&(this.isProjectNotExisting=!0),this.isProjectNotExisting?e(new Error("locize project ".concat(this.options.projectId," does not exist!"))):(this.getLanguagesCalls=this.getLanguagesCalls||[],this.getLanguagesCalls.push(e),this.getLanguagesCalls.length>1?void 0:(this.loadUrl({},i,(function(e,t,n){if(!o.somethingLoaded&&n&&n.resourceNotExisting){o.isProjectNotExisting=!0,o.storage.setProjectNotExisting(o.options.projectId);var i=new Error("locize project ".concat(o.options.projectId," does not exist!")),r=o.getLanguagesCalls;return o.getLanguagesCalls=[],r.forEach((function(e){return e(i)}))}if(t){var s=Object.keys(t).reduce((function(e,o){return t[o].isReferenceLanguage&&(e=o),e}),"");s&&o.options.referenceLng!==s&&(o.options.referenceLng=s)}o.somethingLoaded=!0;var a=o.getLanguagesCalls;o.getLanguagesCalls=[],a.forEach((function(o){return o(e,t)}))})),t))}},{key:"getOptions",value:function(e){var t,o=this;return e||(t=g(),e=function(e,o){if(e)return t.reject(e);t.resolve(o)}),this.getLanguages((function(t,n){if(t)return e(t);var i=Object.keys(n);if(!i.length)return e(new Error("was unable to load languages via API"));var r=i.reduce((function(e,t){var i=n[t];return i.translated[o.options.version]&&i.translated[o.options.version]>=o.options.translatedPercentageThreshold&&e.push(t),e}),[]),s=i.reduce((function(e,t){return t.indexOf("-")>-1||e}),!1);e(null,{fallbackLng:o.options.referenceLng,referenceLng:o.options.referenceLng,supportedLngs:r,load:s?"all":"languageOnly"},n)})),t}},{key:"checkIfProjectExists",value:function(e){var t=this,o=(this.services||{logger:console}).logger;this.somethingLoaded?e&&e(null):this.alreadyRequestedCheckIfProjectExists?setTimeout((function(){return t.checkIfProjectExists(e)}),this.options.checkForProjectTimeout):(this.alreadyRequestedCheckIfProjectExists=!0,this.getLanguages((function(t){t&&t.message&&t.message.indexOf("does not exist")>0&&o&&o.error(t.message),e&&e(t)})))}},{key:"read",value:function(e,t,o){var n,i=this,r=(this.services||{logger:console}).logger,s={};if(this.options.private){var a=p(this.options,["projectId","version","apiKey"]);if(a)return o(new Error(a),!1);n=d(this.options.privatePath,{lng:e,ns:t,projectId:this.options.projectId,version:this.options.version}),s={authorize:!0}}else{var c=p(this.options,["projectId","version"]);if(c)return o(new Error(c),!1);n=d(this.options.loadPath,{lng:e,ns:t,projectId:this.options.projectId,version:this.options.version})}if(!this.isProjectNotExisting&&this.storage.isProjectNotExisting(this.options.projectId)&&(this.isProjectNotExisting=!0),this.isProjectNotExisting){var u=new Error("locize project ".concat(this.options.projectId," does not exist!"));return r&&r.error(u.message),void(o&&o(u))}this.loadUrl(s,n,(function(e,t,n){i.somethingLoaded||(n&&n.resourceNotExisting?setTimeout((function(){return i.checkIfProjectExists()}),i.options.checkForProjectTimeout):i.somethingLoaded=!0),o(e,t)}))}},{key:"loadUrl",value:function(e,t,o,n){var i=this;e=s(e,this.options),"function"==typeof o&&(n=o,o=void 0),n=n||function(){};var r=function(e,o){var r,s,a=o&&o.resourceNotExisting;if(o&&(408===o.status||400===o.status))return n("failed loading "+t,!0,{resourceNotExisting:a});if(o&&(o.status>=500&&o.status<600||!o.status))return n("failed loading "+t,!0,{resourceNotExisting:a});if(o&&o.status>=400&&o.status<500)return n("failed loading "+t,!1,{resourceNotExisting:a});if(!o&&e&&e.message&&e.message.indexOf("Failed to fetch")>-1)return n("failed loading "+t,!0,{resourceNotExisting:a});if(e)return n(e,!1);try{r="string"==typeof o.data?JSON.parse(o.data):o.data}catch(e){s="failed parsing "+t+" to json"}return s?n(s,!1):i.options.failLoadingOnEmptyJSON&&!Object.keys(r).length?n("loaded result empty for "+t,!1,{resourceNotExisting:a}):void n(null,r,{resourceNotExisting:a})};if(!this.options.request||t.indexOf("/languages/".concat(e.projectId))>0)return L(e,t,o,r);var a=O(t,e,o);E(this.options,a,r)}},{key:"create",value:function(e,t,o,n,i,r){var s=this;"function"!=typeof i&&(i=function(){}),this.checkIfProjectExists((function(a){if(a)return i(a);var c=p(s.options,["projectId","version","apiKey","referenceLng"]);return c?i(new Error(c)):s.isAddOrUpdateAllowed?("string"==typeof e&&(e=[e]),e.filter((function(e){return e===s.options.referenceLng})).length<1&&s.services&&s.services.logger&&s.services.logger.warn('locize-backend: will not save missings because the reference language "'.concat(s.options.referenceLng,'" was not in the list of to save languages: ').concat(e.join(", ")," (open your site in the reference language to save missings).")),void e.forEach((function(e){e===s.options.referenceLng&&s.queue.call(s,s.options.referenceLng,t,o,n,i,r)}))):i("host is not allowed to create key.")}))}},{key:"update",value:function(e,t,o,n,i,r){var s=this;"function"!=typeof i&&(i=function(){}),this.checkIfProjectExists((function(a){if(a)return i(a);var c=p(s.options,["projectId","version","apiKey","referenceLng"]);return c?i(new Error(c)):s.isAddOrUpdateAllowed?(r||(r={}),"string"==typeof e&&(e=[e]),r.isUpdate=!0,void e.forEach((function(e){e===s.options.referenceLng&&s.queue.call(s,s.options.referenceLng,t,o,n,i,r)}))):i("host is not allowed to update key.")}))}},{key:"writePage",value:function(e,t,o,n){var i=d(this.options.addPath,{lng:e,ns:t,projectId:this.options.projectId,version:this.options.version}),r=d(this.options.updatePath,{lng:e,ns:t,projectId:this.options.projectId,version:this.options.version}),a=!1,c=!1,u={},l={};o.forEach((function(e){var t=e.options&&e.options.tDescription?{value:e.fallbackValue||"",context:{text:e.options.tDescription}}:e.fallbackValue||"";e.options&&e.options.isUpdate?(c||(c=!0),l[e.key]=t):(a||(a=!0),u[e.key]=t)}));var f=0;a&&f++,c&&f++;var p=function(e){--f||n(e)};if(f||p(),a)if(this.options.request){var g=O(i,s({authorize:!0},this.options),u);E(this.options,g,p)}else L(s({authorize:!0},this.options),i,u,p);if(c)if(this.options.request){var h=O(r,s({authorize:!0},this.options),l);E(this.options,h,p)}else L(s({authorize:!0},this.options),r,l,p)}},{key:"write",value:function(e,t){var o=this;if(!u(this.queuedWrites,["locks",e,t])){var n=u(this.queuedWrites,[e,t]);c(this.queuedWrites,[e,t],[]);var i=1e3,r=n.filter((function(e){return e.callback})).map((function(e){return e.callback}));if(n.length){c(this.queuedWrites,["locks",e,t],!0);var s=function(){c(o.queuedWrites,["locks",e,t],!1),r.forEach((function(e){return e()})),o.options.onSaved&&o.options.onSaved(e,t),o.debouncedProcess(e,t)},a=n.length/i,l=0,f=n.splice(0,i);for(this.writePage(e,t,f,(function(){++l>=a&&s()}));f.length===i;)(f=n.splice(0,i)).length&&this.writePage(e,t,f,(function(){++l>=a&&s()}))}}}},{key:"process",value:function(){var e=this;Object.keys(this.queuedWrites).forEach((function(t){"locks"!==t&&Object.keys(e.queuedWrites[t]).forEach((function(o){e.queuedWrites[t][o].length&&e.write(t,o)}))}))}},{key:"queue",value:function(e,t,o,n,i,r){!function(e,t,o,n){var i=a(e,t,Object),r=i.obj,s=i.k;r[s]=r[s]||[],n&&(r[s]=r[s].concat(o)),n||r[s].push(o)}(this.queuedWrites,[e,t],{key:o,fallbackValue:n||"",callback:i,options:r}),this.debouncedProcess()}}],o&&j(t.prototype,o),n&&j(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function I(e,o){for(var n=0;n<o.length;n++){var i=o[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,t(i.key),i)}}P.type="backend";var T=[],N=T.forEach,q=T.slice;var z=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/,A=function(e,t,o,n){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{path:"/",sameSite:"strict"};o&&(i.expires=new Date,i.expires.setTime(i.expires.getTime()+60*o*1e3)),n&&(i.domain=n),document.cookie=function(e,t,o){var n=o||{};n.path=n.path||"/";var i=encodeURIComponent(t),r="".concat(e,"=").concat(i);if(n.maxAge>0){var s=n.maxAge-0;if(Number.isNaN(s))throw new Error("maxAge should be a Number");r+="; Max-Age=".concat(Math.floor(s))}if(n.domain){if(!z.test(n.domain))throw new TypeError("option domain is invalid");r+="; Domain=".concat(n.domain)}if(n.path){if(!z.test(n.path))throw new TypeError("option path is invalid");r+="; Path=".concat(n.path)}if(n.expires){if("function"!=typeof n.expires.toUTCString)throw new TypeError("option expires is invalid");r+="; Expires=".concat(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}(e,encodeURIComponent(t),i)},U=function(e){for(var t="".concat(e,"="),o=document.cookie.split(";"),n=0;n<o.length;n++){for(var i=o[n];" "===i.charAt(0);)i=i.substring(1,i.length);if(0===i.indexOf(t))return i.substring(t.length,i.length)}return null},C={name:"cookie",lookup:function(e){var t;if(e.lookupCookie&&"undefined"!=typeof document){var o=U(e.lookupCookie);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupCookie&&"undefined"!=typeof document&&A(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("&"),i=0;i<n.length;i++){var r=n[i].indexOf("=");if(r>0)n[i].substring(0,r)===e.lookupQuerystring&&(t=n[i].substring(r+1))}}return t}},R=null,X=function(){if(null!==R)return R;try{R="undefined"!==window&&null!==window.localStorage;var e="i18next.translate.boo";window.localStorage.setItem(e,"foo"),window.localStorage.removeItem(e)}catch(e){R=!1}return R},D={name:"localStorage",lookup:function(e){var t;if(e.lookupLocalStorage&&X()){var o=window.localStorage.getItem(e.lookupLocalStorage);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupLocalStorage&&X()&&window.localStorage.setItem(t.lookupLocalStorage,e)}},M=null,K=function(){if(null!==M)return M;try{M="undefined"!==window&&null!==window.sessionStorage;var e="i18next.translate.boo";window.sessionStorage.setItem(e,"foo"),window.sessionStorage.removeItem(e)}catch(e){M=!1}return M},F={name:"sessionStorage",lookup:function(e){var t;if(e.lookupSessionStorage&&K()){var o=window.sessionStorage.getItem(e.lookupSessionStorage);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupSessionStorage&&K()&&window.sessionStorage.setItem(t.lookupSessionStorage,e)}},J={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}},_={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}},W={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}},$={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 G=function(){function e(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.type="languageDetector",this.detectors={},this.init(t,o)}var t,o,n;return t=e,o=[{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=function(e){return N.call(q.call(arguments,1),(function(t){if(t)for(var o in t)void 0===e[o]&&(e[o]=t[o])})),e}(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(C),this.addDetector(H),this.addDetector(D),this.addDetector(F),this.addDetector(J),this.addDetector(_),this.addDetector(W),this.addDetector($)}},{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)})))}}],o&&I(t.prototype,o),n&&I(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();G.type="languageDetector";var V,B=[],Q=B.forEach,Y=B.slice;function Z(e){return Q.call(Y.call(arguments,1),(function(t){if(t)for(var o in t)void 0===e[o]&&(e[o]=t[o])})),e}if("function"==typeof fetch&&(V="undefined"!=typeof global&&global.fetch?global.fetch:"undefined"!=typeof window&&window.fetch?window.fetch:fetch),"undefined"!=typeof require&&("undefined"==typeof window||void 0===window.document)){var ee=V||require("cross-fetch");ee.default&&(ee=ee.default),exports.default=ee,module.exports=exports.default}var te,oe,ne,ie=Object.freeze({__proto__:null});function re(e){return re="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},re(e)}"function"==typeof fetch&&(te="undefined"!=typeof global&&global.fetch?global.fetch:"undefined"!=typeof window&&window.fetch?window.fetch:fetch),"function"!=typeof XMLHttpRequest&&"object"!==("undefined"==typeof XMLHttpRequest?"undefined":re(XMLHttpRequest))||("undefined"!=typeof global&&global.XMLHttpRequest?oe=global.XMLHttpRequest:"undefined"!=typeof window&&window.XMLHttpRequest&&(oe=window.XMLHttpRequest)),"function"==typeof ActiveXObject&&("undefined"!=typeof global&&global.ActiveXObject?ne=global.ActiveXObject:"undefined"!=typeof window&&window.ActiveXObject&&(ne=window.ActiveXObject)),te||!ie||oe||ne||(te=ie),"function"!=typeof te&&(te=void 0);var se=function(e,t,o,n){return"function"==typeof o&&(n=o,o=void 0),n=n||function(){},te?function(e,t,o,n){var i=function(e){var t=e.headers&&"Error from cloudfront"===e.headers.get("x-cache");if(!e.ok)return n(e.statusText||"Error",{status:e.status,resourceNotExisting:t});e.text().then((function(o){n(null,{status:e.status,data:o,resourceNotExisting:t})})).catch(n)},r={Authorization:e.authorize&&e.apiKey?e.apiKey:void 0,"Content-Type":"application/json"};"undefined"==typeof window&&"undefined"!=typeof global&&void 0!==global.process&&global.process.versions&&global.process.versions.node&&(r["User-Agent"]="locize-lastused (node/".concat(global.process.version,"; ").concat(global.process.platform," ").concat(global.process.arch,")")),"function"==typeof fetch?fetch(t,{method:o?"POST":"GET",body:o?JSON.stringify(o):void 0,headers:r}).then(i).catch(n):te(t,{method:o?"POST":"GET",body:o?JSON.stringify(o):void 0,headers:r}).then(i).catch(n)}(e,t,o,n):"function"==typeof XMLHttpRequest||"object"===("undefined"==typeof XMLHttpRequest?"undefined":re(XMLHttpRequest))||"function"==typeof ActiveXObject?function(e,t,o,n){try{var i;(i=oe?new oe:new ne("MSXML2.XMLHTTP.3.0")).open(o?"POST":"GET",t,1),e.crossDomain||i.setRequestHeader("X-Requested-With","XMLHttpRequest"),e.authorize&&e.apiKey&&i.setRequestHeader("Authorization",e.apiKey),(o||e.setContentTypeJSON)&&i.setRequestHeader("Content-Type","application/json"),i.onreadystatechange=function(){var e="Error from cloudfront"===i.getResponseHeader("x-cache");i.readyState>3&&n(i.status>=400?i.statusText:null,{status:i.status,data:i.responseText,resourceNotExisting:e})},i.send(JSON.stringify(o))}catch(e){console&&console.log(e)}}(e,t,o,n):void n(new Error("No fetch and no xhr implementation found!"))},ae={init:function(e){var t=e.t&&"function"==typeof e.t;t&&!e.options.locizeLastUsed.projectId&&e.options.backend.projectId&&(e.options.locizeLastUsed.projectId=e.options.backend.projectId),t&&!e.options.locizeLastUsed.version&&e.options.backend.version&&(e.options.locizeLastUsed.version=e.options.backend.version),t&&!e.options.locizeLastUsed.apiKey&&e.options.backend.apiKey&&(e.options.locizeLastUsed.apiKey=e.options.backend.apiKey),t&&!e.options.locizeLastUsed.referenceLng&&e.options.backend.referenceLng&&(e.options.locizeLastUsed.referenceLng=e.options.backend.referenceLng),t&&!e.options.locizeLastUsed.referenceLng&&e.options.fallbackLng&&Array.isArray(e.options.fallbackLng)&&"dev"!==e.options.fallbackLng[0]&&(e.options.locizeLastUsed.referenceLng=e.options.fallbackLng[0]),this.options=Z(t?e.options.locizeLastUsed:e,this.options||{},{lastUsedPath:"https://api.locize.app/used/{{projectId}}/{{version}}/{{lng}}/{{ns}}",referenceLng:"en",crossDomain:!0,setContentTypeJSON:!1,version:"latest",debounceSubmit:9e4,allowedHosts:["localhost"]});var o,n,i,r,s="undefined"!=typeof window&&window.location&&window.location.hostname;this.isAllowed=!s||this.options.allowedHosts.indexOf(s)>-1,this.submitting=null,this.pending={},this.done={},this.submit=(o=this.submit,n=this.options.debounceSubmit,function(){var e=this,t=arguments,s=i&&!r;clearTimeout(r),r=setTimeout((function(){r=null,i||o.apply(e,t)}),n),s&&o.apply(e,t)}),t&&this.interceptI18next(e)},interceptI18next:function(e){var t=this,o=e.services.resourceStore.getResource;e.services.resourceStore.getResource=function(n,i,r,s){return r&&t.used(i,r),o.call(e.services.resourceStore,n,i,r,s)}},used:function(e,t,o){var n=this;["pending","done"].forEach((function(o){n.done[e]&&n.done[e][t]||(n[o][e]||(n[o][e]={}),n[o][e][t]=!0)})),this.submit(o)},submit:function(e){var t=this;if(!this.isAllowed)return e&&e(new Error("not allowed"));if(this.submitting)return this.submit(e);var o,n=(o=this.options,["projectId","version","apiKey","referenceLng"].reduce((function(e,t){if(e)return e;if(!o||!o[t]||"string"!=typeof o[t]||!o[t].toLowerCase()===t.toLowerCase()){var n='i18next-lastused :: got "'.concat(o[t],'" in options for ').concat(t," which is invalid.");return console.warn(n),n}return!1}),!1));if(n)return e&&e(new Error(n));this.submitting=this.pending,this.pending={};var i=Object.keys(this.submitting),r=i.length,s=function(o){--r||(t.submitting=null,e&&e(o))};i.forEach((function(e){var o=Object.keys(t.submitting[e]),n=function(e,t,o){var n=e;return t.forEach((function(e){var t=new RegExp("{{".concat(e,"}}"),"g");n=n.replace(t,o[e])})),n}(t.options.lastUsedPath,["projectId","version","lng","ns"],Z({lng:t.options.referenceLng,ns:e},t.options));o.length?se(Z({authorize:!0},t.options),n,o,s):s()}))},type:"3rdParty"},ce=new RegExp("{{(.+?)}}","g");function ue(e){if(e.indexOf("-")<0)return e;var t=e.split("-");return["NB-NO","NN-NO","nb-NO","nn-NO","nb-no","nn-no"].indexOf(e)>-1?t[1].toLowerCase():t[0]}function le(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 fe(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?le(Object(n),!0).forEach((function(t){o(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):le(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var de={interpolator:{interpolate:function(e,t,o){for(var n,i,r;n=ce.exec(e);)"string"!=typeof(i=n[1].trim())&&(i=null==(r=i)?"":""+r),i||(i=""),i=i.replace(/\$/g,"$$$$"),e=e.replace(n[0],t[i]||i),ce.lastIndex=0;return e}},languageUtils:{formatLanguageCode:function(e){return e}}},pe={init:function(e){return this.options=e,this.backend=new P(de,e),this.detector=new G(de,e),this.lng=e.lng||this.detector.detect(),this.referenceLng=e.referenceLng,ae.init(e),this},isValid:function(e,t){return e[t]&&e[t].translated[this.options.version||"latest"]>=(this.options.loadIfTranslatedOver||1)},getLanguage:function(e,t){var o=this;return"function"==typeof e&&(t=e,e=this.lng),e||(e=this.lng),this.getLanguages((function(n,i){return n?t(n):o.isValid(i,e)?t(null,e):o.isValid(i,ue(e))?t(null,ue(e)):void t(null,o.options.fallbackLng||o.referenceLng||Object.keys(i)[0])})),this},getLanguages:function(e){var t=this;return this.publishedLngs?e(null,this.publishedLngs):this.backend.getLanguages((function(o,n){if(o)return e(o);o||(t.publishedLngs=n),t.referenceLng||Object.keys(n).forEach((function(e){n[e].isReferenceLanguage&&(t.referenceLng=e)})),e(null,n)})),this},load:function(e,t,o){var n=this;return"function"==typeof t&&(o=t,t=null),this.getLanguage(t,(function(t,i){if(t)return o(t);n.backend.read(i,e,(function(e,t){return o(e,t,i)}))})),this},loadAll:function(e,t){var n=this;return this.getLanguages((function(i,r){if(i)return t(i);!function(e,t,o){var n=[],i=e.length;e.forEach((function(e,r){t(e,(function(e,t){n[r]=t,e&&(o&&o(e),o=null),0==--i&&o&&o(null,n)}))}))}(Object.keys(r).filter((function(e){return n.isValid(r,e)})),(function(t,i){n.load(e,t,(function(e,n){if(e)return i(e);i(null,o({},t,n))}))}),(function(e,o){if(e)return t(e);var n=o.reduce((function(e,t){return fe(fe({},e),t)}),{});t(null,n)}))})),this},add:function(e,t,o,n,i){var r={};return"function"==typeof n?i=n:"string"==typeof n&&(r.tDescription=n),this.backend.create(this.referenceLng,e,t,o,i,r),this},update:function(e,t,o,n,i){var r={isUpdate:!0};return"function"==typeof n?i=n:"string"==typeof n&&(r.tDescription=n),this.backend.create(this.referenceLng,e,t,o,i,r),this},used:function(e,t){ae.used(e,t)}};return pe}));