forked from i18next/i18next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18next-1.3.3.min.js
2 lines (1 loc) · 7.08 KB
/
i18next-1.3.3.min.js
1
2
(function(){function f(e,u){typeof e=="function"&&(u=e,e={}),e=e||{},i.extend(r,e),typeof r.ns=="string"&&(r.ns={namespaces:[r.ns],defaultNs:r.ns}),r.lng?i.cookie.create("i18next",r.lng):r.lng=i.detectLanguage(),a=[];if(r.lng.indexOf("-")===2&&r.lng.length===5){var f=r.lng.split("-");r.lng=r.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase(),a.push(r.lng),a.push(r.lng.substr(0,2))}else a.push(r.lng);a.indexOf(r.fallbackLng)===-1&&a.push(r.fallbackLng),o=r.lng,i.log("currentLng set to: "+o),t&&r.setJqueryExt&&c();var l;return t&&t.Deferred&&(l=t.Deferred()),r.resStore?(s=r.resStore,u&&u(m),l&&l.resolve(),l):(n.sync.load(a,r,function(e,t){s=t,u&&u(m),l&&l.resolve()}),l)}function l(e,t){f({lng:e},t)}function c(){function e(e,n,r){if(n.length===0)return;var i="text";if(n.indexOf("[")===0){var s=n.split("]");n=s[1],i=s[0].substr(1,s[0].length-1)}n.indexOf(";")===n.length-1&&(n=n.substr(0,n.length-2));var o;i==="text"?(o=t.extend({defaultValue:e.text()},r),e.text(t.t(n,o))):(o=t.extend({defaultValue:e.attr(i)},r),e.attr(i,t.t(n,o)))}function n(n,r){var i=n.attr("data-i18n");if(!i)return;if(i.indexOf(";")<=i.length-1){var s=i.split(";");t.each(s,function(t,i){e(n,i,r)})}else e(n,i,r)}t.t=t.t||m,t.fn.i18n=function(e){return this.each(function(){n(t(this),e);var r=t(this).find("[data-i18n]");r.each(function(){n(t(this),e)})})}}function h(e,t,n){return i.each(t,function(t,i){typeof i=="object"?e=h(e,i,t):e=e.replace(new RegExp([r.interpolationPrefix,n?n+"."+t:t,r.interpolationSuffix].join(""),"g"),i)}),e}function p(e,t){while(e.indexOf(r.reusePrefix)!=-1){u++;if(u>r.maxRecursion)break;var n=e.indexOf(r.reusePrefix),i=e.indexOf(r.reuseSuffix,n)+r.reuseSuffix.length,s=e.substring(n,i),o=s.replace(r.reusePrefix,"").replace(r.reuseSuffix,""),a=g(o,t);e=e.replace(s,a)}return e}function d(e){return e.context&&typeof e.context=="string"}function v(e){return e.count!==undefined&&typeof e.count!="string"&&e.count!==1}function m(e,t){return u=0,g(e,t)}function g(e,t){t=t||{};var n,u,f=t.defaultValue||e;if(!s)return f;var l=r.ns.defaultNs;if(e.indexOf(r.nsseparator)>-1){var c=e.split(r.nsseparator);l=c[0],e=c[1]}if(d(t)){n=i.extend({},t),delete n.context,n.defaultValue=r.contextNotFound;var y=e+"_"+t.context;u=m(y,n);if(u!=r.contextNotFound)return h(u,{context:t.context})}if(v(t)){n=i.extend({},t),delete n.count,n.defaultValue=r.pluralNotFound;var b=e+r.pluralSuffix,S=E.get(o,t.count);S!=="other"&&(b=b+"_"+S),u=m(b,n);if(u!=r.pluralNotFound)return h(u,{count:t.count})}var x,T=e.split(r.keyseparator);for(var N=0,C=a.length;N<C;N++){if(x)break;var k=a[N],L=0,A=s[k][l];while(T[L])A=A&&A[T[L]],L++;if(A){if(typeof A!="string")if(!r.returnObjectTrees&&!t.returnObjectTrees)A="key '"+l+":"+e+" ("+k+")' "+"returned a object instead of string.",i.log(A);else for(var O in A)A[O]=g(e+"."+O,t);else A=h(A,t),A=p(A,t);x=A}}return!x&&r.sendMissing&&w.postMissing(l,e,f),x?x:f}function y(){var e,t=[];(function(){var e=window.location.search.substring(1),n=e.split("&");for(var r=0;r<n.length;r++){var i=n[r].indexOf("=");if(i>0){var s=n[r].substring(0,i),o=n[r].substring(i+1);t[s]=o}}})(),t.setLng&&(e=t.setLng,i.cookie.create("i18next",e));if(!e){var n=i.cookie.read("i18next");n&&(e=n)}return!e&&navigator&&(e=navigator.language?navigator.language:navigator.userLanguage),e||(e=r.fallbackLng),e}function b(){return o}Array.prototype.indexOf||(Array.prototype.indexOf=function(e){"use strict";if(this==null)throw new TypeError;var t=Object(this),n=t.length>>>0;if(n===0)return-1;var r=0;arguments.length>0&&(r=Number(arguments[1]),r!=r?r=0:r!=0&&r!=Infinity&&r!=-Infinity&&(r=(r>0||-1)*Math.floor(Math.abs(r))));if(r>=n)return-1;var i=r>=0?r:Math.max(n-Math.abs(r),0);for(;i<n;i++)if(i in t&&t[i]===e)return i;return-1});var e=this,t=e.jQuery,n={};typeof module!="undefined"&&module.exports?module.exports=n:t?t.i18n=t.i18n||n:e.i18n=e.i18n||n;var r={lng:undefined,lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",ns:"translation",nsseparator:":",keyseparator:".",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:undefined,useLocalStorage:!0,dynamicLoad:!1,sendMissing:!1,interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),setJqueryExt:!0},i={extend:t?t.extend:undefined,each:t?t.each:undefined,ajax:t?t.ajax:undefined,detectLanguage:y,log:function(e){r.debug&&console.log(e)},cookie:{create:function(e,t,n){var r;if(n){var i=new Date;i.setTime(i.getTime()+n*60*1e3),r="; expires="+i.toGMTString()}else r="";document.cookie=e+"="+t+r+"; path=/"},read:function(e){var t=e+"=",n=document.cookie.split(";");for(var r=0;r<n.length;r++){var i=n[r];while(i.charAt(0)==" ")i=i.substring(1,i.length);if(i.indexOf(t)===0)return i.substring(t.length,i.length)}return null},remove:function(e){this.create(e,"",-1)}}},s,o,u=0,a=[],w={load:function(e,t,n){t.useLocalStorage?w._loadLocal(e,function(r,s){var o=[];for(var u=0,a=e.length;u<a;u++)s[e[u]]||o.push(e[u]);o.length>0?w._fetch(o,t,function(e,t){i.extend(s,t),w._storeLocal(t),n(null,s)}):n(null,s)}):w._fetch(e,t,function(e,t){n(null,t)})},_loadLocal:function(e,t){var n={};if(window.localStorage){var r=e.length;i.each(e,function(e,i){var s=window.localStorage.getItem("res_"+i);s&&(n[i]=JSON.parse(s)),r--,r===0&&t(null,n)})}},_storeLocal:function(e){if(window.localStorage)for(var t in e)window.localStorage.setItem("res_"+t,JSON.stringify(e[t]));return},_fetch:function(e,t,n){var s=t.ns,o={};if(!t.dynamicLoad){var u=s.namespaces.length*e.length,a;i.each(s.namespaces,function(t,r){i.each(e,function(e,t){w._fetchOne(t,r,function(e,i){e&&(a=a||[],a.push(e)),o[t]=o[t]||{},o[t][r]=i,u--,u===0&&n(a,o)})})})}else{var f=h(r.resGetPath,{lng:e.join("+"),ns:s.namespaces.join("+")});i.ajax({url:f,success:function(e,t,r){i.log("loaded: "+f),n(null,e)},error:function(e,t,r){i.log("failed loading: "+f),n("failed loading resource.json error: "+r)},dataType:"json",async:r.getAsync})}},_fetchOne:function(e,t,n){var s=h(r.resGetPath,{lng:e,ns:t});i.ajax({url:s,success:function(e,t,r){i.log("loaded: "+s),n(null,e)},error:function(e,t,r){i.log("failed loading: "+s),n(r,{})},dataType:"json",async:r.getAsync})},postMissing:function(e,t,n){var o={};o[t]=n;var u=h(r.resPostPath,{lng:r.fallbackLng,ns:e});i.ajax({url:u,type:"POST",data:o,success:function(o,a,f){i.log("posted missing key '"+t+"' to: "+u),s[r.fallbackLng][e][t]=n},error:function(e,n,r){i.log("failed posting missing key '"+t+"' to: "+u)},dataType:"json",async:r.postAsync})}},E={rules:{sl:function(e){return e%100===1?"one":e%100===2?"two":e%100===3||e%100===4?"few":"other"},ar:function(e){return e===0?"zero":e===1?"one":e===2?"two":e%100>=3&&e%100<=10?"few":e%100>=11&&e%100<=99?"many":"other"}},addRule:function(e,t){E.rules[e]=t},get:function(e,t){function r(e,t){return E.rules[e]?E.rules[e](t):t===1?"one":"other"}var n=e.split("-");return n.length===2?r(n[0],t):r(e,t)}};n.init=f,n.setLng=l,n.t=m,n.translate=m,n.detectLanguage=i.detectLanguage,n.pluralExtensions=E,n.sync=w,n.functions=i,n.lng=b,n.options=r})()