!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define("i18nextBrowserLanguageDetector",o):e.i18nextBrowserLanguageDetector=o()}(this,function(){"use strict";function e(e){return a.call(i.call(arguments,1),function(o){if(o)for(var t in o)void 0===e[t]&&(e[t]=o[t])}),e}function o(){return{order:["querystring","cookie","localStorage","navigator"],lookupQuerystring:"lng",lookupCookie:"i18next",lookupLocalStorage:"i18nextLng",caches:["localStorage"]}}var t={};t.classCallCheck=function(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")},t.createClass=function(){function e(e,o){for(var t=0;t<o.length;t++){var n=o[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(o,t,n){return t&&e(o.prototype,t),n&&e(o,n),o}}();var n=[],a=n.forEach,i=n.slice,r={create:function(e,o,t,n){var a=void 0;if(t){var i=new Date;i.setTime(i.getTime()+60*t*1e3),a="; expires="+i.toGMTString()}else a="";n=n?"domain="+n+";":"",document.cookie=e+"="+o+a+";"+n+"path=/"},read:function(e){for(var o=e+"=",t=document.cookie.split(";"),n=0;n<t.length;n++){for(var a=t[n];" "===a.charAt(0);)a=a.substring(1,a.length);if(0===a.indexOf(o))return a.substring(o.length,a.length)}return null},remove:function(e){this.create(e,"",-1)}},c={name:"cookie",lookup:function(e){var o=void 0;if(e.lookupCookie&&"undefined"!=typeof document){var t=r.read(e.lookupCookie);t&&(o=t)}return o},cacheUserLanguage:function(e,o){o.lookupCookie&&"undefined"!=typeof document&&r.create(o.lookupCookie,e,o.cookieMinutes,o.cookieDomain)}},u={name:"querystring",lookup:function(e){var o=void 0;if("undefined"!=typeof window)for(var t=window.location.search.substring(1),n=t.split("&"),a=0;a<n.length;a++){var i=n[a].indexOf("=");if(i>0){var r=n[a].substring(0,i);r===e.lookupQuerystring&&(o=n[a].substring(i+1))}}return o}},s={setItem:function(e,o){if(window.localStorage)try{window.localStorage.setItem(e,o)}catch(t){}},getItem:function(e,o){if(window.localStorage)try{return window.localStorage.getItem(e,o)}catch(t){return}}},l={name:"localStorage",lookup:function(e){var o=void 0;if(e.lookupLocalStorage&&"undefined"!=typeof window&&window.localStorage){var t=s.getItem(e.lookupLocalStorage);t&&(o=t)}return o},cacheUserLanguage:function(e,o){o.lookupLocalStorage&&"undefined"!=typeof window&&window.localStorage&&s.setItem(o.lookupLocalStorage,e)}},g={name:"navigator",lookup:function(e){var o=[];if("undefined"!=typeof navigator){if(navigator.languages)for(var t=0;t<navigator.languages.length;t++)o.push(navigator.languages[t]);navigator.userLanguage&&o.push(navigator.userLanguage),navigator.language&&o.push(navigator.language)}return o.length>0?o:void 0}},f=function(){function n(e){var o=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];t.classCallCheck(this,n),this.type="languageDetector",this.detectors={},this.init(e,o)}return t.createClass(n,[{key:"init",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],a=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];this.services=t,this.options=e(n,this.options||{},o()),this.i18nOptions=a,this.addDetector(c),this.addDetector(u),this.addDetector(l),this.addDetector(g)}},{key:"addDetector",value:function(e){this.detectors[e.name]=e}},{key:"detect",value:function(e){var o=this;e||(e=this.options.order);var t=[];e.forEach(function(e){if(o.detectors[e]){var n=o.detectors[e].lookup(o.options);n&&"string"==typeof n&&(n=[n]),n&&(t=t.concat(n))}});var n=void 0;return t.forEach(function(e){if(!n){var t=o.services.languageUtils.formatLanguageCode(e);o.services.languageUtils.isWhitelisted(t)&&(n=t)}}),n||this.i18nOptions.fallbackLng[0]}},{key:"cacheUserLanguage",value:function(e,o){var t=this;o||(o=this.options.caches),o&&o.forEach(function(o){t.detectors[o]&&t.detectors[o].cacheUserLanguage(e,t.options)})}}]),n}();return f.type="languageDetector",f});