diff --git a/dist/vue-i18n.common.js b/dist/vue-i18n.common.js index ac1357c4b..d08d09fc5 100644 --- a/dist/vue-i18n.common.js +++ b/dist/vue-i18n.common.js @@ -22,7 +22,8 @@ var numberFormatKeys = [ 'minimumSignificantDigits', 'maximumSignificantDigits', 'localeMatcher', - 'formatMatcher' + 'formatMatcher', + 'unit' ]; /** diff --git a/dist/vue-i18n.esm.browser.js b/dist/vue-i18n.esm.browser.js index 852336a36..d223463aa 100644 --- a/dist/vue-i18n.esm.browser.js +++ b/dist/vue-i18n.esm.browser.js @@ -15,7 +15,8 @@ const numberFormatKeys = [ 'minimumSignificantDigits', 'maximumSignificantDigits', 'localeMatcher', - 'formatMatcher' + 'formatMatcher', + 'unit' ]; /** diff --git a/dist/vue-i18n.esm.browser.min.js b/dist/vue-i18n.esm.browser.min.js index 2086d44e8..f54c6d7e0 100644 --- a/dist/vue-i18n.esm.browser.min.js +++ b/dist/vue-i18n.esm.browser.min.js @@ -1 +1 @@ -const t=["style","currency","currencyDisplay","useGrouping","minimumIntegerDigits","minimumFractionDigits","maximumFractionDigits","minimumSignificantDigits","maximumSignificantDigits","localeMatcher","formatMatcher"];function e(t,e){"undefined"!=typeof console&&(console.warn("[vue-i18n] "+t),e&&console.warn(e.stack))}function n(t){return null!==t&&"object"==typeof t}const s=Object.prototype.toString,r="[object Object]";function i(t){return s.call(t)===r}function a(t){return null==t}function o(...t){let e=null,s=null;return 1===t.length?n(t[0])||Array.isArray(t[0])?s=t[0]:"string"==typeof t[0]&&(e=t[0]):2===t.length&&("string"==typeof t[0]&&(e=t[0]),(n(t[1])||Array.isArray(t[1]))&&(s=t[1])),{locale:e,params:s}}function l(t){return JSON.parse(JSON.stringify(t))}const c=Object.prototype.hasOwnProperty;function u(t,e){return c.call(t,e)}function h(t){const e=Object(t);for(let t=1;tf(t,e[n]));if(n||s)return!1;{const n=Object.keys(t),s=Object.keys(e);return n.length===s.length&&n.every(n=>f(t[n],e[n]))}}catch(t){return!1}}var m={beforeCreate(){const t=this.$options;if(t.i18n=t.i18n||(t.__i18n?{}:null),t.i18n){if(t.i18n instanceof Z){if(t.__i18n)try{let e={};t.__i18n.forEach(t=>{e=h(e,JSON.parse(t))}),Object.keys(e).forEach(n=>{t.i18n.mergeLocaleMessage(n,e[n])})}catch(t){}this._i18n=t.i18n,this._i18nWatcher=this._i18n.watchI18nData()}else if(i(t.i18n)){if(this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof Z&&(t.i18n.root=this.$root,t.i18n.formatter=this.$root.$i18n.formatter,t.i18n.fallbackLocale=this.$root.$i18n.fallbackLocale,t.i18n.formatFallbackMessages=this.$root.$i18n.formatFallbackMessages,t.i18n.silentTranslationWarn=this.$root.$i18n.silentTranslationWarn,t.i18n.silentFallbackWarn=this.$root.$i18n.silentFallbackWarn,t.i18n.pluralizationRules=this.$root.$i18n.pluralizationRules,t.i18n.preserveDirectiveContent=this.$root.$i18n.preserveDirectiveContent),t.__i18n)try{let e={};t.__i18n.forEach(t=>{e=h(e,JSON.parse(t))}),t.i18n.messages=e}catch(t){}const{sharedMessages:e}=t.i18n;e&&i(e)&&(t.i18n.messages=h(t.i18n.messages,e)),this._i18n=new Z(t.i18n),this._i18nWatcher=this._i18n.watchI18nData(),(void 0===t.i18n.sync||t.i18n.sync)&&(this._localeWatcher=this.$i18n.watchLocale())}}else this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof Z?this._i18n=this.$root.$i18n:t.parent&&t.parent.$i18n&&t.parent.$i18n instanceof Z&&(this._i18n=t.parent.$i18n)},beforeMount(){const t=this.$options;t.i18n=t.i18n||(t.__i18n?{}:null),t.i18n?t.i18n instanceof Z?(this._i18n.subscribeDataChanging(this),this._subscribing=!0):i(t.i18n)&&(this._i18n.subscribeDataChanging(this),this._subscribing=!0):this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof Z?(this._i18n.subscribeDataChanging(this),this._subscribing=!0):t.parent&&t.parent.$i18n&&t.parent.$i18n instanceof Z&&(this._i18n.subscribeDataChanging(this),this._subscribing=!0)},beforeDestroy(){if(!this._i18n)return;const t=this;this.$nextTick(()=>{t._subscribing&&(t._i18n.unsubscribeDataChanging(t),delete t._subscribing),t._i18nWatcher&&(t._i18nWatcher(),t._i18n.destroyVM(),delete t._i18nWatcher),t._localeWatcher&&(t._localeWatcher(),delete t._localeWatcher),t._i18n=null})}},_={name:"i18n",functional:!0,props:{tag:{type:String},path:{type:String,required:!0},locale:{type:String},places:{type:[Array,Object]}},render(t,{data:e,parent:n,props:s,slots:r}){const{$i18n:i}=n;if(!i)return;const{path:a,locale:o,places:l}=s,c=r(),u=i.i(a,o,function(t){let e;for(e in t)if("default"!==e)return!1;return Boolean(e)}(c)||l?function(t,e){const n=e?function(t){return Array.isArray(t)?t.reduce(p,{}):Object.assign({},t)}(e):{};if(!t)return n;const s=(t=t.filter(t=>t.tag||""!==t.text.trim())).every(d);return t.reduce(s?g:p,n)}(c.default,l):c),h=s.tag||"span";return h?t(h,e,u):u}};function g(t,e){return e.data&&e.data.attrs&&e.data.attrs.place&&(t[e.data.attrs.place]=e),t}function p(t,e,n){return t[n]=e,t}function d(t){return Boolean(t.data&&t.data.attrs&&t.data.attrs.place)}var b={name:"i18n-n",functional:!0,props:{tag:{type:String,default:"span"},value:{type:Number,required:!0},format:{type:[String,Object]},locale:{type:String}},render(e,{props:s,parent:r,data:i}){const a=r.$i18n;if(!a)return null;let o=null,l=null;"string"==typeof s.format?o=s.format:n(s.format)&&(s.format.key&&(o=s.format.key),l=Object.keys(s.format).reduce((e,n)=>t.includes(n)?Object.assign({},e,{[n]:s.format[n]}):e,null));const c=s.locale||a.locale,u=a._ntp(s.value,c,o,l),h=u.map((t,e)=>{const n=i.scopedSlots&&i.scopedSlots[t.type];return n?n({[t.type]:t.value,index:e,parts:u}):t.value});return e(s.tag,{attrs:i.attrs,class:i.class,staticClass:i.staticClass},h)}};function v(t,e,n){w(t,n)&&F(t,e,n)}function y(t,e,n,s){if(!w(t,n))return;const r=n.context.$i18n;(function(t,e){const n=e.context;return t._locale===n.$i18n.locale})(t,n)&&f(e.value,e.oldValue)&&f(t._localeMessage,r.getLocaleMessage(r.locale))||F(t,e,n)}function $(t,n,s,r){if(!s.context)return void e("Vue instance does not exists in VNode context");const i=s.context.$i18n||{};n.modifiers.preserve||i.preserveDirectiveContent||(t.textContent=""),t._vt=void 0,delete t._vt,t._locale=void 0,delete t._locale,t._localeMessage=void 0,delete t._localeMessage}function w(t,n){const s=n.context;return s?!!s.$i18n||(e("VueI18n instance does not exists in Vue instance"),!1):(e("Vue instance does not exists in VNode context"),!1)}function F(t,n,s){const r=n.value,{path:a,locale:o,args:l,choice:c}=function(t){let e,n,s,r;"string"==typeof t?e=t:i(t)&&(e=t.path,n=t.locale,s=t.args,r=t.choice);return{path:e,locale:n,args:s,choice:r}}(r);if(!a&&!o&&!l)return void e("value type not supported");if(!a)return void e("`path` is required in v-t directive");const u=s.context;t._vt=t.textContent=c?u.$i18n.tc(a,c,...k(o,l)):u.$i18n.t(a,...k(o,l)),t._locale=u.$i18n.locale,t._localeMessage=u.$i18n.getLocaleMessage(u.$i18n.locale)}function k(t,e){const n=[];return t&&n.push(t),e&&(Array.isArray(e)||i(e))&&n.push(e),n}let M;function D(t){D.installed=!0;(M=t).version&&Number(M.version.split(".")[0]);!function(t){t.prototype.hasOwnProperty("$i18n")||Object.defineProperty(t.prototype,"$i18n",{get(){return this._i18n}}),t.prototype.$t=function(t,...e){const n=this.$i18n;return n._t(t,n.locale,n._getMessages(),this,...e)},t.prototype.$tc=function(t,e,...n){const s=this.$i18n;return s._tc(t,s.locale,s._getMessages(),this,e,...n)},t.prototype.$te=function(t,e){const n=this.$i18n;return n._te(t,n.locale,n._getMessages(),e)},t.prototype.$d=function(t,...e){return this.$i18n.d(t,...e)},t.prototype.$n=function(t,...e){return this.$i18n.n(t,...e)}}(M),M.mixin(m),M.directive("t",{bind:v,update:y,unbind:$}),M.component(_.name,_),M.component(b.name,b),M.config.optionMergeStrategies.i18n=function(t,e){return void 0===e?t:e}}const T=/^(?:\d)+/,x=/^(?:\w)+/;const L=0,I=1,O=2,W=3,C=0,j=4,N=5,S=6,A=7,H=8,R=[];R[C]={ws:[C],ident:[3,L],"[":[j],eof:[A]},R[1]={ws:[1],".":[2],"[":[j],eof:[A]},R[2]={ws:[2],ident:[3,L],0:[3,L],number:[3,L]},R[3]={ident:[3,L],0:[3,L],number:[3,L],ws:[1,I],".":[2,I],"[":[j,I],eof:[A,I]},R[j]={"'":[N,L],'"':[S,L],"[":[j,O],"]":[1,W],eof:H,else:[j,L]},R[N]={"'":[j,L],eof:H,else:[N,L]},R[S]={'"':[j,L],eof:H,else:[S,L]};const V=/^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;function E(t){if(null==t)return"eof";switch(t.charCodeAt(0)){case 91:case 93:case 46:case 34:case 39:return t;case 95:case 36:case 45:return"ident";case 9:case 10:case 13:case 160:case 65279:case 8232:case 8233:return"ws"}return"ident"}function P(t){const e=t.trim();return("0"!==t.charAt(0)||!isNaN(t))&&(n=e,V.test(n)?function(t){const e=t.charCodeAt(0);return e!==t.charCodeAt(t.length-1)||34!==e&&39!==e?t:t.slice(1,-1)}(e):"*"+e);var n}class z{constructor(){this._cache=Object.create(null)}parsePath(t){let e=this._cache[t];return e||(e=function(t){const e=[];let n,s,r,i,a,o,l,c=-1,u=C,h=0;const f=[];function m(){const e=t[c+1];if(u===N&&"'"===e||u===S&&'"'===e)return c++,r="\\"+e,f[L](),!0}for(f[I]=function(){void 0!==s&&(e.push(s),s=void 0)},f[L]=function(){void 0===s?s=r:s+=r},f[O]=function(){f[L](),h++},f[W]=function(){if(h>0)h--,u=j,f[L]();else{if(h=0,void 0===s)return!1;if(!1===(s=P(s)))return!1;f[I]()}};null!==u;)if("\\"!==(n=t[++c])||!m()){if(i=E(n),(a=(l=R[u])[i]||l.else||H)===H)return;if(u=a[0],(o=f[a[1]])&&(r=void 0===(r=a[2])?n:r,!1===o()))return;if(u===A)return e}}(t))&&(this._cache[t]=e),e||[]}getPathValue(t,e){if(!n(t))return null;const s=this.parsePath(e);if(0===s.length)return null;{const e=s.length;let n=t,r=0;for(;r/,U=/(?:@(?:\.[a-z]+)?:(?:[\w\-_|.]+|\([\w\-_|.]+\)))/g,q=/^@(?:\.([a-z]+))?:/,B=/[()]/g,G={upper:t=>t.toLocaleUpperCase(),lower:t=>t.toLocaleLowerCase()},X=new class{constructor(){this._caches=Object.create(null)}interpolate(t,e){if(!e)return[t];let s=this._caches[t];return s||(s=function(t){const e=[];let n=0,s="";for(;n!(!t||!e)&&(!a(this._path.getPathValue(t,e))||!!t[e])),"warn"!==this._warnHtmlInMessage&&"error"!==this._warnHtmlInMessage||Object.keys(s).forEach(t=>{this._checkLocaleMessage(t,this._warnHtmlInMessage,s[t])}),this._initVM({locale:e,fallbackLocale:n,messages:s,dateTimeFormats:r,numberFormats:i})}_checkLocaleMessage(t,n,s){const r=(t,n,s,a)=>{if(i(s))Object.keys(s).forEach(e=>{const o=s[e];i(o)?(a.push(e),a.push("."),r(t,n,o,a),a.pop(),a.pop()):(a.push(e),r(t,n,o,a),a.pop())});else if(Array.isArray(s))s.forEach((e,s)=>{i(e)?(a.push(`[${s}]`),a.push("."),r(t,n,e,a),a.pop(),a.pop()):(a.push(`[${s}]`),r(t,n,e,a),a.pop())});else if("string"==typeof s){if(J.test(s)){const r=`Detected HTML in message '${s}' of keypath '${a.join("")}' at '${n}'. Consider component interpolation with '' to avoid XSS. See https://bit.ly/2ZqJzkp`;"warn"===t?e(r):"error"===t&&function(t,e){"undefined"!=typeof console&&(console.error("[vue-i18n] "+t),e&&console.error(e.stack))}(r)}}};r(n,t,s,[])}_initVM(t){const e=M.config.silent;M.config.silent=!0,this._vm=new M({data:t}),M.config.silent=e}destroyVM(){this._vm.$destroy()}subscribeDataChanging(t){this._dataListeners.push(t)}unsubscribeDataChanging(t){!function(t,e){if(t.length){const n=t.indexOf(e);if(n>-1)t.splice(n,1)}}(this._dataListeners,t)}watchI18nData(){const t=this;return this._vm.$watch("$data",()=>{let e=t._dataListeners.length;for(;e--;)M.nextTick(()=>{t._dataListeners[e]&&t._dataListeners[e].$forceUpdate()})},{deep:!0})}watchLocale(){if(!this._sync||!this._root)return null;const t=this._vm;return this._root.$i18n.vm.$watch("locale",e=>{t.$set(t,"locale",e),t.$forceUpdate()},{immediate:!0})}get vm(){return this._vm}get messages(){return l(this._getMessages())}get dateTimeFormats(){return l(this._getDateTimeFormats())}get numberFormats(){return l(this._getNumberFormats())}get availableLocales(){return Object.keys(this.messages).sort()}get locale(){return this._vm.locale}set locale(t){this._vm.$set(this._vm,"locale",t)}get fallbackLocale(){return this._vm.fallbackLocale}set fallbackLocale(t){this._vm.$set(this._vm,"fallbackLocale",t)}get formatFallbackMessages(){return this._formatFallbackMessages}set formatFallbackMessages(t){this._formatFallbackMessages=t}get missing(){return this._missing}set missing(t){this._missing=t}get formatter(){return this._formatter}set formatter(t){this._formatter=t}get silentTranslationWarn(){return this._silentTranslationWarn}set silentTranslationWarn(t){this._silentTranslationWarn=t}get silentFallbackWarn(){return this._silentFallbackWarn}set silentFallbackWarn(t){this._silentFallbackWarn=t}get preserveDirectiveContent(){return this._preserveDirectiveContent}set preserveDirectiveContent(t){this._preserveDirectiveContent=t}get warnHtmlInMessage(){return this._warnHtmlInMessage}set warnHtmlInMessage(t){const e=this._warnHtmlInMessage;if(this._warnHtmlInMessage=t,e!==t&&("warn"===t||"error"===t)){const t=this._getMessages();Object.keys(t).forEach(e=>{this._checkLocaleMessage(e,this._warnHtmlInMessage,t[e])})}}_getMessages(){return this._vm.messages}_getDateTimeFormats(){return this._vm.dateTimeFormats}_getNumberFormats(){return this._vm.numberFormats}_warnDefault(t,e,n,s,r){if(!a(n))return n;if(this._missing){const n=this._missing.apply(null,[t,e,s,r]);if("string"==typeof n)return n}if(this._formatFallbackMessages){const t=o(...r);return this._render(e,"string",t.params,e)}return e}_isFallbackRoot(t){return!t&&!a(this._root)&&this._fallbackRoot}_isSilentFallbackWarn(t){return this._silentFallbackWarn instanceof RegExp?this._silentFallbackWarn.test(t):this._silentFallbackWarn}_isSilentFallback(t,e){return this._isSilentFallbackWarn(e)&&(this._isFallbackRoot()||t!==this.fallbackLocale)}_isSilentTranslationWarn(t){return this._silentTranslationWarn instanceof RegExp?this._silentTranslationWarn.test(t):this._silentTranslationWarn}_interpolate(t,e,n,s,r,o,l){if(!e)return null;const c=this._path.getPathValue(e,n);if(Array.isArray(c)||i(c))return c;let u;if(a(c)){if(!i(e))return null;if("string"!=typeof(u=e[n]))return null}else{if("string"!=typeof c)return null;u=c}return(u.indexOf("@:")>=0||u.indexOf("@.")>=0)&&(u=this._link(t,e,u,s,"raw",o,l)),this._render(u,r,o,n)}_link(t,e,n,s,r,i,a){let o=n;const l=o.match(U);for(const n in l){if(!l.hasOwnProperty(n))continue;const c=l[n],u=c.match(q),[h,f]=u,m=c.replace(h,"").replace(B,"");if(a.includes(m))return o;a.push(m);let _=this._interpolate(t,e,m,s,"raw"===r?"string":r,"raw"===r?void 0:i,a);if(this._isFallbackRoot(_)){if(!this._root)throw Error("unexpected error");const t=this._root.$i18n;_=t._translate(t._getMessages(),t.locale,t.fallbackLocale,m,s,r,i)}_=this._warnDefault(t,m,_,s,Array.isArray(i)?i:[i]),this._modifiers.hasOwnProperty(f)?_=this._modifiers[f](_):G.hasOwnProperty(f)&&(_=G[f](_)),a.pop(),o=_?o.replace(c,_):o}return o}_render(t,e,n,s){let r=this._formatter.interpolate(t,n,s);return r||(r=X.interpolate(t,n,s)),"string"===e?r.join(""):r}_translate(t,e,n,s,r,i,o){let l=this._interpolate(e,t[e],s,r,i,o,[s]);return a(l)&&a(l=this._interpolate(n,t[n],s,r,i,o,[s]))?null:l}_t(t,e,n,s,...r){if(!t)return"";const i=o(...r),a=i.locale||e,l=this._translate(n,a,this.fallbackLocale,t,s,"string",i.params);if(this._isFallbackRoot(l)){if(!this._root)throw Error("unexpected error");return this._root.$t(t,...r)}return this._warnDefault(a,t,l,s,r)}t(t,...e){return this._t(t,this.locale,this._getMessages(),null,...e)}_i(t,e,n,s,r){const i=this._translate(n,e,this.fallbackLocale,t,s,"raw",r);if(this._isFallbackRoot(i)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.i(t,e,r)}return this._warnDefault(e,t,i,s,[r])}i(t,e,n){return t?("string"!=typeof e&&(e=this.locale),this._i(t,e,this._getMessages(),null,n)):""}_tc(t,e,n,s,r,...i){if(!t)return"";void 0===r&&(r=1);const a={count:r,n:r},l=o(...i);return l.params=Object.assign(a,l.params),i=null===l.locale?[l.params]:[l.locale,l.params],this.fetchChoice(this._t(t,e,n,s,...i),r)}fetchChoice(t,e){if(!t&&"string"!=typeof t)return null;const n=t.split("|");return n[e=this.getChoiceIndex(e,n.length)]?n[e].trim():t}getChoiceIndex(t,e){return this.locale in this.pluralizationRules?this.pluralizationRules[this.locale].apply(this,[t,e]):((t,e)=>(t=Math.abs(t),2===e?t?t>1?1:0:1:t?Math.min(t,2):0))(t,e)}tc(t,e,...n){return this._tc(t,this.locale,this._getMessages(),null,e,...n)}_te(t,e,n,...s){const r=o(...s).locale||e;return this._exist(n[r],t)}te(t,e){return this._te(t,this.locale,this._getMessages(),e)}getLocaleMessage(t){return l(this._vm.messages[t]||{})}setLocaleMessage(t,e){("warn"!==this._warnHtmlInMessage&&"error"!==this._warnHtmlInMessage||(this._checkLocaleMessage(t,this._warnHtmlInMessage,e),"error"!==this._warnHtmlInMessage))&&this._vm.$set(this._vm.messages,t,e)}mergeLocaleMessage(t,e){("warn"!==this._warnHtmlInMessage&&"error"!==this._warnHtmlInMessage||(this._checkLocaleMessage(t,this._warnHtmlInMessage,e),"error"!==this._warnHtmlInMessage))&&this._vm.$set(this._vm.messages,t,h(this._vm.messages[t]||{},e))}getDateTimeFormat(t){return l(this._vm.dateTimeFormats[t]||{})}setDateTimeFormat(t,e){this._vm.$set(this._vm.dateTimeFormats,t,e)}mergeDateTimeFormat(t,e){this._vm.$set(this._vm.dateTimeFormats,t,h(this._vm.dateTimeFormats[t]||{},e))}_localizeDateTime(t,e,n,s,r){let i=e,o=s[i];if((a(o)||a(o[r]))&&(o=s[i=n]),a(o)||a(o[r]))return null;{const e=o[r],n=`${i}__${r}`;let s=this._dateTimeFormatters[n];return s||(s=this._dateTimeFormatters[n]=new Intl.DateTimeFormat(i,e)),s.format(t)}}_d(t,e,n){if(!n)return new Intl.DateTimeFormat(e).format(t);const s=this._localizeDateTime(t,e,this.fallbackLocale,this._getDateTimeFormats(),n);if(this._isFallbackRoot(s)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.d(t,n,e)}return s||""}d(t,...e){let s=this.locale,r=null;return 1===e.length?"string"==typeof e[0]?r=e[0]:n(e[0])&&(e[0].locale&&(s=e[0].locale),e[0].key&&(r=e[0].key)):2===e.length&&("string"==typeof e[0]&&(r=e[0]),"string"==typeof e[1]&&(s=e[1])),this._d(t,s,r)}getNumberFormat(t){return l(this._vm.numberFormats[t]||{})}setNumberFormat(t,e){this._vm.$set(this._vm.numberFormats,t,e)}mergeNumberFormat(t,e){this._vm.$set(this._vm.numberFormats,t,h(this._vm.numberFormats[t]||{},e))}_getNumberFormatter(t,e,n,s,r,i){let o=e,l=s[o];if((a(l)||a(l[r]))&&(l=s[o=n]),a(l)||a(l[r]))return null;{const t=l[r];let e;if(i)e=new Intl.NumberFormat(o,Object.assign({},t,i));else{const n=`${o}__${r}`;(e=this._numberFormatters[n])||(e=this._numberFormatters[n]=new Intl.NumberFormat(o,t))}return e}}_n(t,e,n,s){if(!Z.availabilities.numberFormat)return"";if(!n){return(s?new Intl.NumberFormat(e,s):new Intl.NumberFormat(e)).format(t)}const r=this._getNumberFormatter(t,e,this.fallbackLocale,this._getNumberFormats(),n,s),i=r&&r.format(t);if(this._isFallbackRoot(i)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.n(t,Object.assign({},{key:n,locale:e},s))}return i||""}n(e,...s){let r=this.locale,i=null,a=null;return 1===s.length?"string"==typeof s[0]?i=s[0]:n(s[0])&&(s[0].locale&&(r=s[0].locale),s[0].key&&(i=s[0].key),a=Object.keys(s[0]).reduce((e,n)=>t.includes(n)?Object.assign({},e,{[n]:s[0][n]}):e,null)):2===s.length&&("string"==typeof s[0]&&(i=s[0]),"string"==typeof s[1]&&(r=s[1])),this._n(e,r,i,a)}_ntp(t,e,n,s){if(!Z.availabilities.numberFormat)return[];if(!n){return(s?new Intl.NumberFormat(e,s):new Intl.NumberFormat(e)).formatToParts(t)}const r=this._getNumberFormatter(t,e,this.fallbackLocale,this._getNumberFormats(),n,s),i=r&&r.formatToParts(t);if(this._isFallbackRoot(i)){if(!this._root)throw Error("unexpected error");return this._root.$i18n._ntp(t,e,n,s)}return i||[]}}let K;Object.defineProperty(Z,"availabilities",{get(){if(!K){const t="undefined"!=typeof Intl;K={dateTimeFormat:t&&void 0!==Intl.DateTimeFormat,numberFormat:t&&void 0!==Intl.NumberFormat}}return K}}),Z.install=D,Z.version="8.15.1";export default Z; \ No newline at end of file +const t=["style","currency","currencyDisplay","useGrouping","minimumIntegerDigits","minimumFractionDigits","maximumFractionDigits","minimumSignificantDigits","maximumSignificantDigits","localeMatcher","formatMatcher","unit"];function e(t,e){"undefined"!=typeof console&&(console.warn("[vue-i18n] "+t),e&&console.warn(e.stack))}function n(t){return null!==t&&"object"==typeof t}const s=Object.prototype.toString,r="[object Object]";function i(t){return s.call(t)===r}function a(t){return null==t}function o(...t){let e=null,s=null;return 1===t.length?n(t[0])||Array.isArray(t[0])?s=t[0]:"string"==typeof t[0]&&(e=t[0]):2===t.length&&("string"==typeof t[0]&&(e=t[0]),(n(t[1])||Array.isArray(t[1]))&&(s=t[1])),{locale:e,params:s}}function l(t){return JSON.parse(JSON.stringify(t))}const c=Object.prototype.hasOwnProperty;function u(t,e){return c.call(t,e)}function h(t){const e=Object(t);for(let t=1;tf(t,e[n]));if(n||s)return!1;{const n=Object.keys(t),s=Object.keys(e);return n.length===s.length&&n.every(n=>f(t[n],e[n]))}}catch(t){return!1}}var m={beforeCreate(){const t=this.$options;if(t.i18n=t.i18n||(t.__i18n?{}:null),t.i18n){if(t.i18n instanceof Z){if(t.__i18n)try{let e={};t.__i18n.forEach(t=>{e=h(e,JSON.parse(t))}),Object.keys(e).forEach(n=>{t.i18n.mergeLocaleMessage(n,e[n])})}catch(t){}this._i18n=t.i18n,this._i18nWatcher=this._i18n.watchI18nData()}else if(i(t.i18n)){if(this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof Z&&(t.i18n.root=this.$root,t.i18n.formatter=this.$root.$i18n.formatter,t.i18n.fallbackLocale=this.$root.$i18n.fallbackLocale,t.i18n.formatFallbackMessages=this.$root.$i18n.formatFallbackMessages,t.i18n.silentTranslationWarn=this.$root.$i18n.silentTranslationWarn,t.i18n.silentFallbackWarn=this.$root.$i18n.silentFallbackWarn,t.i18n.pluralizationRules=this.$root.$i18n.pluralizationRules,t.i18n.preserveDirectiveContent=this.$root.$i18n.preserveDirectiveContent),t.__i18n)try{let e={};t.__i18n.forEach(t=>{e=h(e,JSON.parse(t))}),t.i18n.messages=e}catch(t){}const{sharedMessages:e}=t.i18n;e&&i(e)&&(t.i18n.messages=h(t.i18n.messages,e)),this._i18n=new Z(t.i18n),this._i18nWatcher=this._i18n.watchI18nData(),(void 0===t.i18n.sync||t.i18n.sync)&&(this._localeWatcher=this.$i18n.watchLocale())}}else this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof Z?this._i18n=this.$root.$i18n:t.parent&&t.parent.$i18n&&t.parent.$i18n instanceof Z&&(this._i18n=t.parent.$i18n)},beforeMount(){const t=this.$options;t.i18n=t.i18n||(t.__i18n?{}:null),t.i18n?t.i18n instanceof Z?(this._i18n.subscribeDataChanging(this),this._subscribing=!0):i(t.i18n)&&(this._i18n.subscribeDataChanging(this),this._subscribing=!0):this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof Z?(this._i18n.subscribeDataChanging(this),this._subscribing=!0):t.parent&&t.parent.$i18n&&t.parent.$i18n instanceof Z&&(this._i18n.subscribeDataChanging(this),this._subscribing=!0)},beforeDestroy(){if(!this._i18n)return;const t=this;this.$nextTick(()=>{t._subscribing&&(t._i18n.unsubscribeDataChanging(t),delete t._subscribing),t._i18nWatcher&&(t._i18nWatcher(),t._i18n.destroyVM(),delete t._i18nWatcher),t._localeWatcher&&(t._localeWatcher(),delete t._localeWatcher),t._i18n=null})}},_={name:"i18n",functional:!0,props:{tag:{type:String},path:{type:String,required:!0},locale:{type:String},places:{type:[Array,Object]}},render(t,{data:e,parent:n,props:s,slots:r}){const{$i18n:i}=n;if(!i)return;const{path:a,locale:o,places:l}=s,c=r(),u=i.i(a,o,function(t){let e;for(e in t)if("default"!==e)return!1;return Boolean(e)}(c)||l?function(t,e){const n=e?function(t){return Array.isArray(t)?t.reduce(p,{}):Object.assign({},t)}(e):{};if(!t)return n;const s=(t=t.filter(t=>t.tag||""!==t.text.trim())).every(d);return t.reduce(s?g:p,n)}(c.default,l):c),h=s.tag||"span";return h?t(h,e,u):u}};function g(t,e){return e.data&&e.data.attrs&&e.data.attrs.place&&(t[e.data.attrs.place]=e),t}function p(t,e,n){return t[n]=e,t}function d(t){return Boolean(t.data&&t.data.attrs&&t.data.attrs.place)}var b={name:"i18n-n",functional:!0,props:{tag:{type:String,default:"span"},value:{type:Number,required:!0},format:{type:[String,Object]},locale:{type:String}},render(e,{props:s,parent:r,data:i}){const a=r.$i18n;if(!a)return null;let o=null,l=null;"string"==typeof s.format?o=s.format:n(s.format)&&(s.format.key&&(o=s.format.key),l=Object.keys(s.format).reduce((e,n)=>t.includes(n)?Object.assign({},e,{[n]:s.format[n]}):e,null));const c=s.locale||a.locale,u=a._ntp(s.value,c,o,l),h=u.map((t,e)=>{const n=i.scopedSlots&&i.scopedSlots[t.type];return n?n({[t.type]:t.value,index:e,parts:u}):t.value});return e(s.tag,{attrs:i.attrs,class:i.class,staticClass:i.staticClass},h)}};function v(t,e,n){w(t,n)&&F(t,e,n)}function y(t,e,n,s){if(!w(t,n))return;const r=n.context.$i18n;(function(t,e){const n=e.context;return t._locale===n.$i18n.locale})(t,n)&&f(e.value,e.oldValue)&&f(t._localeMessage,r.getLocaleMessage(r.locale))||F(t,e,n)}function $(t,n,s,r){if(!s.context)return void e("Vue instance does not exists in VNode context");const i=s.context.$i18n||{};n.modifiers.preserve||i.preserveDirectiveContent||(t.textContent=""),t._vt=void 0,delete t._vt,t._locale=void 0,delete t._locale,t._localeMessage=void 0,delete t._localeMessage}function w(t,n){const s=n.context;return s?!!s.$i18n||(e("VueI18n instance does not exists in Vue instance"),!1):(e("Vue instance does not exists in VNode context"),!1)}function F(t,n,s){const r=n.value,{path:a,locale:o,args:l,choice:c}=function(t){let e,n,s,r;"string"==typeof t?e=t:i(t)&&(e=t.path,n=t.locale,s=t.args,r=t.choice);return{path:e,locale:n,args:s,choice:r}}(r);if(!a&&!o&&!l)return void e("value type not supported");if(!a)return void e("`path` is required in v-t directive");const u=s.context;t._vt=t.textContent=c?u.$i18n.tc(a,c,...k(o,l)):u.$i18n.t(a,...k(o,l)),t._locale=u.$i18n.locale,t._localeMessage=u.$i18n.getLocaleMessage(u.$i18n.locale)}function k(t,e){const n=[];return t&&n.push(t),e&&(Array.isArray(e)||i(e))&&n.push(e),n}let M;function D(t){D.installed=!0;(M=t).version&&Number(M.version.split(".")[0]);!function(t){t.prototype.hasOwnProperty("$i18n")||Object.defineProperty(t.prototype,"$i18n",{get(){return this._i18n}}),t.prototype.$t=function(t,...e){const n=this.$i18n;return n._t(t,n.locale,n._getMessages(),this,...e)},t.prototype.$tc=function(t,e,...n){const s=this.$i18n;return s._tc(t,s.locale,s._getMessages(),this,e,...n)},t.prototype.$te=function(t,e){const n=this.$i18n;return n._te(t,n.locale,n._getMessages(),e)},t.prototype.$d=function(t,...e){return this.$i18n.d(t,...e)},t.prototype.$n=function(t,...e){return this.$i18n.n(t,...e)}}(M),M.mixin(m),M.directive("t",{bind:v,update:y,unbind:$}),M.component(_.name,_),M.component(b.name,b),M.config.optionMergeStrategies.i18n=function(t,e){return void 0===e?t:e}}const T=/^(?:\d)+/,x=/^(?:\w)+/;const L=0,I=1,O=2,W=3,C=0,j=4,N=5,S=6,A=7,H=8,R=[];R[C]={ws:[C],ident:[3,L],"[":[j],eof:[A]},R[1]={ws:[1],".":[2],"[":[j],eof:[A]},R[2]={ws:[2],ident:[3,L],0:[3,L],number:[3,L]},R[3]={ident:[3,L],0:[3,L],number:[3,L],ws:[1,I],".":[2,I],"[":[j,I],eof:[A,I]},R[j]={"'":[N,L],'"':[S,L],"[":[j,O],"]":[1,W],eof:H,else:[j,L]},R[N]={"'":[j,L],eof:H,else:[N,L]},R[S]={'"':[j,L],eof:H,else:[S,L]};const V=/^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;function E(t){if(null==t)return"eof";switch(t.charCodeAt(0)){case 91:case 93:case 46:case 34:case 39:return t;case 95:case 36:case 45:return"ident";case 9:case 10:case 13:case 160:case 65279:case 8232:case 8233:return"ws"}return"ident"}function P(t){const e=t.trim();return("0"!==t.charAt(0)||!isNaN(t))&&(n=e,V.test(n)?function(t){const e=t.charCodeAt(0);return e!==t.charCodeAt(t.length-1)||34!==e&&39!==e?t:t.slice(1,-1)}(e):"*"+e);var n}class z{constructor(){this._cache=Object.create(null)}parsePath(t){let e=this._cache[t];return e||(e=function(t){const e=[];let n,s,r,i,a,o,l,c=-1,u=C,h=0;const f=[];function m(){const e=t[c+1];if(u===N&&"'"===e||u===S&&'"'===e)return c++,r="\\"+e,f[L](),!0}for(f[I]=function(){void 0!==s&&(e.push(s),s=void 0)},f[L]=function(){void 0===s?s=r:s+=r},f[O]=function(){f[L](),h++},f[W]=function(){if(h>0)h--,u=j,f[L]();else{if(h=0,void 0===s)return!1;if(!1===(s=P(s)))return!1;f[I]()}};null!==u;)if("\\"!==(n=t[++c])||!m()){if(i=E(n),(a=(l=R[u])[i]||l.else||H)===H)return;if(u=a[0],(o=f[a[1]])&&(r=void 0===(r=a[2])?n:r,!1===o()))return;if(u===A)return e}}(t))&&(this._cache[t]=e),e||[]}getPathValue(t,e){if(!n(t))return null;const s=this.parsePath(e);if(0===s.length)return null;{const e=s.length;let n=t,r=0;for(;r/,U=/(?:@(?:\.[a-z]+)?:(?:[\w\-_|.]+|\([\w\-_|.]+\)))/g,q=/^@(?:\.([a-z]+))?:/,B=/[()]/g,G={upper:t=>t.toLocaleUpperCase(),lower:t=>t.toLocaleLowerCase()},X=new class{constructor(){this._caches=Object.create(null)}interpolate(t,e){if(!e)return[t];let s=this._caches[t];return s||(s=function(t){const e=[];let n=0,s="";for(;n!(!t||!e)&&(!a(this._path.getPathValue(t,e))||!!t[e])),"warn"!==this._warnHtmlInMessage&&"error"!==this._warnHtmlInMessage||Object.keys(s).forEach(t=>{this._checkLocaleMessage(t,this._warnHtmlInMessage,s[t])}),this._initVM({locale:e,fallbackLocale:n,messages:s,dateTimeFormats:r,numberFormats:i})}_checkLocaleMessage(t,n,s){const r=(t,n,s,a)=>{if(i(s))Object.keys(s).forEach(e=>{const o=s[e];i(o)?(a.push(e),a.push("."),r(t,n,o,a),a.pop(),a.pop()):(a.push(e),r(t,n,o,a),a.pop())});else if(Array.isArray(s))s.forEach((e,s)=>{i(e)?(a.push(`[${s}]`),a.push("."),r(t,n,e,a),a.pop(),a.pop()):(a.push(`[${s}]`),r(t,n,e,a),a.pop())});else if("string"==typeof s){if(J.test(s)){const r=`Detected HTML in message '${s}' of keypath '${a.join("")}' at '${n}'. Consider component interpolation with '' to avoid XSS. See https://bit.ly/2ZqJzkp`;"warn"===t?e(r):"error"===t&&function(t,e){"undefined"!=typeof console&&(console.error("[vue-i18n] "+t),e&&console.error(e.stack))}(r)}}};r(n,t,s,[])}_initVM(t){const e=M.config.silent;M.config.silent=!0,this._vm=new M({data:t}),M.config.silent=e}destroyVM(){this._vm.$destroy()}subscribeDataChanging(t){this._dataListeners.push(t)}unsubscribeDataChanging(t){!function(t,e){if(t.length){const n=t.indexOf(e);if(n>-1)t.splice(n,1)}}(this._dataListeners,t)}watchI18nData(){const t=this;return this._vm.$watch("$data",()=>{let e=t._dataListeners.length;for(;e--;)M.nextTick(()=>{t._dataListeners[e]&&t._dataListeners[e].$forceUpdate()})},{deep:!0})}watchLocale(){if(!this._sync||!this._root)return null;const t=this._vm;return this._root.$i18n.vm.$watch("locale",e=>{t.$set(t,"locale",e),t.$forceUpdate()},{immediate:!0})}get vm(){return this._vm}get messages(){return l(this._getMessages())}get dateTimeFormats(){return l(this._getDateTimeFormats())}get numberFormats(){return l(this._getNumberFormats())}get availableLocales(){return Object.keys(this.messages).sort()}get locale(){return this._vm.locale}set locale(t){this._vm.$set(this._vm,"locale",t)}get fallbackLocale(){return this._vm.fallbackLocale}set fallbackLocale(t){this._vm.$set(this._vm,"fallbackLocale",t)}get formatFallbackMessages(){return this._formatFallbackMessages}set formatFallbackMessages(t){this._formatFallbackMessages=t}get missing(){return this._missing}set missing(t){this._missing=t}get formatter(){return this._formatter}set formatter(t){this._formatter=t}get silentTranslationWarn(){return this._silentTranslationWarn}set silentTranslationWarn(t){this._silentTranslationWarn=t}get silentFallbackWarn(){return this._silentFallbackWarn}set silentFallbackWarn(t){this._silentFallbackWarn=t}get preserveDirectiveContent(){return this._preserveDirectiveContent}set preserveDirectiveContent(t){this._preserveDirectiveContent=t}get warnHtmlInMessage(){return this._warnHtmlInMessage}set warnHtmlInMessage(t){const e=this._warnHtmlInMessage;if(this._warnHtmlInMessage=t,e!==t&&("warn"===t||"error"===t)){const t=this._getMessages();Object.keys(t).forEach(e=>{this._checkLocaleMessage(e,this._warnHtmlInMessage,t[e])})}}_getMessages(){return this._vm.messages}_getDateTimeFormats(){return this._vm.dateTimeFormats}_getNumberFormats(){return this._vm.numberFormats}_warnDefault(t,e,n,s,r){if(!a(n))return n;if(this._missing){const n=this._missing.apply(null,[t,e,s,r]);if("string"==typeof n)return n}if(this._formatFallbackMessages){const t=o(...r);return this._render(e,"string",t.params,e)}return e}_isFallbackRoot(t){return!t&&!a(this._root)&&this._fallbackRoot}_isSilentFallbackWarn(t){return this._silentFallbackWarn instanceof RegExp?this._silentFallbackWarn.test(t):this._silentFallbackWarn}_isSilentFallback(t,e){return this._isSilentFallbackWarn(e)&&(this._isFallbackRoot()||t!==this.fallbackLocale)}_isSilentTranslationWarn(t){return this._silentTranslationWarn instanceof RegExp?this._silentTranslationWarn.test(t):this._silentTranslationWarn}_interpolate(t,e,n,s,r,o,l){if(!e)return null;const c=this._path.getPathValue(e,n);if(Array.isArray(c)||i(c))return c;let u;if(a(c)){if(!i(e))return null;if("string"!=typeof(u=e[n]))return null}else{if("string"!=typeof c)return null;u=c}return(u.indexOf("@:")>=0||u.indexOf("@.")>=0)&&(u=this._link(t,e,u,s,"raw",o,l)),this._render(u,r,o,n)}_link(t,e,n,s,r,i,a){let o=n;const l=o.match(U);for(const n in l){if(!l.hasOwnProperty(n))continue;const c=l[n],u=c.match(q),[h,f]=u,m=c.replace(h,"").replace(B,"");if(a.includes(m))return o;a.push(m);let _=this._interpolate(t,e,m,s,"raw"===r?"string":r,"raw"===r?void 0:i,a);if(this._isFallbackRoot(_)){if(!this._root)throw Error("unexpected error");const t=this._root.$i18n;_=t._translate(t._getMessages(),t.locale,t.fallbackLocale,m,s,r,i)}_=this._warnDefault(t,m,_,s,Array.isArray(i)?i:[i]),this._modifiers.hasOwnProperty(f)?_=this._modifiers[f](_):G.hasOwnProperty(f)&&(_=G[f](_)),a.pop(),o=_?o.replace(c,_):o}return o}_render(t,e,n,s){let r=this._formatter.interpolate(t,n,s);return r||(r=X.interpolate(t,n,s)),"string"===e?r.join(""):r}_translate(t,e,n,s,r,i,o){let l=this._interpolate(e,t[e],s,r,i,o,[s]);return a(l)&&a(l=this._interpolate(n,t[n],s,r,i,o,[s]))?null:l}_t(t,e,n,s,...r){if(!t)return"";const i=o(...r),a=i.locale||e,l=this._translate(n,a,this.fallbackLocale,t,s,"string",i.params);if(this._isFallbackRoot(l)){if(!this._root)throw Error("unexpected error");return this._root.$t(t,...r)}return this._warnDefault(a,t,l,s,r)}t(t,...e){return this._t(t,this.locale,this._getMessages(),null,...e)}_i(t,e,n,s,r){const i=this._translate(n,e,this.fallbackLocale,t,s,"raw",r);if(this._isFallbackRoot(i)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.i(t,e,r)}return this._warnDefault(e,t,i,s,[r])}i(t,e,n){return t?("string"!=typeof e&&(e=this.locale),this._i(t,e,this._getMessages(),null,n)):""}_tc(t,e,n,s,r,...i){if(!t)return"";void 0===r&&(r=1);const a={count:r,n:r},l=o(...i);return l.params=Object.assign(a,l.params),i=null===l.locale?[l.params]:[l.locale,l.params],this.fetchChoice(this._t(t,e,n,s,...i),r)}fetchChoice(t,e){if(!t&&"string"!=typeof t)return null;const n=t.split("|");return n[e=this.getChoiceIndex(e,n.length)]?n[e].trim():t}getChoiceIndex(t,e){return this.locale in this.pluralizationRules?this.pluralizationRules[this.locale].apply(this,[t,e]):((t,e)=>(t=Math.abs(t),2===e?t?t>1?1:0:1:t?Math.min(t,2):0))(t,e)}tc(t,e,...n){return this._tc(t,this.locale,this._getMessages(),null,e,...n)}_te(t,e,n,...s){const r=o(...s).locale||e;return this._exist(n[r],t)}te(t,e){return this._te(t,this.locale,this._getMessages(),e)}getLocaleMessage(t){return l(this._vm.messages[t]||{})}setLocaleMessage(t,e){("warn"!==this._warnHtmlInMessage&&"error"!==this._warnHtmlInMessage||(this._checkLocaleMessage(t,this._warnHtmlInMessage,e),"error"!==this._warnHtmlInMessage))&&this._vm.$set(this._vm.messages,t,e)}mergeLocaleMessage(t,e){("warn"!==this._warnHtmlInMessage&&"error"!==this._warnHtmlInMessage||(this._checkLocaleMessage(t,this._warnHtmlInMessage,e),"error"!==this._warnHtmlInMessage))&&this._vm.$set(this._vm.messages,t,h(this._vm.messages[t]||{},e))}getDateTimeFormat(t){return l(this._vm.dateTimeFormats[t]||{})}setDateTimeFormat(t,e){this._vm.$set(this._vm.dateTimeFormats,t,e)}mergeDateTimeFormat(t,e){this._vm.$set(this._vm.dateTimeFormats,t,h(this._vm.dateTimeFormats[t]||{},e))}_localizeDateTime(t,e,n,s,r){let i=e,o=s[i];if((a(o)||a(o[r]))&&(o=s[i=n]),a(o)||a(o[r]))return null;{const e=o[r],n=`${i}__${r}`;let s=this._dateTimeFormatters[n];return s||(s=this._dateTimeFormatters[n]=new Intl.DateTimeFormat(i,e)),s.format(t)}}_d(t,e,n){if(!n)return new Intl.DateTimeFormat(e).format(t);const s=this._localizeDateTime(t,e,this.fallbackLocale,this._getDateTimeFormats(),n);if(this._isFallbackRoot(s)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.d(t,n,e)}return s||""}d(t,...e){let s=this.locale,r=null;return 1===e.length?"string"==typeof e[0]?r=e[0]:n(e[0])&&(e[0].locale&&(s=e[0].locale),e[0].key&&(r=e[0].key)):2===e.length&&("string"==typeof e[0]&&(r=e[0]),"string"==typeof e[1]&&(s=e[1])),this._d(t,s,r)}getNumberFormat(t){return l(this._vm.numberFormats[t]||{})}setNumberFormat(t,e){this._vm.$set(this._vm.numberFormats,t,e)}mergeNumberFormat(t,e){this._vm.$set(this._vm.numberFormats,t,h(this._vm.numberFormats[t]||{},e))}_getNumberFormatter(t,e,n,s,r,i){let o=e,l=s[o];if((a(l)||a(l[r]))&&(l=s[o=n]),a(l)||a(l[r]))return null;{const t=l[r];let e;if(i)e=new Intl.NumberFormat(o,Object.assign({},t,i));else{const n=`${o}__${r}`;(e=this._numberFormatters[n])||(e=this._numberFormatters[n]=new Intl.NumberFormat(o,t))}return e}}_n(t,e,n,s){if(!Z.availabilities.numberFormat)return"";if(!n){return(s?new Intl.NumberFormat(e,s):new Intl.NumberFormat(e)).format(t)}const r=this._getNumberFormatter(t,e,this.fallbackLocale,this._getNumberFormats(),n,s),i=r&&r.format(t);if(this._isFallbackRoot(i)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.n(t,Object.assign({},{key:n,locale:e},s))}return i||""}n(e,...s){let r=this.locale,i=null,a=null;return 1===s.length?"string"==typeof s[0]?i=s[0]:n(s[0])&&(s[0].locale&&(r=s[0].locale),s[0].key&&(i=s[0].key),a=Object.keys(s[0]).reduce((e,n)=>t.includes(n)?Object.assign({},e,{[n]:s[0][n]}):e,null)):2===s.length&&("string"==typeof s[0]&&(i=s[0]),"string"==typeof s[1]&&(r=s[1])),this._n(e,r,i,a)}_ntp(t,e,n,s){if(!Z.availabilities.numberFormat)return[];if(!n){return(s?new Intl.NumberFormat(e,s):new Intl.NumberFormat(e)).formatToParts(t)}const r=this._getNumberFormatter(t,e,this.fallbackLocale,this._getNumberFormats(),n,s),i=r&&r.formatToParts(t);if(this._isFallbackRoot(i)){if(!this._root)throw Error("unexpected error");return this._root.$i18n._ntp(t,e,n,s)}return i||[]}}let K;Object.defineProperty(Z,"availabilities",{get(){if(!K){const t="undefined"!=typeof Intl;K={dateTimeFormat:t&&void 0!==Intl.DateTimeFormat,numberFormat:t&&void 0!==Intl.NumberFormat}}return K}}),Z.install=D,Z.version="8.15.1";export default Z; \ No newline at end of file diff --git a/dist/vue-i18n.esm.js b/dist/vue-i18n.esm.js index 12351aaea..19a12ff6c 100644 --- a/dist/vue-i18n.esm.js +++ b/dist/vue-i18n.esm.js @@ -20,7 +20,8 @@ var numberFormatKeys = [ 'minimumSignificantDigits', 'maximumSignificantDigits', 'localeMatcher', - 'formatMatcher' + 'formatMatcher', + 'unit' ]; /** diff --git a/dist/vue-i18n.js b/dist/vue-i18n.js index 9465df63e..323b4e02d 100644 --- a/dist/vue-i18n.js +++ b/dist/vue-i18n.js @@ -26,7 +26,8 @@ 'minimumSignificantDigits', 'maximumSignificantDigits', 'localeMatcher', - 'formatMatcher' + 'formatMatcher', + 'unit' ]; /** diff --git a/dist/vue-i18n.min.js b/dist/vue-i18n.min.js index f0bce2c60..478f4ccae 100644 --- a/dist/vue-i18n.min.js +++ b/dist/vue-i18n.min.js @@ -3,4 +3,4 @@ * (c) 2019 kazuya kawaguchi * Released under the MIT License. */ -var t,e;t=this,e=function(){"use strict";var t=["style","currency","currencyDisplay","useGrouping","minimumIntegerDigits","minimumFractionDigits","maximumFractionDigits","minimumSignificantDigits","maximumSignificantDigits","localeMatcher","formatMatcher"];function e(t,e){"undefined"!=typeof console&&(console.warn("[vue-i18n] "+t),e&&console.warn(e.stack))}function n(t){return null!==t&&"object"==typeof t}var r=Object.prototype.toString,i="[object Object]";function a(t){return r.call(t)===i}function s(t){return null==t}function o(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];var r=null,i=null;return 1===t.length?n(t[0])||Array.isArray(t[0])?i=t[0]:"string"==typeof t[0]&&(r=t[0]):2===t.length&&("string"==typeof t[0]&&(r=t[0]),(n(t[1])||Array.isArray(t[1]))&&(i=t[1])),{locale:r,params:i}}function l(t){return JSON.parse(JSON.stringify(t))}var c=Object.prototype.hasOwnProperty;function u(t,e){return c.call(t,e)}function f(t){for(var e=arguments,r=Object(t),i=1;i0;)e[n]=arguments[n+1];var r=this.$i18n;return r._t.apply(r,[t,r.locale,r._getMessages(),this].concat(e))},t.prototype.$tc=function(t,e){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];var i=this.$i18n;return i._tc.apply(i,[t,i.locale,i._getMessages(),this,e].concat(n))},t.prototype.$te=function(t,e){var n=this.$i18n;return n._te(t,n.locale,n._getMessages(),e)},t.prototype.$d=function(t){for(var e,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return(e=this.$i18n).d.apply(e,[t].concat(n))},t.prototype.$n=function(t){for(var e,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return(e=this.$i18n).n.apply(e,[t].concat(n))}}(y),y.mixin(p),y.directive("t",{bind:d,update:F,unbind:k}),y.component(m.name,m),y.component(b.name,b),y.config.optionMergeStrategies.i18n=function(t,e){return void 0===e?t:e}}var T=function(){this._caches=Object.create(null)};T.prototype.interpolate=function(t,e){if(!e)return[t];var r=this._caches[t];return r||(r=function(t){var e=[],n=0,r="";for(;n0)f--,u=N,h[I]();else{if(f=0,void 0===n)return!1;if(!1===(n=z(n)))return!1;h[O]()}};null!==u;)if("\\"!==(e=t[++c])||!p()){if(i=P(e),(a=(o=V[u])[i]||o.else||R)===R)return;if(u=a[0],(s=h[a[1]])&&(r=void 0===(r=a[2])?e:r,!1===s()))return;if(u===H)return l}}(t))&&(this._cache[t]=e),e||[]},J.prototype.getPathValue=function(t,e){if(!n(t))return null;var r=this.parsePath(e);if(0===r.length)return null;for(var i=r.length,a=t,s=0;s/,B=/(?:@(?:\.[a-z]+)?:(?:[\w\-_|.]+|\([\w\-_|.]+\)))/g,G=/^@(?:\.([a-z]+))?:/,X=/[()]/g,Z={upper:function(t){return t.toLocaleUpperCase()},lower:function(t){return t.toLocaleLowerCase()}},K=new T,Q=function(t){var e=this;void 0===t&&(t={}),!y&&"undefined"!=typeof window&&window.Vue&&D(window.Vue);var n=t.locale||"en-US",r=t.fallbackLocale||"en-US",i=t.messages||{},a=t.dateTimeFormats||{},o=t.numberFormats||{};this._vm=null,this._formatter=t.formatter||K,this._modifiers=t.modifiers||{},this._missing=t.missing||null,this._root=t.root||null,this._sync=void 0===t.sync||!!t.sync,this._fallbackRoot=void 0===t.fallbackRoot||!!t.fallbackRoot,this._formatFallbackMessages=void 0!==t.formatFallbackMessages&&!!t.formatFallbackMessages,this._silentTranslationWarn=void 0!==t.silentTranslationWarn&&t.silentTranslationWarn,this._silentFallbackWarn=void 0!==t.silentFallbackWarn&&!!t.silentFallbackWarn,this._dateTimeFormatters={},this._numberFormatters={},this._path=new J,this._dataListeners=[],this._preserveDirectiveContent=void 0!==t.preserveDirectiveContent&&!!t.preserveDirectiveContent,this.pluralizationRules=t.pluralizationRules||{},this._warnHtmlInMessage=t.warnHtmlInMessage||"off",this._exist=function(t,n){return!(!t||!n)&&(!s(e._path.getPathValue(t,n))||!!t[n])},"warn"!==this._warnHtmlInMessage&&"error"!==this._warnHtmlInMessage||Object.keys(i).forEach(function(t){e._checkLocaleMessage(t,e._warnHtmlInMessage,i[t])}),this._initVM({locale:n,fallbackLocale:r,messages:i,dateTimeFormats:a,numberFormats:o})},Y={vm:{configurable:!0},messages:{configurable:!0},dateTimeFormats:{configurable:!0},numberFormats:{configurable:!0},availableLocales:{configurable:!0},locale:{configurable:!0},fallbackLocale:{configurable:!0},formatFallbackMessages:{configurable:!0},missing:{configurable:!0},formatter:{configurable:!0},silentTranslationWarn:{configurable:!0},silentFallbackWarn:{configurable:!0},preserveDirectiveContent:{configurable:!0},warnHtmlInMessage:{configurable:!0}};return Q.prototype._checkLocaleMessage=function(t,n,r){var i=function(t,n,r,s){if(a(r))Object.keys(r).forEach(function(e){var o=r[e];a(o)?(s.push(e),s.push("."),i(t,n,o,s),s.pop(),s.pop()):(s.push(e),i(t,n,o,s),s.pop())});else if(Array.isArray(r))r.forEach(function(e,r){a(e)?(s.push("["+r+"]"),s.push("."),i(t,n,e,s),s.pop(),s.pop()):(s.push("["+r+"]"),i(t,n,e,s),s.pop())});else if("string"==typeof r){if(q.test(r)){var o="Detected HTML in message '"+r+"' of keypath '"+s.join("")+"' at '"+n+"'. Consider component interpolation with '' to avoid XSS. See https://bit.ly/2ZqJzkp";"warn"===t?e(o):"error"===t&&function(t,e){"undefined"!=typeof console&&(console.error("[vue-i18n] "+t),e&&console.error(e.stack))}(o)}}};i(n,t,r,[])},Q.prototype._initVM=function(t){var e=y.config.silent;y.config.silent=!0,this._vm=new y({data:t}),y.config.silent=e},Q.prototype.destroyVM=function(){this._vm.$destroy()},Q.prototype.subscribeDataChanging=function(t){this._dataListeners.push(t)},Q.prototype.unsubscribeDataChanging=function(t){!function(t,e){if(t.length){var n=t.indexOf(e);if(n>-1)t.splice(n,1)}}(this._dataListeners,t)},Q.prototype.watchI18nData=function(){var t=this;return this._vm.$watch("$data",function(){for(var e=t._dataListeners.length;e--;)y.nextTick(function(){t._dataListeners[e]&&t._dataListeners[e].$forceUpdate()})},{deep:!0})},Q.prototype.watchLocale=function(){if(!this._sync||!this._root)return null;var t=this._vm;return this._root.$i18n.vm.$watch("locale",function(e){t.$set(t,"locale",e),t.$forceUpdate()},{immediate:!0})},Y.vm.get=function(){return this._vm},Y.messages.get=function(){return l(this._getMessages())},Y.dateTimeFormats.get=function(){return l(this._getDateTimeFormats())},Y.numberFormats.get=function(){return l(this._getNumberFormats())},Y.availableLocales.get=function(){return Object.keys(this.messages).sort()},Y.locale.get=function(){return this._vm.locale},Y.locale.set=function(t){this._vm.$set(this._vm,"locale",t)},Y.fallbackLocale.get=function(){return this._vm.fallbackLocale},Y.fallbackLocale.set=function(t){this._vm.$set(this._vm,"fallbackLocale",t)},Y.formatFallbackMessages.get=function(){return this._formatFallbackMessages},Y.formatFallbackMessages.set=function(t){this._formatFallbackMessages=t},Y.missing.get=function(){return this._missing},Y.missing.set=function(t){this._missing=t},Y.formatter.get=function(){return this._formatter},Y.formatter.set=function(t){this._formatter=t},Y.silentTranslationWarn.get=function(){return this._silentTranslationWarn},Y.silentTranslationWarn.set=function(t){this._silentTranslationWarn=t},Y.silentFallbackWarn.get=function(){return this._silentFallbackWarn},Y.silentFallbackWarn.set=function(t){this._silentFallbackWarn=t},Y.preserveDirectiveContent.get=function(){return this._preserveDirectiveContent},Y.preserveDirectiveContent.set=function(t){this._preserveDirectiveContent=t},Y.warnHtmlInMessage.get=function(){return this._warnHtmlInMessage},Y.warnHtmlInMessage.set=function(t){var e=this,n=this._warnHtmlInMessage;if(this._warnHtmlInMessage=t,n!==t&&("warn"===t||"error"===t)){var r=this._getMessages();Object.keys(r).forEach(function(t){e._checkLocaleMessage(t,e._warnHtmlInMessage,r[t])})}},Q.prototype._getMessages=function(){return this._vm.messages},Q.prototype._getDateTimeFormats=function(){return this._vm.dateTimeFormats},Q.prototype._getNumberFormats=function(){return this._vm.numberFormats},Q.prototype._warnDefault=function(t,e,n,r,i){if(!s(n))return n;if(this._missing){var a=this._missing.apply(null,[t,e,r,i]);if("string"==typeof a)return a}if(this._formatFallbackMessages){var l=o.apply(void 0,i);return this._render(e,"string",l.params,e)}return e},Q.prototype._isFallbackRoot=function(t){return!t&&!s(this._root)&&this._fallbackRoot},Q.prototype._isSilentFallbackWarn=function(t){return this._silentFallbackWarn instanceof RegExp?this._silentFallbackWarn.test(t):this._silentFallbackWarn},Q.prototype._isSilentFallback=function(t,e){return this._isSilentFallbackWarn(e)&&(this._isFallbackRoot()||t!==this.fallbackLocale)},Q.prototype._isSilentTranslationWarn=function(t){return this._silentTranslationWarn instanceof RegExp?this._silentTranslationWarn.test(t):this._silentTranslationWarn},Q.prototype._interpolate=function(t,e,n,r,i,o,l){if(!e)return null;var c,u=this._path.getPathValue(e,n);if(Array.isArray(u)||a(u))return u;if(s(u)){if(!a(e))return null;if("string"!=typeof(c=e[n]))return null}else{if("string"!=typeof u)return null;c=u}return(c.indexOf("@:")>=0||c.indexOf("@.")>=0)&&(c=this._link(t,e,c,r,"raw",o,l)),this._render(c,i,o,n)},Q.prototype._link=function(t,e,n,r,i,a,s){var o=n,l=o.match(B);for(var c in l)if(l.hasOwnProperty(c)){var u=l[c],f=u.match(G),h=f[0],p=f[1],m=u.replace(h,"").replace(X,"");if(s.includes(m))return o;s.push(m);var g=this._interpolate(t,e,m,r,"raw"===i?"string":i,"raw"===i?void 0:a,s);if(this._isFallbackRoot(g)){if(!this._root)throw Error("unexpected error");var _=this._root.$i18n;g=_._translate(_._getMessages(),_.locale,_.fallbackLocale,m,r,i,a)}g=this._warnDefault(t,m,g,r,Array.isArray(a)?a:[a]),this._modifiers.hasOwnProperty(p)?g=this._modifiers[p](g):Z.hasOwnProperty(p)&&(g=Z[p](g)),s.pop(),o=g?o.replace(u,g):o}return o},Q.prototype._render=function(t,e,n,r){var i=this._formatter.interpolate(t,n,r);return i||(i=K.interpolate(t,n,r)),"string"===e?i.join(""):i},Q.prototype._translate=function(t,e,n,r,i,a,o){var l=this._interpolate(e,t[e],r,i,a,o,[r]);return s(l)&&s(l=this._interpolate(n,t[n],r,i,a,o,[r]))?null:l},Q.prototype._t=function(t,e,n,r){for(var i,a=[],s=arguments.length-4;s-- >0;)a[s]=arguments[s+4];if(!t)return"";var l=o.apply(void 0,a),c=l.locale||e,u=this._translate(n,c,this.fallbackLocale,t,r,"string",l.params);if(this._isFallbackRoot(u)){if(!this._root)throw Error("unexpected error");return(i=this._root).$t.apply(i,[t].concat(a))}return this._warnDefault(c,t,u,r,a)},Q.prototype.t=function(t){for(var e,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return(e=this)._t.apply(e,[t,this.locale,this._getMessages(),null].concat(n))},Q.prototype._i=function(t,e,n,r,i){var a=this._translate(n,e,this.fallbackLocale,t,r,"raw",i);if(this._isFallbackRoot(a)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.i(t,e,i)}return this._warnDefault(e,t,a,r,[i])},Q.prototype.i=function(t,e,n){return t?("string"!=typeof e&&(e=this.locale),this._i(t,e,this._getMessages(),null,n)):""},Q.prototype._tc=function(t,e,n,r,i){for(var a,s=[],l=arguments.length-5;l-- >0;)s[l]=arguments[l+5];if(!t)return"";void 0===i&&(i=1);var c={count:i,n:i},u=o.apply(void 0,s);return u.params=Object.assign(c,u.params),s=null===u.locale?[u.params]:[u.locale,u.params],this.fetchChoice((a=this)._t.apply(a,[t,e,n,r].concat(s)),i)},Q.prototype.fetchChoice=function(t,e){if(!t&&"string"!=typeof t)return null;var n=t.split("|");return n[e=this.getChoiceIndex(e,n.length)]?n[e].trim():t},Q.prototype.getChoiceIndex=function(t,e){var n,r;return this.locale in this.pluralizationRules?this.pluralizationRules[this.locale].apply(this,[t,e]):(n=t,r=e,n=Math.abs(n),2===r?n?n>1?1:0:1:n?Math.min(n,2):0)},Q.prototype.tc=function(t,e){for(var n,r=[],i=arguments.length-2;i-- >0;)r[i]=arguments[i+2];return(n=this)._tc.apply(n,[t,this.locale,this._getMessages(),null,e].concat(r))},Q.prototype._te=function(t,e,n){for(var r=[],i=arguments.length-3;i-- >0;)r[i]=arguments[i+3];var a=o.apply(void 0,r).locale||e;return this._exist(n[a],t)},Q.prototype.te=function(t,e){return this._te(t,this.locale,this._getMessages(),e)},Q.prototype.getLocaleMessage=function(t){return l(this._vm.messages[t]||{})},Q.prototype.setLocaleMessage=function(t,e){("warn"!==this._warnHtmlInMessage&&"error"!==this._warnHtmlInMessage||(this._checkLocaleMessage(t,this._warnHtmlInMessage,e),"error"!==this._warnHtmlInMessage))&&this._vm.$set(this._vm.messages,t,e)},Q.prototype.mergeLocaleMessage=function(t,e){("warn"!==this._warnHtmlInMessage&&"error"!==this._warnHtmlInMessage||(this._checkLocaleMessage(t,this._warnHtmlInMessage,e),"error"!==this._warnHtmlInMessage))&&this._vm.$set(this._vm.messages,t,f(this._vm.messages[t]||{},e))},Q.prototype.getDateTimeFormat=function(t){return l(this._vm.dateTimeFormats[t]||{})},Q.prototype.setDateTimeFormat=function(t,e){this._vm.$set(this._vm.dateTimeFormats,t,e)},Q.prototype.mergeDateTimeFormat=function(t,e){this._vm.$set(this._vm.dateTimeFormats,t,f(this._vm.dateTimeFormats[t]||{},e))},Q.prototype._localizeDateTime=function(t,e,n,r,i){var a=e,o=r[a];if((s(o)||s(o[i]))&&(o=r[a=n]),s(o)||s(o[i]))return null;var l=o[i],c=a+"__"+i,u=this._dateTimeFormatters[c];return u||(u=this._dateTimeFormatters[c]=new Intl.DateTimeFormat(a,l)),u.format(t)},Q.prototype._d=function(t,e,n){if(!n)return new Intl.DateTimeFormat(e).format(t);var r=this._localizeDateTime(t,e,this.fallbackLocale,this._getDateTimeFormats(),n);if(this._isFallbackRoot(r)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.d(t,n,e)}return r||""},Q.prototype.d=function(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];var i=this.locale,a=null;return 1===e.length?"string"==typeof e[0]?a=e[0]:n(e[0])&&(e[0].locale&&(i=e[0].locale),e[0].key&&(a=e[0].key)):2===e.length&&("string"==typeof e[0]&&(a=e[0]),"string"==typeof e[1]&&(i=e[1])),this._d(t,i,a)},Q.prototype.getNumberFormat=function(t){return l(this._vm.numberFormats[t]||{})},Q.prototype.setNumberFormat=function(t,e){this._vm.$set(this._vm.numberFormats,t,e)},Q.prototype.mergeNumberFormat=function(t,e){this._vm.$set(this._vm.numberFormats,t,f(this._vm.numberFormats[t]||{},e))},Q.prototype._getNumberFormatter=function(t,e,n,r,i,a){var o=e,l=r[o];if((s(l)||s(l[i]))&&(l=r[o=n]),s(l)||s(l[i]))return null;var c,u=l[i];if(a)c=new Intl.NumberFormat(o,Object.assign({},u,a));else{var f=o+"__"+i;(c=this._numberFormatters[f])||(c=this._numberFormatters[f]=new Intl.NumberFormat(o,u))}return c},Q.prototype._n=function(t,e,n,r){if(!Q.availabilities.numberFormat)return"";if(!n)return(r?new Intl.NumberFormat(e,r):new Intl.NumberFormat(e)).format(t);var i=this._getNumberFormatter(t,e,this.fallbackLocale,this._getNumberFormats(),n,r),a=i&&i.format(t);if(this._isFallbackRoot(a)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.n(t,Object.assign({},{key:n,locale:e},r))}return a||""},Q.prototype.n=function(e){for(var r=[],i=arguments.length-1;i-- >0;)r[i]=arguments[i+1];var a=this.locale,s=null,o=null;return 1===r.length?"string"==typeof r[0]?s=r[0]:n(r[0])&&(r[0].locale&&(a=r[0].locale),r[0].key&&(s=r[0].key),o=Object.keys(r[0]).reduce(function(e,n){var i;return t.includes(n)?Object.assign({},e,((i={})[n]=r[0][n],i)):e},null)):2===r.length&&("string"==typeof r[0]&&(s=r[0]),"string"==typeof r[1]&&(a=r[1])),this._n(e,a,s,o)},Q.prototype._ntp=function(t,e,n,r){if(!Q.availabilities.numberFormat)return[];if(!n)return(r?new Intl.NumberFormat(e,r):new Intl.NumberFormat(e)).formatToParts(t);var i=this._getNumberFormatter(t,e,this.fallbackLocale,this._getNumberFormats(),n,r),a=i&&i.formatToParts(t);if(this._isFallbackRoot(a)){if(!this._root)throw Error("unexpected error");return this._root.$i18n._ntp(t,e,n,r)}return a||[]},Object.defineProperties(Q.prototype,Y),Object.defineProperty(Q,"availabilities",{get:function(){if(!U){var t="undefined"!=typeof Intl;U={dateTimeFormat:t&&void 0!==Intl.DateTimeFormat,numberFormat:t&&void 0!==Intl.NumberFormat}}return U}}),Q.install=D,Q.version="8.15.1",Q},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueI18n=e(); \ No newline at end of file +var t,e;t=this,e=function(){"use strict";var t=["style","currency","currencyDisplay","useGrouping","minimumIntegerDigits","minimumFractionDigits","maximumFractionDigits","minimumSignificantDigits","maximumSignificantDigits","localeMatcher","formatMatcher","unit"];function e(t,e){"undefined"!=typeof console&&(console.warn("[vue-i18n] "+t),e&&console.warn(e.stack))}function n(t){return null!==t&&"object"==typeof t}var r=Object.prototype.toString,i="[object Object]";function a(t){return r.call(t)===i}function s(t){return null==t}function o(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];var r=null,i=null;return 1===t.length?n(t[0])||Array.isArray(t[0])?i=t[0]:"string"==typeof t[0]&&(r=t[0]):2===t.length&&("string"==typeof t[0]&&(r=t[0]),(n(t[1])||Array.isArray(t[1]))&&(i=t[1])),{locale:r,params:i}}function l(t){return JSON.parse(JSON.stringify(t))}var c=Object.prototype.hasOwnProperty;function u(t,e){return c.call(t,e)}function f(t){for(var e=arguments,r=Object(t),i=1;i0;)e[n]=arguments[n+1];var r=this.$i18n;return r._t.apply(r,[t,r.locale,r._getMessages(),this].concat(e))},t.prototype.$tc=function(t,e){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];var i=this.$i18n;return i._tc.apply(i,[t,i.locale,i._getMessages(),this,e].concat(n))},t.prototype.$te=function(t,e){var n=this.$i18n;return n._te(t,n.locale,n._getMessages(),e)},t.prototype.$d=function(t){for(var e,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return(e=this.$i18n).d.apply(e,[t].concat(n))},t.prototype.$n=function(t){for(var e,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return(e=this.$i18n).n.apply(e,[t].concat(n))}}(y),y.mixin(p),y.directive("t",{bind:d,update:F,unbind:k}),y.component(m.name,m),y.component(b.name,b),y.config.optionMergeStrategies.i18n=function(t,e){return void 0===e?t:e}}var T=function(){this._caches=Object.create(null)};T.prototype.interpolate=function(t,e){if(!e)return[t];var r=this._caches[t];return r||(r=function(t){var e=[],n=0,r="";for(;n0)f--,u=N,h[I]();else{if(f=0,void 0===n)return!1;if(!1===(n=z(n)))return!1;h[O]()}};null!==u;)if("\\"!==(e=t[++c])||!p()){if(i=P(e),(a=(o=V[u])[i]||o.else||R)===R)return;if(u=a[0],(s=h[a[1]])&&(r=void 0===(r=a[2])?e:r,!1===s()))return;if(u===H)return l}}(t))&&(this._cache[t]=e),e||[]},J.prototype.getPathValue=function(t,e){if(!n(t))return null;var r=this.parsePath(e);if(0===r.length)return null;for(var i=r.length,a=t,s=0;s/,B=/(?:@(?:\.[a-z]+)?:(?:[\w\-_|.]+|\([\w\-_|.]+\)))/g,G=/^@(?:\.([a-z]+))?:/,X=/[()]/g,Z={upper:function(t){return t.toLocaleUpperCase()},lower:function(t){return t.toLocaleLowerCase()}},K=new T,Q=function(t){var e=this;void 0===t&&(t={}),!y&&"undefined"!=typeof window&&window.Vue&&D(window.Vue);var n=t.locale||"en-US",r=t.fallbackLocale||"en-US",i=t.messages||{},a=t.dateTimeFormats||{},o=t.numberFormats||{};this._vm=null,this._formatter=t.formatter||K,this._modifiers=t.modifiers||{},this._missing=t.missing||null,this._root=t.root||null,this._sync=void 0===t.sync||!!t.sync,this._fallbackRoot=void 0===t.fallbackRoot||!!t.fallbackRoot,this._formatFallbackMessages=void 0!==t.formatFallbackMessages&&!!t.formatFallbackMessages,this._silentTranslationWarn=void 0!==t.silentTranslationWarn&&t.silentTranslationWarn,this._silentFallbackWarn=void 0!==t.silentFallbackWarn&&!!t.silentFallbackWarn,this._dateTimeFormatters={},this._numberFormatters={},this._path=new J,this._dataListeners=[],this._preserveDirectiveContent=void 0!==t.preserveDirectiveContent&&!!t.preserveDirectiveContent,this.pluralizationRules=t.pluralizationRules||{},this._warnHtmlInMessage=t.warnHtmlInMessage||"off",this._exist=function(t,n){return!(!t||!n)&&(!s(e._path.getPathValue(t,n))||!!t[n])},"warn"!==this._warnHtmlInMessage&&"error"!==this._warnHtmlInMessage||Object.keys(i).forEach(function(t){e._checkLocaleMessage(t,e._warnHtmlInMessage,i[t])}),this._initVM({locale:n,fallbackLocale:r,messages:i,dateTimeFormats:a,numberFormats:o})},Y={vm:{configurable:!0},messages:{configurable:!0},dateTimeFormats:{configurable:!0},numberFormats:{configurable:!0},availableLocales:{configurable:!0},locale:{configurable:!0},fallbackLocale:{configurable:!0},formatFallbackMessages:{configurable:!0},missing:{configurable:!0},formatter:{configurable:!0},silentTranslationWarn:{configurable:!0},silentFallbackWarn:{configurable:!0},preserveDirectiveContent:{configurable:!0},warnHtmlInMessage:{configurable:!0}};return Q.prototype._checkLocaleMessage=function(t,n,r){var i=function(t,n,r,s){if(a(r))Object.keys(r).forEach(function(e){var o=r[e];a(o)?(s.push(e),s.push("."),i(t,n,o,s),s.pop(),s.pop()):(s.push(e),i(t,n,o,s),s.pop())});else if(Array.isArray(r))r.forEach(function(e,r){a(e)?(s.push("["+r+"]"),s.push("."),i(t,n,e,s),s.pop(),s.pop()):(s.push("["+r+"]"),i(t,n,e,s),s.pop())});else if("string"==typeof r){if(q.test(r)){var o="Detected HTML in message '"+r+"' of keypath '"+s.join("")+"' at '"+n+"'. Consider component interpolation with '' to avoid XSS. See https://bit.ly/2ZqJzkp";"warn"===t?e(o):"error"===t&&function(t,e){"undefined"!=typeof console&&(console.error("[vue-i18n] "+t),e&&console.error(e.stack))}(o)}}};i(n,t,r,[])},Q.prototype._initVM=function(t){var e=y.config.silent;y.config.silent=!0,this._vm=new y({data:t}),y.config.silent=e},Q.prototype.destroyVM=function(){this._vm.$destroy()},Q.prototype.subscribeDataChanging=function(t){this._dataListeners.push(t)},Q.prototype.unsubscribeDataChanging=function(t){!function(t,e){if(t.length){var n=t.indexOf(e);if(n>-1)t.splice(n,1)}}(this._dataListeners,t)},Q.prototype.watchI18nData=function(){var t=this;return this._vm.$watch("$data",function(){for(var e=t._dataListeners.length;e--;)y.nextTick(function(){t._dataListeners[e]&&t._dataListeners[e].$forceUpdate()})},{deep:!0})},Q.prototype.watchLocale=function(){if(!this._sync||!this._root)return null;var t=this._vm;return this._root.$i18n.vm.$watch("locale",function(e){t.$set(t,"locale",e),t.$forceUpdate()},{immediate:!0})},Y.vm.get=function(){return this._vm},Y.messages.get=function(){return l(this._getMessages())},Y.dateTimeFormats.get=function(){return l(this._getDateTimeFormats())},Y.numberFormats.get=function(){return l(this._getNumberFormats())},Y.availableLocales.get=function(){return Object.keys(this.messages).sort()},Y.locale.get=function(){return this._vm.locale},Y.locale.set=function(t){this._vm.$set(this._vm,"locale",t)},Y.fallbackLocale.get=function(){return this._vm.fallbackLocale},Y.fallbackLocale.set=function(t){this._vm.$set(this._vm,"fallbackLocale",t)},Y.formatFallbackMessages.get=function(){return this._formatFallbackMessages},Y.formatFallbackMessages.set=function(t){this._formatFallbackMessages=t},Y.missing.get=function(){return this._missing},Y.missing.set=function(t){this._missing=t},Y.formatter.get=function(){return this._formatter},Y.formatter.set=function(t){this._formatter=t},Y.silentTranslationWarn.get=function(){return this._silentTranslationWarn},Y.silentTranslationWarn.set=function(t){this._silentTranslationWarn=t},Y.silentFallbackWarn.get=function(){return this._silentFallbackWarn},Y.silentFallbackWarn.set=function(t){this._silentFallbackWarn=t},Y.preserveDirectiveContent.get=function(){return this._preserveDirectiveContent},Y.preserveDirectiveContent.set=function(t){this._preserveDirectiveContent=t},Y.warnHtmlInMessage.get=function(){return this._warnHtmlInMessage},Y.warnHtmlInMessage.set=function(t){var e=this,n=this._warnHtmlInMessage;if(this._warnHtmlInMessage=t,n!==t&&("warn"===t||"error"===t)){var r=this._getMessages();Object.keys(r).forEach(function(t){e._checkLocaleMessage(t,e._warnHtmlInMessage,r[t])})}},Q.prototype._getMessages=function(){return this._vm.messages},Q.prototype._getDateTimeFormats=function(){return this._vm.dateTimeFormats},Q.prototype._getNumberFormats=function(){return this._vm.numberFormats},Q.prototype._warnDefault=function(t,e,n,r,i){if(!s(n))return n;if(this._missing){var a=this._missing.apply(null,[t,e,r,i]);if("string"==typeof a)return a}if(this._formatFallbackMessages){var l=o.apply(void 0,i);return this._render(e,"string",l.params,e)}return e},Q.prototype._isFallbackRoot=function(t){return!t&&!s(this._root)&&this._fallbackRoot},Q.prototype._isSilentFallbackWarn=function(t){return this._silentFallbackWarn instanceof RegExp?this._silentFallbackWarn.test(t):this._silentFallbackWarn},Q.prototype._isSilentFallback=function(t,e){return this._isSilentFallbackWarn(e)&&(this._isFallbackRoot()||t!==this.fallbackLocale)},Q.prototype._isSilentTranslationWarn=function(t){return this._silentTranslationWarn instanceof RegExp?this._silentTranslationWarn.test(t):this._silentTranslationWarn},Q.prototype._interpolate=function(t,e,n,r,i,o,l){if(!e)return null;var c,u=this._path.getPathValue(e,n);if(Array.isArray(u)||a(u))return u;if(s(u)){if(!a(e))return null;if("string"!=typeof(c=e[n]))return null}else{if("string"!=typeof u)return null;c=u}return(c.indexOf("@:")>=0||c.indexOf("@.")>=0)&&(c=this._link(t,e,c,r,"raw",o,l)),this._render(c,i,o,n)},Q.prototype._link=function(t,e,n,r,i,a,s){var o=n,l=o.match(B);for(var c in l)if(l.hasOwnProperty(c)){var u=l[c],f=u.match(G),h=f[0],p=f[1],m=u.replace(h,"").replace(X,"");if(s.includes(m))return o;s.push(m);var g=this._interpolate(t,e,m,r,"raw"===i?"string":i,"raw"===i?void 0:a,s);if(this._isFallbackRoot(g)){if(!this._root)throw Error("unexpected error");var _=this._root.$i18n;g=_._translate(_._getMessages(),_.locale,_.fallbackLocale,m,r,i,a)}g=this._warnDefault(t,m,g,r,Array.isArray(a)?a:[a]),this._modifiers.hasOwnProperty(p)?g=this._modifiers[p](g):Z.hasOwnProperty(p)&&(g=Z[p](g)),s.pop(),o=g?o.replace(u,g):o}return o},Q.prototype._render=function(t,e,n,r){var i=this._formatter.interpolate(t,n,r);return i||(i=K.interpolate(t,n,r)),"string"===e?i.join(""):i},Q.prototype._translate=function(t,e,n,r,i,a,o){var l=this._interpolate(e,t[e],r,i,a,o,[r]);return s(l)&&s(l=this._interpolate(n,t[n],r,i,a,o,[r]))?null:l},Q.prototype._t=function(t,e,n,r){for(var i,a=[],s=arguments.length-4;s-- >0;)a[s]=arguments[s+4];if(!t)return"";var l=o.apply(void 0,a),c=l.locale||e,u=this._translate(n,c,this.fallbackLocale,t,r,"string",l.params);if(this._isFallbackRoot(u)){if(!this._root)throw Error("unexpected error");return(i=this._root).$t.apply(i,[t].concat(a))}return this._warnDefault(c,t,u,r,a)},Q.prototype.t=function(t){for(var e,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return(e=this)._t.apply(e,[t,this.locale,this._getMessages(),null].concat(n))},Q.prototype._i=function(t,e,n,r,i){var a=this._translate(n,e,this.fallbackLocale,t,r,"raw",i);if(this._isFallbackRoot(a)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.i(t,e,i)}return this._warnDefault(e,t,a,r,[i])},Q.prototype.i=function(t,e,n){return t?("string"!=typeof e&&(e=this.locale),this._i(t,e,this._getMessages(),null,n)):""},Q.prototype._tc=function(t,e,n,r,i){for(var a,s=[],l=arguments.length-5;l-- >0;)s[l]=arguments[l+5];if(!t)return"";void 0===i&&(i=1);var c={count:i,n:i},u=o.apply(void 0,s);return u.params=Object.assign(c,u.params),s=null===u.locale?[u.params]:[u.locale,u.params],this.fetchChoice((a=this)._t.apply(a,[t,e,n,r].concat(s)),i)},Q.prototype.fetchChoice=function(t,e){if(!t&&"string"!=typeof t)return null;var n=t.split("|");return n[e=this.getChoiceIndex(e,n.length)]?n[e].trim():t},Q.prototype.getChoiceIndex=function(t,e){var n,r;return this.locale in this.pluralizationRules?this.pluralizationRules[this.locale].apply(this,[t,e]):(n=t,r=e,n=Math.abs(n),2===r?n?n>1?1:0:1:n?Math.min(n,2):0)},Q.prototype.tc=function(t,e){for(var n,r=[],i=arguments.length-2;i-- >0;)r[i]=arguments[i+2];return(n=this)._tc.apply(n,[t,this.locale,this._getMessages(),null,e].concat(r))},Q.prototype._te=function(t,e,n){for(var r=[],i=arguments.length-3;i-- >0;)r[i]=arguments[i+3];var a=o.apply(void 0,r).locale||e;return this._exist(n[a],t)},Q.prototype.te=function(t,e){return this._te(t,this.locale,this._getMessages(),e)},Q.prototype.getLocaleMessage=function(t){return l(this._vm.messages[t]||{})},Q.prototype.setLocaleMessage=function(t,e){("warn"!==this._warnHtmlInMessage&&"error"!==this._warnHtmlInMessage||(this._checkLocaleMessage(t,this._warnHtmlInMessage,e),"error"!==this._warnHtmlInMessage))&&this._vm.$set(this._vm.messages,t,e)},Q.prototype.mergeLocaleMessage=function(t,e){("warn"!==this._warnHtmlInMessage&&"error"!==this._warnHtmlInMessage||(this._checkLocaleMessage(t,this._warnHtmlInMessage,e),"error"!==this._warnHtmlInMessage))&&this._vm.$set(this._vm.messages,t,f(this._vm.messages[t]||{},e))},Q.prototype.getDateTimeFormat=function(t){return l(this._vm.dateTimeFormats[t]||{})},Q.prototype.setDateTimeFormat=function(t,e){this._vm.$set(this._vm.dateTimeFormats,t,e)},Q.prototype.mergeDateTimeFormat=function(t,e){this._vm.$set(this._vm.dateTimeFormats,t,f(this._vm.dateTimeFormats[t]||{},e))},Q.prototype._localizeDateTime=function(t,e,n,r,i){var a=e,o=r[a];if((s(o)||s(o[i]))&&(o=r[a=n]),s(o)||s(o[i]))return null;var l=o[i],c=a+"__"+i,u=this._dateTimeFormatters[c];return u||(u=this._dateTimeFormatters[c]=new Intl.DateTimeFormat(a,l)),u.format(t)},Q.prototype._d=function(t,e,n){if(!n)return new Intl.DateTimeFormat(e).format(t);var r=this._localizeDateTime(t,e,this.fallbackLocale,this._getDateTimeFormats(),n);if(this._isFallbackRoot(r)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.d(t,n,e)}return r||""},Q.prototype.d=function(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];var i=this.locale,a=null;return 1===e.length?"string"==typeof e[0]?a=e[0]:n(e[0])&&(e[0].locale&&(i=e[0].locale),e[0].key&&(a=e[0].key)):2===e.length&&("string"==typeof e[0]&&(a=e[0]),"string"==typeof e[1]&&(i=e[1])),this._d(t,i,a)},Q.prototype.getNumberFormat=function(t){return l(this._vm.numberFormats[t]||{})},Q.prototype.setNumberFormat=function(t,e){this._vm.$set(this._vm.numberFormats,t,e)},Q.prototype.mergeNumberFormat=function(t,e){this._vm.$set(this._vm.numberFormats,t,f(this._vm.numberFormats[t]||{},e))},Q.prototype._getNumberFormatter=function(t,e,n,r,i,a){var o=e,l=r[o];if((s(l)||s(l[i]))&&(l=r[o=n]),s(l)||s(l[i]))return null;var c,u=l[i];if(a)c=new Intl.NumberFormat(o,Object.assign({},u,a));else{var f=o+"__"+i;(c=this._numberFormatters[f])||(c=this._numberFormatters[f]=new Intl.NumberFormat(o,u))}return c},Q.prototype._n=function(t,e,n,r){if(!Q.availabilities.numberFormat)return"";if(!n)return(r?new Intl.NumberFormat(e,r):new Intl.NumberFormat(e)).format(t);var i=this._getNumberFormatter(t,e,this.fallbackLocale,this._getNumberFormats(),n,r),a=i&&i.format(t);if(this._isFallbackRoot(a)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.n(t,Object.assign({},{key:n,locale:e},r))}return a||""},Q.prototype.n=function(e){for(var r=[],i=arguments.length-1;i-- >0;)r[i]=arguments[i+1];var a=this.locale,s=null,o=null;return 1===r.length?"string"==typeof r[0]?s=r[0]:n(r[0])&&(r[0].locale&&(a=r[0].locale),r[0].key&&(s=r[0].key),o=Object.keys(r[0]).reduce(function(e,n){var i;return t.includes(n)?Object.assign({},e,((i={})[n]=r[0][n],i)):e},null)):2===r.length&&("string"==typeof r[0]&&(s=r[0]),"string"==typeof r[1]&&(a=r[1])),this._n(e,a,s,o)},Q.prototype._ntp=function(t,e,n,r){if(!Q.availabilities.numberFormat)return[];if(!n)return(r?new Intl.NumberFormat(e,r):new Intl.NumberFormat(e)).formatToParts(t);var i=this._getNumberFormatter(t,e,this.fallbackLocale,this._getNumberFormats(),n,r),a=i&&i.formatToParts(t);if(this._isFallbackRoot(a)){if(!this._root)throw Error("unexpected error");return this._root.$i18n._ntp(t,e,n,r)}return a||[]},Object.defineProperties(Q.prototype,Y),Object.defineProperty(Q,"availabilities",{get:function(){if(!U){var t="undefined"!=typeof Intl;U={dateTimeFormat:t&&void 0!==Intl.DateTimeFormat,numberFormat:t&&void 0!==Intl.NumberFormat}}return U}}),Q.install=D,Q.version="8.15.1",Q},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueI18n=e(); \ No newline at end of file diff --git a/src/util.js b/src/util.js index 834af4ce6..04c021edd 100644 --- a/src/util.js +++ b/src/util.js @@ -15,7 +15,8 @@ export const numberFormatKeys = [ 'minimumSignificantDigits', 'maximumSignificantDigits', 'localeMatcher', - 'formatMatcher' + 'formatMatcher', + 'unit' ] /**