-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathriot-i18n.min.js
1 lines (1 loc) · 1.77 KB
/
riot-i18n.min.js
1
!function(i,t){"function"==typeof define&&define.amd?define(["exports","riot"],function(n,e){t(i.i18n=n,e)}):"object"==typeof exports?t(exports,require("riot")):t(i.i18n={},i.riot)}(this,function(i,t){function n(){this._entities={},this._default=e,this._language=this._default;var i=t.observable();this.on=i.on,this.off=i.off,this.trigger=i.trigger,this.on("lang",this.setLanguage)}var e="en";n.prototype.dictionary=function(i){this._entities=i},n.prototype.defaultLanguage=function(i){this._default=i},n.prototype.localise=function(i,t){function n(i,t,e,s){s=s||"",t=t||{},e=e||0;var a=i&&!i.length,o=a?Object.keys(i).length:0;if(a&&o>0){var r;for(r in i)s.split(".").length>e&&(s=s.split(".").splice(0,e).join(".")),s=0==e?r:s+"."+r,t=n(i[r],t,e+1,s)}else t[s]=i;return t}var e,s;if(this._entities[this._language]||(e=i),e||(s=n(this._entities[this._language]),e=s[i]?s[i]:i),t){var a,o=n(t);for(a in o)e=e.replace(new RegExp("{"+a+"}","g"),o[a])}return e},n.prototype.setLanguage=function(i){this._language=i||this._default,this.trigger("update")},n.prototype.getLanguage=function(){return this._language};var s,a=new n;for(s in a)i[s]=a[s];t.mixin("i18n",{i18n:i}),t.tag2("i1-8n",'<span ref="localised" name="localised"></span> <span ref="original" name="original" class="original"><yield></yield></span>','i1-8n,[riot-tag="i1-8n"],[data-is="i1-8n"]{ display: inline-block; } i1-8n .original,[riot-tag="i1-8n"] .original,[data-is="i1-8n"] .original{ display: none; }',"",function(){this.mixin("i18n"),this.i18n.on("update",function(){this.update()}.bind(this)),this.on("mount",function(){this.hasRefs=void 0!=this.refs,this.localise()}),this.on("update",function(){this.localise()}),this.localise=function(){var i=this.hasRefs?this.refs:this;i.localised.innerHTML=this.i18n.localise(i.original.innerHTML)}})});