UNPKG

vue-inter

Version:

Simple i18n for Vue.js

3 lines (2 loc) 2.17 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueInter=t()}(this,function(){"use strict";var e=function(e,t){if(!t)return e;return e.replace(/{(.*?)}/g,function(e,n){for(var r=t,a=0,o=n.split(".");a<o.length;a+=1){var i=o[a];r=r?r[i]:""}return r||""})};var t,n=function(e){for(var t=arguments,n=1;n<arguments.length;n++)for(var r in arguments[n])e[r]=t[n][r];return e},r={name:"FormatMessage",functional:!0,props:{path:{type:String,required:!0},data:{type:Object},defaultMessage:{type:String},tag:{type:[String,Object],default:"span"}},render:function(e,t){var r=t.props,a=t.data,o=t.listeners,i=t.parent.$inter.formatMessage({path:r.path,defaultMessage:r.defaultMessage},r.data);return e(r.tag,n({},a,{on:o}),[i])}},a=function(n){var r=n.locale,a=n.messages;void 0===a&&(a={});var o=n.template;void 0===o&&(o=e),this.template=o,this.messages=a,t.util.defineReactive(this,"__locale",r)},o={currentLocale:{configurable:!0},availableLocales:{configurable:!0}};return a.install=function(e){(t=e).mixin({beforeCreate:function(){this.$inter=this.$options.inter||this.$parent&&this.$parent.$inter}}),t.component(r.name,r)},a.prototype.formatMessage=function(e){for(var t=[],n=arguments.length-1;n-- >0;)t[n]=arguments[n+1];if("object"!=typeof e)throw new TypeError("messageDescriptor in .formatMessage must be an object.");var r,a,o=e.path,i=e.defaultMessage,s=this.messages[this.currentLocale],u=o&&(r=s,function(e){for(var t=e.split("."),n=[],r=0;r<t.length;r++){for(var a=t[r];"\\"===a[a.length-1]&&void 0!==t[r+1];)a=a.slice(0,-1)+".",a+=t[++r];n.push(a)}return n}(o).reduce(function(e,t){return e&&e[t]},r));return"function"==typeof u?u.apply(void 0,t):(void 0===u&&(u=void 0===i?o:i),(a=this).template.apply(a,[u].concat(t)))},o.currentLocale.get=function(){return this.__locale},a.prototype.setCurrentLocale=function(e){return this.__locale=e,this},a.prototype.setLocaleData=function(e,t){return this.messages[e]=t,this},o.availableLocales.get=function(){return Object.keys(this.messages)},Object.defineProperties(a.prototype,o),a}); //# sourceMappingURL=vue-inter.min.js.map