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