Greasy Fork is available in English.

i18next-localstorage-backend.js

A i18next module

Detta skript bör inte installeras direkt. Det är ett bibliotek för andra skript att inkludera med meta-direktivet // @require https://update.greasyfork.org/scripts/484743/1311041/i18next-localstorage-backendjs.js

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).i18nextLocalStorageBackend=e()}(this,(function(){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}function e(e){var n=function(e,n){if("object"!==t(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,n||"default");if("object"!==t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"===t(n)?n:String(n)}function n(t,n,r){return(n=e(n))in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,n){for(var r=0;r<n.length;r++){var o=n[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,e(o.key),o)}}function i(t,e,n){return e&&o(t.prototype,e),n&&o(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function a(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?s(Object(r),!0).forEach((function(e){n(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var c=function(){function t(e){r(this,t),this.store=e.store}return i(t,[{key:"setItem",value:function(t,e){if(this.store)try{this.store.setItem(t,e)}catch(t){}}},{key:"getItem",value:function(t,e){if(this.store)try{return this.store.getItem(t,e)}catch(t){}}}]),t}();function u(){var t=null;try{t=window.localStorage}catch(t){"undefined"!=typeof window&&console.log("Failed to load local storage.",t)}return{prefix:"i18next_res_",expirationTime:6048e5,defaultVersion:void 0,versions:{},store:t}}var f=function(){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r(this,t),this.init(e,n),this.type="backend"}return i(t,[{key:"init",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.services=t,this.options=a(a(a({},u()),this.options),e),this.storage=new c(this.options)}},{key:"read",value:function(t,e,n){var r=Date.now();if(!this.storage.store)return n(null,null);var o=this.storage.getItem("".concat(this.options.prefix).concat(t,"-").concat(e));if(o){o=JSON.parse(o);var i=this.getVersion(t);if(o.i18nStamp&&o.i18nStamp+this.options.expirationTime>r&&i===o.i18nVersion){var s=o.i18nStamp;return delete o.i18nVersion,delete o.i18nStamp,n(null,o,s)}}return n(null,null)}},{key:"save",value:function(t,e,n){if(this.storage.store){n.i18nStamp=Date.now();var r=this.getVersion(t);r&&(n.i18nVersion=r),this.storage.setItem("".concat(this.options.prefix).concat(t,"-").concat(e),JSON.stringify(n))}}},{key:"getVersion",value:function(t){return this.options.versions[t]||this.options.defaultVersion}}]),t}();return f.type="backend",f}));