vue-i18n 8.6.0 → 8.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/decls/i18n.js +3 -1
- package/dist/vue-i18n.common.js +11 -4
- package/dist/vue-i18n.esm.js +11 -4
- package/dist/vue-i18n.js +11 -4
- package/dist/vue-i18n.min.js +3 -3
- package/package.json +1 -1
- package/src/directive.js +4 -1
- package/src/index.js +4 -0
- package/src/mixin.js +1 -0
- package/types/index.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
<a name="8.7.0"></a>
|
|
2
|
+
# [8.7.0](https://github.com/kazupon/vue-i18n/compare/v8.6.0...v8.7.0) (2019-01-02)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### :zap: Improvements
|
|
6
|
+
|
|
7
|
+
* **directive:** Preserve directive content ([#495](https://github.com/kazupon/vue-i18n/issues/495)) by [@bponomarenko](https://github.com/bponomarenko) ([c29edba](https://github.com/kazupon/vue-i18n/commit/c29edba)), closes [#495](https://github.com/kazupon/vue-i18n/issues/495) [#408](https://github.com/kazupon/vue-i18n/issues/408) [#408](https://github.com/kazupon/vue-i18n/issues/408)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
1
11
|
<a name="8.6.0"></a>
|
|
2
12
|
# [8.6.0](https://github.com/kazupon/vue-i18n/compare/v8.5.0...v8.6.0) (2018-12-25)
|
|
3
13
|
|
package/decls/i18n.js
CHANGED
|
@@ -65,6 +65,7 @@ declare type I18nOptions = {
|
|
|
65
65
|
pluralizationRules?: {
|
|
66
66
|
[lang: string]: (choice: number, choicesLength: number) => number,
|
|
67
67
|
},
|
|
68
|
+
preserveDirectiveContent?: boolean,
|
|
68
69
|
};
|
|
69
70
|
|
|
70
71
|
declare type IntlAvailability = {
|
|
@@ -106,7 +107,8 @@ declare interface I18n {
|
|
|
106
107
|
n (value: number, ...args: any): NumberFormatResult,
|
|
107
108
|
pluralizationRules: {
|
|
108
109
|
[lang: string]: (choice: number, choicesLength: number) => number
|
|
109
|
-
}
|
|
110
|
+
},
|
|
111
|
+
preserveDirectiveContent: boolean
|
|
110
112
|
};
|
|
111
113
|
|
|
112
114
|
declare interface Formatter {
|
package/dist/vue-i18n.common.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* vue-i18n v8.
|
|
3
|
-
* (c)
|
|
2
|
+
* vue-i18n v8.7.0
|
|
3
|
+
* (c) 2019 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
@@ -218,6 +218,7 @@ var mixin = {
|
|
|
218
218
|
options.i18n.fallbackLocale = this.$root.$i18n.fallbackLocale;
|
|
219
219
|
options.i18n.silentTranslationWarn = this.$root.$i18n.silentTranslationWarn;
|
|
220
220
|
options.i18n.pluralizationRules = this.$root.$i18n.pluralizationRules;
|
|
221
|
+
options.i18n.preserveDirectiveContent = this.$root.$i18n.preserveDirectiveContent;
|
|
221
222
|
}
|
|
222
223
|
|
|
223
224
|
// init locale messages via custom blocks
|
|
@@ -391,7 +392,10 @@ function unbind (el, binding, vnode, oldVNode) {
|
|
|
391
392
|
return
|
|
392
393
|
}
|
|
393
394
|
|
|
394
|
-
|
|
395
|
+
var i18n = vnode.context.$i18n || {};
|
|
396
|
+
if (!binding.modifiers.preserve && !i18n.preserveDirectiveContent) {
|
|
397
|
+
el.textContent = '';
|
|
398
|
+
}
|
|
395
399
|
el._vt = undefined;
|
|
396
400
|
delete el['_vt'];
|
|
397
401
|
el._locale = undefined;
|
|
@@ -977,6 +981,9 @@ var VueI18n = function VueI18n (options) {
|
|
|
977
981
|
this._dataListeners = [];
|
|
978
982
|
|
|
979
983
|
this.pluralizationRules = options.pluralizationRules || {};
|
|
984
|
+
this.preserveDirectiveContent = options.preserveDirectiveContent === undefined
|
|
985
|
+
? false
|
|
986
|
+
: !!options.preserveDirectiveContent;
|
|
980
987
|
|
|
981
988
|
this._exist = function (message, key) {
|
|
982
989
|
if (!message || !key) { return false }
|
|
@@ -1633,6 +1640,6 @@ Object.defineProperty(VueI18n, 'availabilities', {
|
|
|
1633
1640
|
}
|
|
1634
1641
|
});
|
|
1635
1642
|
VueI18n.install = install;
|
|
1636
|
-
VueI18n.version = '8.
|
|
1643
|
+
VueI18n.version = '8.7.0';
|
|
1637
1644
|
|
|
1638
1645
|
module.exports = VueI18n;
|
package/dist/vue-i18n.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* vue-i18n v8.
|
|
3
|
-
* (c)
|
|
2
|
+
* vue-i18n v8.7.0
|
|
3
|
+
* (c) 2019 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
/* */
|
|
@@ -216,6 +216,7 @@ var mixin = {
|
|
|
216
216
|
options.i18n.fallbackLocale = this.$root.$i18n.fallbackLocale;
|
|
217
217
|
options.i18n.silentTranslationWarn = this.$root.$i18n.silentTranslationWarn;
|
|
218
218
|
options.i18n.pluralizationRules = this.$root.$i18n.pluralizationRules;
|
|
219
|
+
options.i18n.preserveDirectiveContent = this.$root.$i18n.preserveDirectiveContent;
|
|
219
220
|
}
|
|
220
221
|
|
|
221
222
|
// init locale messages via custom blocks
|
|
@@ -389,7 +390,10 @@ function unbind (el, binding, vnode, oldVNode) {
|
|
|
389
390
|
return
|
|
390
391
|
}
|
|
391
392
|
|
|
392
|
-
|
|
393
|
+
var i18n = vnode.context.$i18n || {};
|
|
394
|
+
if (!binding.modifiers.preserve && !i18n.preserveDirectiveContent) {
|
|
395
|
+
el.textContent = '';
|
|
396
|
+
}
|
|
393
397
|
el._vt = undefined;
|
|
394
398
|
delete el['_vt'];
|
|
395
399
|
el._locale = undefined;
|
|
@@ -975,6 +979,9 @@ var VueI18n = function VueI18n (options) {
|
|
|
975
979
|
this._dataListeners = [];
|
|
976
980
|
|
|
977
981
|
this.pluralizationRules = options.pluralizationRules || {};
|
|
982
|
+
this.preserveDirectiveContent = options.preserveDirectiveContent === undefined
|
|
983
|
+
? false
|
|
984
|
+
: !!options.preserveDirectiveContent;
|
|
978
985
|
|
|
979
986
|
this._exist = function (message, key) {
|
|
980
987
|
if (!message || !key) { return false }
|
|
@@ -1631,6 +1638,6 @@ Object.defineProperty(VueI18n, 'availabilities', {
|
|
|
1631
1638
|
}
|
|
1632
1639
|
});
|
|
1633
1640
|
VueI18n.install = install;
|
|
1634
|
-
VueI18n.version = '8.
|
|
1641
|
+
VueI18n.version = '8.7.0';
|
|
1635
1642
|
|
|
1636
1643
|
export default VueI18n;
|
package/dist/vue-i18n.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* vue-i18n v8.
|
|
3
|
-
* (c)
|
|
2
|
+
* vue-i18n v8.7.0
|
|
3
|
+
* (c) 2019 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
(function (global, factory) {
|
|
@@ -222,6 +222,7 @@
|
|
|
222
222
|
options.i18n.fallbackLocale = this.$root.$i18n.fallbackLocale;
|
|
223
223
|
options.i18n.silentTranslationWarn = this.$root.$i18n.silentTranslationWarn;
|
|
224
224
|
options.i18n.pluralizationRules = this.$root.$i18n.pluralizationRules;
|
|
225
|
+
options.i18n.preserveDirectiveContent = this.$root.$i18n.preserveDirectiveContent;
|
|
225
226
|
}
|
|
226
227
|
|
|
227
228
|
// init locale messages via custom blocks
|
|
@@ -395,7 +396,10 @@
|
|
|
395
396
|
return
|
|
396
397
|
}
|
|
397
398
|
|
|
398
|
-
|
|
399
|
+
var i18n = vnode.context.$i18n || {};
|
|
400
|
+
if (!binding.modifiers.preserve && !i18n.preserveDirectiveContent) {
|
|
401
|
+
el.textContent = '';
|
|
402
|
+
}
|
|
399
403
|
el._vt = undefined;
|
|
400
404
|
delete el['_vt'];
|
|
401
405
|
el._locale = undefined;
|
|
@@ -981,6 +985,9 @@
|
|
|
981
985
|
this._dataListeners = [];
|
|
982
986
|
|
|
983
987
|
this.pluralizationRules = options.pluralizationRules || {};
|
|
988
|
+
this.preserveDirectiveContent = options.preserveDirectiveContent === undefined
|
|
989
|
+
? false
|
|
990
|
+
: !!options.preserveDirectiveContent;
|
|
984
991
|
|
|
985
992
|
this._exist = function (message, key) {
|
|
986
993
|
if (!message || !key) { return false }
|
|
@@ -1637,7 +1644,7 @@
|
|
|
1637
1644
|
}
|
|
1638
1645
|
});
|
|
1639
1646
|
VueI18n.install = install;
|
|
1640
|
-
VueI18n.version = '8.
|
|
1647
|
+
VueI18n.version = '8.7.0';
|
|
1641
1648
|
|
|
1642
1649
|
return VueI18n;
|
|
1643
1650
|
|
package/dist/vue-i18n.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* vue-i18n v8.
|
|
3
|
-
* (c)
|
|
2
|
+
* vue-i18n v8.7.0
|
|
3
|
+
* (c) 2019 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueI18n=e()}(this,function(){"use strict";function t(t,e){"undefined"!=typeof console&&(console.warn("[vue-i18n] "+t),e&&console.warn(e.stack))}function e(t){return null!==t&&"object"==typeof t}function n(t){return L.call(t)===O}function r(t){return null===t||void 0===t}function i(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var r=null,i=null;return 1===t.length?e(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]),(e(t[1])||Array.isArray(t[1]))&&(i=t[1])),{locale:r,params:i}}function a(t){return JSON.parse(JSON.stringify(t))}function o(t,e){if(t.length){var n=t.indexOf(e);if(n>-1)return t.splice(n,1)}}function s(t,e){return M.call(t,e)}function l(t){for(var n=arguments,r=Object(t),i=1;i<arguments.length;i++){var a=n[i];if(void 0!==a&&null!==a){var o=void 0;for(o in a)s(a,o)&&(e(a[o])?r[o]=l(r[o],a[o]):r[o]=a[o])}}return r}function c(t,n){if(t===n)return!0;var r=e(t),i=e(n);if(!r||!i)return!r&&!i&&String(t)===String(n);try{var a=Array.isArray(t),o=Array.isArray(n);if(a&&o)return t.length===n.length&&t.every(function(t,e){return c(t,n[e])});if(a||o)return!1;var s=Object.keys(t),l=Object.keys(n);return s.length===l.length&&s.every(function(e){return c(t[e],n[e])})}catch(t){return!1}}function u(t){t.prototype.hasOwnProperty("$i18n")||Object.defineProperty(t.prototype,"$i18n",{get:function(){return this._i18n}}),t.prototype.$t=function(t){for(var e=[],n=arguments.length-1;n-- >0;)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))}}function f(t,e,n){m(t,n)&&g(t,e,n)}function h(t,e,n,r){if(m(t,n)){var i=n.context.$i18n;_(t,n)&&c(e.value,e.oldValue)&&c(t._localeMessage,i.getLocaleMessage(i.locale))||g(t,e,n)}}function p(e,n,r,i){if(!r.context)return void t("Vue instance does not exists in VNode context");e.textContent="",e._vt=void 0,delete e._vt,e._locale=void 0,delete e._locale,e._localeMessage=void 0,delete e._localeMessage}function m(e,n){var r=n.context;return r?!!r.$i18n||(t("VueI18n instance does not exists in Vue instance"),!1):(t("Vue instance doest not exists in VNode context"),!1)}function _(t,e){var n=e.context;return t._locale===n.$i18n.locale}function g(e,n,r){var i,a,o=n.value,s=v(o),l=s.path,c=s.locale,u=s.args,f=s.choice;if(!l&&!c&&!u)return void t("value type not supported");if(!l)return void t("`path` is required in v-t directive");var h=r.context;e._vt=e.textContent=f?(i=h.$i18n).tc.apply(i,[l,f].concat(y(c,u))):(a=h.$i18n).t.apply(a,[l].concat(y(c,u))),e._locale=h.$i18n.locale,e._localeMessage=h.$i18n.getLocaleMessage(h.$i18n.locale)}function v(t){var e,r,i,a;return"string"==typeof t?e=t:n(t)&&(e=t.path,r=t.locale,i=t.args,a=t.choice),{path:e,locale:r,args:i,choice:a}}function y(t,e){var r=[];return t&&r.push(t),e&&(Array.isArray(e)||n(e))&&r.push(e),r}function d(t){d.installed=!0,D=t;D.version&&Number(D.version.split(".")[0]);u(D),D.mixin(A),D.directive("t",{bind:f,update:h,unbind:p}),D.component(j.name,j),D.config.optionMergeStrategies.i18n=function(t,e){return void 0===e?t:e}}function b(t){for(var e=[],n=0,r="";n<t.length;){var i=t[n++];if("{"===i){r&&e.push({type:"text",value:r}),r="";var a="";for(i=t[n++];void 0!==i&&"}"!==i;)a+=i,i=t[n++];var o="}"===i,s=C.test(a)?"list":o&&W.test(a)?"named":"unknown";e.push({value:a,type:s})}else"%"===i?"{"!==t[n]&&(r+=i):r+=i}return r&&e.push({type:"text",value:r}),e}function $(t,n){var r=[],i=0,a=Array.isArray(n)?"list":e(n)?"named":"unknown";if("unknown"===a)return r;for(;i<t.length;){var o=t[i];switch(o.type){case"text":r.push(o.value);break;case"list":r.push(n[parseInt(o.value,10)]);break;case"named":"named"===a&&r.push(n[o.value])}i++}return r}function w(t){return B.test(t)}function F(t){var e=t.charCodeAt(0);return e!==t.charCodeAt(t.length-1)||34!==e&&39!==e?t:t.slice(1,-1)}function k(t){if(void 0===t||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 32:case 9:case 10:case 13:case 160:case 65279:case 8232:case 8233:return"ws"}return"ident"}function x(t){var e=t.trim();return("0"!==t.charAt(0)||!isNaN(t))&&(w(e)?F(e):"*"+e)}function T(t){var e,n,r,i,a,o,s,l=[],c=-1,u=z,f=0,h=[];for(h[R]=function(){void 0!==n&&(l.push(n),n=void 0)},h[I]=function(){void 0===n?n=r:n+=r},h[S]=function(){h[I](),f++},h[V]=function(){if(f>0)f--,u=P,h[I]();else{if(f=0,!1===(n=x(n)))return!1;h[R]()}};null!==u;)if(c++,"\\"!==(e=t[c])||!function(){var e=t[c+1];if(u===E&&"'"===e||u===U&&'"'===e)return c++,r="\\"+e,h[I](),!0}()){if(i=k(e),s=G[u],(a=s[i]||s.else||q)===q)return;if(u=a[0],(o=h[a[1]])&&(r=a[2],r=void 0===r?e:r,!1===o()))return;if(u===J)return l}}var D,L=Object.prototype.toString,O="[object Object]",M=Object.prototype.hasOwnProperty,A={beforeCreate:function(){var t=this.$options;if(t.i18n=t.i18n||(t.__i18n?{}:null),t.i18n){if(t.i18n instanceof et){if(t.__i18n)try{var e={};t.__i18n.forEach(function(t){e=l(e,JSON.parse(t))}),Object.keys(e).forEach(function(n){t.i18n.mergeLocaleMessage(n,e[n])})}catch(t){}this._i18n=t.i18n,this._i18nWatcher=this._i18n.watchI18nData(),this._i18n.subscribeDataChanging(this),this._subscribing=!0}else if(n(t.i18n)){if(this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof et&&(t.i18n.root=this.$root,t.i18n.formatter=this.$root.$i18n.formatter,t.i18n.fallbackLocale=this.$root.$i18n.fallbackLocale,t.i18n.silentTranslationWarn=this.$root.$i18n.silentTranslationWarn,t.i18n.pluralizationRules=this.$root.$i18n.pluralizationRules),t.__i18n)try{var r={};t.__i18n.forEach(function(t){r=l(r,JSON.parse(t))}),t.i18n.messages=r}catch(t){}this._i18n=new et(t.i18n),this._i18nWatcher=this._i18n.watchI18nData(),this._i18n.subscribeDataChanging(this),this._subscribing=!0,(void 0===t.i18n.sync||t.i18n.sync)&&(this._localeWatcher=this.$i18n.watchLocale())}}else this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof et?(this._i18n=this.$root.$i18n,this._i18n.subscribeDataChanging(this),this._subscribing=!0):t.parent&&t.parent.$i18n&&t.parent.$i18n instanceof et&&(this._i18n=t.parent.$i18n,this._i18n.subscribeDataChanging(this),this._subscribing=!0)},beforeDestroy:function(){this._i18n&&(this._subscribing&&(this._i18n.unsubscribeDataChanging(this),delete this._subscribing),this._i18nWatcher&&(this._i18nWatcher(),delete this._i18nWatcher),this._localeWatcher&&(this._localeWatcher(),delete this._localeWatcher),this._i18n=null)}},j={name:"i18n",functional:!0,props:{tag:{type:String,default:"span"},path:{type:String,required:!0},locale:{type:String},places:{type:[Array,Object]}},render:function(t,e){var n=e.props,r=e.data,i=e.children,a=e.parent,o=a.$i18n;if(i=(i||[]).filter(function(t){return t.tag||(t.text=t.text.trim())}),!o)return i;var s=n.path,l=n.locale,c={},u=n.places||{},f=(Array.isArray(u)?u.length:Object.keys(u).length,i.every(function(t){if(t.data&&t.data.attrs){var e=t.data.attrs.place;return void 0!==e&&""!==e}}));return Array.isArray(u)?u.forEach(function(t,e){c[e]=t}):Object.keys(u).forEach(function(t){c[t]=u[t]}),i.forEach(function(t,e){var n=f?""+t.data.attrs.place:""+e;c[n]=t}),t(n.tag,r,o.i(s,l,c))}},N=function(){this._caches=Object.create(null)};N.prototype.interpolate=function(t,e){if(!e)return[t];var n=this._caches[t];return n||(n=b(t),this._caches[t]=n),$(n,e)};var C=/^(?:\d)+/,W=/^(?:\w)+/,I=0,R=1,S=2,V=3,z=0,P=4,E=5,U=6,J=7,q=8,G=[];G[z]={ws:[z],ident:[3,I],"[":[P],eof:[J]},G[1]={ws:[1],".":[2],"[":[P],eof:[J]},G[2]={ws:[2],ident:[3,I],0:[3,I],number:[3,I]},G[3]={ident:[3,I],0:[3,I],number:[3,I],ws:[1,R],".":[2,R],"[":[P,R],eof:[J,R]},G[P]={"'":[E,I],'"':[U,I],"[":[P,S],"]":[1,V],eof:q,else:[P,I]},G[E]={"'":[P,I],eof:q,else:[E,I]},G[U]={'"':[P,I],eof:q,else:[U,I]};var B=/^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/,H=function(){this._cache=Object.create(null)};H.prototype.parsePath=function(t){var e=this._cache[t];return e||(e=T(t))&&(this._cache[t]=e),e||[]},H.prototype.getPathValue=function(t,n){if(!e(t))return null;var r=this.parsePath(n);if(0===r.length)return null;for(var i=r.length,a=t,o=0;o<i;){var s=a[r[o]];if(void 0===s)return null;a=s,o++}return a};var K=["style","currency","currencyDisplay","useGrouping","minimumIntegerDigits","minimumFractionDigits","maximumFractionDigits","minimumSignificantDigits","maximumSignificantDigits","localeMatcher","formatMatcher"],Q=/(?:@(?:\.[a-z]+)?:(?:[\w\-_|.]+|\([\w\-_|.]+\)))/g,X=/^@(?:\.([a-z]+))?:/,Y=/[()]/g,Z={upper:function(t){return t.toLocaleUpperCase()},lower:function(t){return t.toLocaleLowerCase()}},tt=new N,et=function(t){var e=this;void 0===t&&(t={}),!D&&"undefined"!=typeof window&&window.Vue&&d(window.Vue);var n=t.locale||"en-US",i=t.fallbackLocale||"en-US",a=t.messages||{},o=t.dateTimeFormats||{},s=t.numberFormats||{};this._vm=null,this._formatter=t.formatter||tt,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._silentTranslationWarn=void 0!==t.silentTranslationWarn&&!!t.silentTranslationWarn,this._dateTimeFormatters={},this._numberFormatters={},this._path=new H,this._dataListeners=[],this.pluralizationRules=t.pluralizationRules||{},this._exist=function(t,n){return!(!t||!n)&&!r(e._path.getPathValue(t,n))},this._initVM({locale:n,fallbackLocale:i,messages:a,dateTimeFormats:o,numberFormats:s})},nt={vm:{configurable:!0},messages:{configurable:!0},dateTimeFormats:{configurable:!0},numberFormats:{configurable:!0},locale:{configurable:!0},fallbackLocale:{configurable:!0},missing:{configurable:!0},formatter:{configurable:!0},silentTranslationWarn:{configurable:!0}};et.prototype._initVM=function(t){var e=D.config.silent;D.config.silent=!0,this._vm=new D({data:t}),D.config.silent=e},et.prototype.subscribeDataChanging=function(t){this._dataListeners.push(t)},et.prototype.unsubscribeDataChanging=function(t){o(this._dataListeners,t)},et.prototype.watchI18nData=function(){var t=this;return this._vm.$watch("$data",function(){for(var e=t._dataListeners.length;e--;)D.nextTick(function(){t._dataListeners[e]&&t._dataListeners[e].$forceUpdate()})},{deep:!0})},et.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})},nt.vm.get=function(){return this._vm},nt.messages.get=function(){return a(this._getMessages())},nt.dateTimeFormats.get=function(){return a(this._getDateTimeFormats())},nt.numberFormats.get=function(){return a(this._getNumberFormats())},nt.locale.get=function(){return this._vm.locale},nt.locale.set=function(t){this._vm.$set(this._vm,"locale",t)},nt.fallbackLocale.get=function(){return this._vm.fallbackLocale},nt.fallbackLocale.set=function(t){this._vm.$set(this._vm,"fallbackLocale",t)},nt.missing.get=function(){return this._missing},nt.missing.set=function(t){this._missing=t},nt.formatter.get=function(){return this._formatter},nt.formatter.set=function(t){this._formatter=t},nt.silentTranslationWarn.get=function(){return this._silentTranslationWarn},nt.silentTranslationWarn.set=function(t){this._silentTranslationWarn=t},et.prototype._getMessages=function(){return this._vm.messages},et.prototype._getDateTimeFormats=function(){return this._vm.dateTimeFormats},et.prototype._getNumberFormats=function(){return this._vm.numberFormats},et.prototype._warnDefault=function(t,e,n,i,a){if(!r(n))return n;if(this._missing){var o=this._missing.apply(null,[t,e,i,a]);if("string"==typeof o)return o}return e},et.prototype._isFallbackRoot=function(t){return!t&&!r(this._root)&&this._fallbackRoot},et.prototype._interpolate=function(t,e,i,a,o,s,l){if(!e)return null;var c=this._path.getPathValue(e,i);if(Array.isArray(c)||n(c))return c;var u;if(r(c)){if(!n(e))return null;if("string"!=typeof(u=e[i]))return null}else{if("string"!=typeof c)return null;u=c}return(u.indexOf("@:")>=0||u.indexOf("@.")>=0)&&(u=this._link(t,e,u,a,o,s,l)),this._render(u,o,s,i)},et.prototype._link=function(t,e,n,r,i,a,o){var s=this,l=n,c=l.match(Q);for(var u in c)if(c.hasOwnProperty(u)){var f=c[u],h=f.match(X),p=h[0],m=h[1],_=f.replace(p,"").replace(Y,"");if(o.includes(_))return l;o.push(_);var g=s._interpolate(t,e,_,r,"raw"===i?"string":i,"raw"===i?void 0:a,o);if(s._isFallbackRoot(g)){if(!s._root)throw Error("unexpected error");var v=s._root.$i18n;g=v._translate(v._getMessages(),v.locale,v.fallbackLocale,_,r,i,a)}g=s._warnDefault(t,_,g,r,Array.isArray(a)?a:[a]),Z.hasOwnProperty(m)&&(g=Z[m](g)),o.pop(),l=g?l.replace(f,g):l}return l},et.prototype._render=function(t,e,n,r){var i=this._formatter.interpolate(t,n,r);return i||(i=tt.interpolate(t,n,r)),"string"===e?i.join(""):i},et.prototype._translate=function(t,e,n,i,a,o,s){var l=this._interpolate(e,t[e],i,a,o,s,[i]);return r(l)?(l=this._interpolate(n,t[n],i,a,o,s,[i]),r(l)?null:l):l},et.prototype._t=function(t,e,n,r){for(var a,o=[],s=arguments.length-4;s-- >0;)o[s]=arguments[s+4];if(!t)return"";var l=i.apply(void 0,o),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(a=this._root).$t.apply(a,[t].concat(o))}return this._warnDefault(c,t,u,r,o)},et.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))},et.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])},et.prototype.i=function(t,e,n){return t?("string"!=typeof e&&(e=this.locale),this._i(t,e,this._getMessages(),null,n)):""},et.prototype._tc=function(t,e,n,r,a){for(var o,s=[],l=arguments.length-5;l-- >0;)s[l]=arguments[l+5];if(!t)return"";void 0===a&&(a=1);var c={count:a,n:a},u=i.apply(void 0,s);return u.params=Object.assign(c,u.params),s=null===u.locale?[u.params]:[u.locale,u.params],this.fetchChoice((o=this)._t.apply(o,[t,e,n,r].concat(s)),a)},et.prototype.fetchChoice=function(t,e){if(!t&&"string"!=typeof t)return null;var n=t.split("|");return e=this.getChoiceIndex(e,n.length),n[e]?n[e].trim():t},et.prototype.getChoiceIndex=function(t,e){return this.locale in this.pluralizationRules?this.pluralizationRules[this.locale].apply(this,[t,e]):function(t,e){return t=Math.abs(t),2===e?t?t>1?1:0:1:t?Math.min(t,2):0}(t,e)},et.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))},et.prototype._te=function(t,e,n){for(var r=[],a=arguments.length-3;a-- >0;)r[a]=arguments[a+3];var o=i.apply(void 0,r).locale||e;return this._exist(n[o],t)},et.prototype.te=function(t,e){return this._te(t,this.locale,this._getMessages(),e)},et.prototype.getLocaleMessage=function(t){return a(this._vm.messages[t]||{})},et.prototype.setLocaleMessage=function(t,e){this._vm.$set(this._vm.messages,t,e)},et.prototype.mergeLocaleMessage=function(t,e){this._vm.$set(this._vm.messages,t,l(this._vm.messages[t]||{},e))},et.prototype.getDateTimeFormat=function(t){return a(this._vm.dateTimeFormats[t]||{})},et.prototype.setDateTimeFormat=function(t,e){this._vm.$set(this._vm.dateTimeFormats,t,e)},et.prototype.mergeDateTimeFormat=function(t,e){this._vm.$set(this._vm.dateTimeFormats,t,l(this._vm.dateTimeFormats[t]||{},e))},et.prototype._localizeDateTime=function(t,e,n,i,a){var o=e,s=i[o];if((r(s)||r(s[a]))&&(o=n,s=i[o]),r(s)||r(s[a]))return null;var l=s[a],c=o+"__"+a,u=this._dateTimeFormatters[c];return u||(u=this._dateTimeFormatters[c]=new Intl.DateTimeFormat(o,l)),u.format(t)},et.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||""},et.prototype.d=function(t){for(var n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];var i=this.locale,a=null;return 1===n.length?"string"==typeof n[0]?a=n[0]:e(n[0])&&(n[0].locale&&(i=n[0].locale),n[0].key&&(a=n[0].key)):2===n.length&&("string"==typeof n[0]&&(a=n[0]),"string"==typeof n[1]&&(i=n[1])),this._d(t,i,a)},et.prototype.getNumberFormat=function(t){return a(this._vm.numberFormats[t]||{})},et.prototype.setNumberFormat=function(t,e){this._vm.$set(this._vm.numberFormats,t,e)},et.prototype.mergeNumberFormat=function(t,e){this._vm.$set(this._vm.numberFormats,t,l(this._vm.numberFormats[t]||{},e))},et.prototype._localizeNumber=function(t,e,n,i,a,o){var s=e,l=i[s];if((r(l)||r(l[a]))&&(s=n,l=i[s]),r(l)||r(l[a]))return null;var c,u=l[a];if(o)c=new Intl.NumberFormat(s,Object.assign({},u,o));else{var f=s+"__"+a;c=this._numberFormatters[f],c||(c=this._numberFormatters[f]=new Intl.NumberFormat(s,u))}return c.format(t)},et.prototype._n=function(t,e,n,r){if(!et.availabilities.numberFormat)return"";if(!n){return(r?new Intl.NumberFormat(e,r):new Intl.NumberFormat(e)).format(t)}var i=this._localizeNumber(t,e,this.fallbackLocale,this._getNumberFormats(),n,r);if(this._isFallbackRoot(i)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.n(t,Object.assign({},{key:n,locale:e},r))}return i||""},et.prototype.n=function(t){for(var n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];var i=this.locale,a=null,o=null;return 1===n.length?"string"==typeof n[0]?a=n[0]:e(n[0])&&(n[0].locale&&(i=n[0].locale),n[0].key&&(a=n[0].key),o=Object.keys(n[0]).reduce(function(t,e){var r;return K.includes(e)?Object.assign({},t,(r={},r[e]=n[0][e],r)):t},null)):2===n.length&&("string"==typeof n[0]&&(a=n[0]),"string"==typeof n[1]&&(i=n[1])),this._n(t,i,a,o)},Object.defineProperties(et.prototype,nt);var rt;return Object.defineProperty(et,"availabilities",{get:function(){if(!rt){var t="undefined"!=typeof Intl;rt={dateTimeFormat:t&&void 0!==Intl.DateTimeFormat,numberFormat:t&&void 0!==Intl.NumberFormat}}return rt}}),et.install=d,et.version="8.6.0",et});
|
|
6
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueI18n=e()}(this,function(){"use strict";function t(t,e){"undefined"!=typeof console&&(console.warn("[vue-i18n] "+t),e&&console.warn(e.stack))}function e(t){return null!==t&&"object"==typeof t}function n(t){return L.call(t)===O}function r(t){return null===t||void 0===t}function i(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var r=null,i=null;return 1===t.length?e(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]),(e(t[1])||Array.isArray(t[1]))&&(i=t[1])),{locale:r,params:i}}function a(t){return JSON.parse(JSON.stringify(t))}function o(t,e){if(t.length){var n=t.indexOf(e);if(n>-1)return t.splice(n,1)}}function s(t,e){return M.call(t,e)}function c(t){for(var n=arguments,r=Object(t),i=1;i<arguments.length;i++){var a=n[i];if(void 0!==a&&null!==a){var o=void 0;for(o in a)s(a,o)&&(e(a[o])?r[o]=c(r[o],a[o]):r[o]=a[o])}}return r}function l(t,n){if(t===n)return!0;var r=e(t),i=e(n);if(!r||!i)return!r&&!i&&String(t)===String(n);try{var a=Array.isArray(t),o=Array.isArray(n);if(a&&o)return t.length===n.length&&t.every(function(t,e){return l(t,n[e])});if(a||o)return!1;var s=Object.keys(t),c=Object.keys(n);return s.length===c.length&&s.every(function(e){return l(t[e],n[e])})}catch(t){return!1}}function u(t){t.prototype.hasOwnProperty("$i18n")||Object.defineProperty(t.prototype,"$i18n",{get:function(){return this._i18n}}),t.prototype.$t=function(t){for(var e=[],n=arguments.length-1;n-- >0;)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))}}function f(t,e,n){m(t,n)&&g(t,e,n)}function h(t,e,n,r){if(m(t,n)){var i=n.context.$i18n;_(t,n)&&l(e.value,e.oldValue)&&l(t._localeMessage,i.getLocaleMessage(i.locale))||g(t,e,n)}}function p(e,n,r,i){if(!r.context)return void t("Vue instance does not exists in VNode context");var a=r.context.$i18n||{};n.modifiers.preserve||a.preserveDirectiveContent||(e.textContent=""),e._vt=void 0,delete e._vt,e._locale=void 0,delete e._locale,e._localeMessage=void 0,delete e._localeMessage}function m(e,n){var r=n.context;return r?!!r.$i18n||(t("VueI18n instance does not exists in Vue instance"),!1):(t("Vue instance doest not exists in VNode context"),!1)}function _(t,e){var n=e.context;return t._locale===n.$i18n.locale}function g(e,n,r){var i,a,o=n.value,s=v(o),c=s.path,l=s.locale,u=s.args,f=s.choice;if(!c&&!l&&!u)return void t("value type not supported");if(!c)return void t("`path` is required in v-t directive");var h=r.context;e._vt=e.textContent=f?(i=h.$i18n).tc.apply(i,[c,f].concat(y(l,u))):(a=h.$i18n).t.apply(a,[c].concat(y(l,u))),e._locale=h.$i18n.locale,e._localeMessage=h.$i18n.getLocaleMessage(h.$i18n.locale)}function v(t){var e,r,i,a;return"string"==typeof t?e=t:n(t)&&(e=t.path,r=t.locale,i=t.args,a=t.choice),{path:e,locale:r,args:i,choice:a}}function y(t,e){var r=[];return t&&r.push(t),e&&(Array.isArray(e)||n(e))&&r.push(e),r}function d(t){d.installed=!0,T=t;T.version&&Number(T.version.split(".")[0]);u(T),T.mixin(A),T.directive("t",{bind:f,update:h,unbind:p}),T.component(C.name,C),T.config.optionMergeStrategies.i18n=function(t,e){return void 0===e?t:e}}function b(t){for(var e=[],n=0,r="";n<t.length;){var i=t[n++];if("{"===i){r&&e.push({type:"text",value:r}),r="";var a="";for(i=t[n++];void 0!==i&&"}"!==i;)a+=i,i=t[n++];var o="}"===i,s=N.test(a)?"list":o&&W.test(a)?"named":"unknown";e.push({value:a,type:s})}else"%"===i?"{"!==t[n]&&(r+=i):r+=i}return r&&e.push({type:"text",value:r}),e}function $(t,n){var r=[],i=0,a=Array.isArray(n)?"list":e(n)?"named":"unknown";if("unknown"===a)return r;for(;i<t.length;){var o=t[i];switch(o.type){case"text":r.push(o.value);break;case"list":r.push(n[parseInt(o.value,10)]);break;case"named":"named"===a&&r.push(n[o.value])}i++}return r}function w(t){return B.test(t)}function F(t){var e=t.charCodeAt(0);return e!==t.charCodeAt(t.length-1)||34!==e&&39!==e?t:t.slice(1,-1)}function k(t){if(void 0===t||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 32:case 9:case 10:case 13:case 160:case 65279:case 8232:case 8233:return"ws"}return"ident"}function D(t){var e=t.trim();return("0"!==t.charAt(0)||!isNaN(t))&&(w(e)?F(e):"*"+e)}function x(t){var e,n,r,i,a,o,s,c=[],l=-1,u=z,f=0,h=[];for(h[R]=function(){void 0!==n&&(c.push(n),n=void 0)},h[I]=function(){void 0===n?n=r:n+=r},h[S]=function(){h[I](),f++},h[V]=function(){if(f>0)f--,u=P,h[I]();else{if(f=0,!1===(n=D(n)))return!1;h[R]()}};null!==u;)if(l++,"\\"!==(e=t[l])||!function(){var e=t[l+1];if(u===E&&"'"===e||u===U&&'"'===e)return l++,r="\\"+e,h[I](),!0}()){if(i=k(e),s=G[u],(a=s[i]||s.else||q)===q)return;if(u=a[0],(o=h[a[1]])&&(r=a[2],r=void 0===r?e:r,!1===o()))return;if(u===J)return c}}var T,L=Object.prototype.toString,O="[object Object]",M=Object.prototype.hasOwnProperty,A={beforeCreate:function(){var t=this.$options;if(t.i18n=t.i18n||(t.__i18n?{}:null),t.i18n){if(t.i18n instanceof et){if(t.__i18n)try{var e={};t.__i18n.forEach(function(t){e=c(e,JSON.parse(t))}),Object.keys(e).forEach(function(n){t.i18n.mergeLocaleMessage(n,e[n])})}catch(t){}this._i18n=t.i18n,this._i18nWatcher=this._i18n.watchI18nData(),this._i18n.subscribeDataChanging(this),this._subscribing=!0}else if(n(t.i18n)){if(this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof et&&(t.i18n.root=this.$root,t.i18n.formatter=this.$root.$i18n.formatter,t.i18n.fallbackLocale=this.$root.$i18n.fallbackLocale,t.i18n.silentTranslationWarn=this.$root.$i18n.silentTranslationWarn,t.i18n.pluralizationRules=this.$root.$i18n.pluralizationRules,t.i18n.preserveDirectiveContent=this.$root.$i18n.preserveDirectiveContent),t.__i18n)try{var r={};t.__i18n.forEach(function(t){r=c(r,JSON.parse(t))}),t.i18n.messages=r}catch(t){}this._i18n=new et(t.i18n),this._i18nWatcher=this._i18n.watchI18nData(),this._i18n.subscribeDataChanging(this),this._subscribing=!0,(void 0===t.i18n.sync||t.i18n.sync)&&(this._localeWatcher=this.$i18n.watchLocale())}}else this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof et?(this._i18n=this.$root.$i18n,this._i18n.subscribeDataChanging(this),this._subscribing=!0):t.parent&&t.parent.$i18n&&t.parent.$i18n instanceof et&&(this._i18n=t.parent.$i18n,this._i18n.subscribeDataChanging(this),this._subscribing=!0)},beforeDestroy:function(){this._i18n&&(this._subscribing&&(this._i18n.unsubscribeDataChanging(this),delete this._subscribing),this._i18nWatcher&&(this._i18nWatcher(),delete this._i18nWatcher),this._localeWatcher&&(this._localeWatcher(),delete this._localeWatcher),this._i18n=null)}},C={name:"i18n",functional:!0,props:{tag:{type:String,default:"span"},path:{type:String,required:!0},locale:{type:String},places:{type:[Array,Object]}},render:function(t,e){var n=e.props,r=e.data,i=e.children,a=e.parent,o=a.$i18n;if(i=(i||[]).filter(function(t){return t.tag||(t.text=t.text.trim())}),!o)return i;var s=n.path,c=n.locale,l={},u=n.places||{},f=(Array.isArray(u)?u.length:Object.keys(u).length,i.every(function(t){if(t.data&&t.data.attrs){var e=t.data.attrs.place;return void 0!==e&&""!==e}}));return Array.isArray(u)?u.forEach(function(t,e){l[e]=t}):Object.keys(u).forEach(function(t){l[t]=u[t]}),i.forEach(function(t,e){var n=f?""+t.data.attrs.place:""+e;l[n]=t}),t(n.tag,r,o.i(s,c,l))}},j=function(){this._caches=Object.create(null)};j.prototype.interpolate=function(t,e){if(!e)return[t];var n=this._caches[t];return n||(n=b(t),this._caches[t]=n),$(n,e)};var N=/^(?:\d)+/,W=/^(?:\w)+/,I=0,R=1,S=2,V=3,z=0,P=4,E=5,U=6,J=7,q=8,G=[];G[z]={ws:[z],ident:[3,I],"[":[P],eof:[J]},G[1]={ws:[1],".":[2],"[":[P],eof:[J]},G[2]={ws:[2],ident:[3,I],0:[3,I],number:[3,I]},G[3]={ident:[3,I],0:[3,I],number:[3,I],ws:[1,R],".":[2,R],"[":[P,R],eof:[J,R]},G[P]={"'":[E,I],'"':[U,I],"[":[P,S],"]":[1,V],eof:q,else:[P,I]},G[E]={"'":[P,I],eof:q,else:[E,I]},G[U]={'"':[P,I],eof:q,else:[U,I]};var B=/^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/,H=function(){this._cache=Object.create(null)};H.prototype.parsePath=function(t){var e=this._cache[t];return e||(e=x(t))&&(this._cache[t]=e),e||[]},H.prototype.getPathValue=function(t,n){if(!e(t))return null;var r=this.parsePath(n);if(0===r.length)return null;for(var i=r.length,a=t,o=0;o<i;){var s=a[r[o]];if(void 0===s)return null;a=s,o++}return a};var K=["style","currency","currencyDisplay","useGrouping","minimumIntegerDigits","minimumFractionDigits","maximumFractionDigits","minimumSignificantDigits","maximumSignificantDigits","localeMatcher","formatMatcher"],Q=/(?:@(?:\.[a-z]+)?:(?:[\w\-_|.]+|\([\w\-_|.]+\)))/g,X=/^@(?:\.([a-z]+))?:/,Y=/[()]/g,Z={upper:function(t){return t.toLocaleUpperCase()},lower:function(t){return t.toLocaleLowerCase()}},tt=new j,et=function(t){var e=this;void 0===t&&(t={}),!T&&"undefined"!=typeof window&&window.Vue&&d(window.Vue);var n=t.locale||"en-US",i=t.fallbackLocale||"en-US",a=t.messages||{},o=t.dateTimeFormats||{},s=t.numberFormats||{};this._vm=null,this._formatter=t.formatter||tt,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._silentTranslationWarn=void 0!==t.silentTranslationWarn&&!!t.silentTranslationWarn,this._dateTimeFormatters={},this._numberFormatters={},this._path=new H,this._dataListeners=[],this.pluralizationRules=t.pluralizationRules||{},this.preserveDirectiveContent=void 0!==t.preserveDirectiveContent&&!!t.preserveDirectiveContent,this._exist=function(t,n){return!(!t||!n)&&!r(e._path.getPathValue(t,n))},this._initVM({locale:n,fallbackLocale:i,messages:a,dateTimeFormats:o,numberFormats:s})},nt={vm:{configurable:!0},messages:{configurable:!0},dateTimeFormats:{configurable:!0},numberFormats:{configurable:!0},locale:{configurable:!0},fallbackLocale:{configurable:!0},missing:{configurable:!0},formatter:{configurable:!0},silentTranslationWarn:{configurable:!0}};et.prototype._initVM=function(t){var e=T.config.silent;T.config.silent=!0,this._vm=new T({data:t}),T.config.silent=e},et.prototype.subscribeDataChanging=function(t){this._dataListeners.push(t)},et.prototype.unsubscribeDataChanging=function(t){o(this._dataListeners,t)},et.prototype.watchI18nData=function(){var t=this;return this._vm.$watch("$data",function(){for(var e=t._dataListeners.length;e--;)T.nextTick(function(){t._dataListeners[e]&&t._dataListeners[e].$forceUpdate()})},{deep:!0})},et.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})},nt.vm.get=function(){return this._vm},nt.messages.get=function(){return a(this._getMessages())},nt.dateTimeFormats.get=function(){return a(this._getDateTimeFormats())},nt.numberFormats.get=function(){return a(this._getNumberFormats())},nt.locale.get=function(){return this._vm.locale},nt.locale.set=function(t){this._vm.$set(this._vm,"locale",t)},nt.fallbackLocale.get=function(){return this._vm.fallbackLocale},nt.fallbackLocale.set=function(t){this._vm.$set(this._vm,"fallbackLocale",t)},nt.missing.get=function(){return this._missing},nt.missing.set=function(t){this._missing=t},nt.formatter.get=function(){return this._formatter},nt.formatter.set=function(t){this._formatter=t},nt.silentTranslationWarn.get=function(){return this._silentTranslationWarn},nt.silentTranslationWarn.set=function(t){this._silentTranslationWarn=t},et.prototype._getMessages=function(){return this._vm.messages},et.prototype._getDateTimeFormats=function(){return this._vm.dateTimeFormats},et.prototype._getNumberFormats=function(){return this._vm.numberFormats},et.prototype._warnDefault=function(t,e,n,i,a){if(!r(n))return n;if(this._missing){var o=this._missing.apply(null,[t,e,i,a]);if("string"==typeof o)return o}return e},et.prototype._isFallbackRoot=function(t){return!t&&!r(this._root)&&this._fallbackRoot},et.prototype._interpolate=function(t,e,i,a,o,s,c){if(!e)return null;var l=this._path.getPathValue(e,i);if(Array.isArray(l)||n(l))return l;var u;if(r(l)){if(!n(e))return null;if("string"!=typeof(u=e[i]))return null}else{if("string"!=typeof l)return null;u=l}return(u.indexOf("@:")>=0||u.indexOf("@.")>=0)&&(u=this._link(t,e,u,a,o,s,c)),this._render(u,o,s,i)},et.prototype._link=function(t,e,n,r,i,a,o){var s=this,c=n,l=c.match(Q);for(var u in l)if(l.hasOwnProperty(u)){var f=l[u],h=f.match(X),p=h[0],m=h[1],_=f.replace(p,"").replace(Y,"");if(o.includes(_))return c;o.push(_);var g=s._interpolate(t,e,_,r,"raw"===i?"string":i,"raw"===i?void 0:a,o);if(s._isFallbackRoot(g)){if(!s._root)throw Error("unexpected error");var v=s._root.$i18n;g=v._translate(v._getMessages(),v.locale,v.fallbackLocale,_,r,i,a)}g=s._warnDefault(t,_,g,r,Array.isArray(a)?a:[a]),Z.hasOwnProperty(m)&&(g=Z[m](g)),o.pop(),c=g?c.replace(f,g):c}return c},et.prototype._render=function(t,e,n,r){var i=this._formatter.interpolate(t,n,r);return i||(i=tt.interpolate(t,n,r)),"string"===e?i.join(""):i},et.prototype._translate=function(t,e,n,i,a,o,s){var c=this._interpolate(e,t[e],i,a,o,s,[i]);return r(c)?(c=this._interpolate(n,t[n],i,a,o,s,[i]),r(c)?null:c):c},et.prototype._t=function(t,e,n,r){for(var a,o=[],s=arguments.length-4;s-- >0;)o[s]=arguments[s+4];if(!t)return"";var c=i.apply(void 0,o),l=c.locale||e,u=this._translate(n,l,this.fallbackLocale,t,r,"string",c.params);if(this._isFallbackRoot(u)){if(!this._root)throw Error("unexpected error");return(a=this._root).$t.apply(a,[t].concat(o))}return this._warnDefault(l,t,u,r,o)},et.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))},et.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])},et.prototype.i=function(t,e,n){return t?("string"!=typeof e&&(e=this.locale),this._i(t,e,this._getMessages(),null,n)):""},et.prototype._tc=function(t,e,n,r,a){for(var o,s=[],c=arguments.length-5;c-- >0;)s[c]=arguments[c+5];if(!t)return"";void 0===a&&(a=1);var l={count:a,n:a},u=i.apply(void 0,s);return u.params=Object.assign(l,u.params),s=null===u.locale?[u.params]:[u.locale,u.params],this.fetchChoice((o=this)._t.apply(o,[t,e,n,r].concat(s)),a)},et.prototype.fetchChoice=function(t,e){if(!t&&"string"!=typeof t)return null;var n=t.split("|");return e=this.getChoiceIndex(e,n.length),n[e]?n[e].trim():t},et.prototype.getChoiceIndex=function(t,e){return this.locale in this.pluralizationRules?this.pluralizationRules[this.locale].apply(this,[t,e]):function(t,e){return t=Math.abs(t),2===e?t?t>1?1:0:1:t?Math.min(t,2):0}(t,e)},et.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))},et.prototype._te=function(t,e,n){for(var r=[],a=arguments.length-3;a-- >0;)r[a]=arguments[a+3];var o=i.apply(void 0,r).locale||e;return this._exist(n[o],t)},et.prototype.te=function(t,e){return this._te(t,this.locale,this._getMessages(),e)},et.prototype.getLocaleMessage=function(t){return a(this._vm.messages[t]||{})},et.prototype.setLocaleMessage=function(t,e){this._vm.$set(this._vm.messages,t,e)},et.prototype.mergeLocaleMessage=function(t,e){this._vm.$set(this._vm.messages,t,c(this._vm.messages[t]||{},e))},et.prototype.getDateTimeFormat=function(t){return a(this._vm.dateTimeFormats[t]||{})},et.prototype.setDateTimeFormat=function(t,e){this._vm.$set(this._vm.dateTimeFormats,t,e)},et.prototype.mergeDateTimeFormat=function(t,e){this._vm.$set(this._vm.dateTimeFormats,t,c(this._vm.dateTimeFormats[t]||{},e))},et.prototype._localizeDateTime=function(t,e,n,i,a){var o=e,s=i[o];if((r(s)||r(s[a]))&&(o=n,s=i[o]),r(s)||r(s[a]))return null;var c=s[a],l=o+"__"+a,u=this._dateTimeFormatters[l];return u||(u=this._dateTimeFormatters[l]=new Intl.DateTimeFormat(o,c)),u.format(t)},et.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||""},et.prototype.d=function(t){for(var n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];var i=this.locale,a=null;return 1===n.length?"string"==typeof n[0]?a=n[0]:e(n[0])&&(n[0].locale&&(i=n[0].locale),n[0].key&&(a=n[0].key)):2===n.length&&("string"==typeof n[0]&&(a=n[0]),"string"==typeof n[1]&&(i=n[1])),this._d(t,i,a)},et.prototype.getNumberFormat=function(t){return a(this._vm.numberFormats[t]||{})},et.prototype.setNumberFormat=function(t,e){this._vm.$set(this._vm.numberFormats,t,e)},et.prototype.mergeNumberFormat=function(t,e){this._vm.$set(this._vm.numberFormats,t,c(this._vm.numberFormats[t]||{},e))},et.prototype._localizeNumber=function(t,e,n,i,a,o){var s=e,c=i[s];if((r(c)||r(c[a]))&&(s=n,c=i[s]),r(c)||r(c[a]))return null;var l,u=c[a];if(o)l=new Intl.NumberFormat(s,Object.assign({},u,o));else{var f=s+"__"+a;l=this._numberFormatters[f],l||(l=this._numberFormatters[f]=new Intl.NumberFormat(s,u))}return l.format(t)},et.prototype._n=function(t,e,n,r){if(!et.availabilities.numberFormat)return"";if(!n){return(r?new Intl.NumberFormat(e,r):new Intl.NumberFormat(e)).format(t)}var i=this._localizeNumber(t,e,this.fallbackLocale,this._getNumberFormats(),n,r);if(this._isFallbackRoot(i)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.n(t,Object.assign({},{key:n,locale:e},r))}return i||""},et.prototype.n=function(t){for(var n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];var i=this.locale,a=null,o=null;return 1===n.length?"string"==typeof n[0]?a=n[0]:e(n[0])&&(n[0].locale&&(i=n[0].locale),n[0].key&&(a=n[0].key),o=Object.keys(n[0]).reduce(function(t,e){var r;return K.includes(e)?Object.assign({},t,(r={},r[e]=n[0][e],r)):t},null)):2===n.length&&("string"==typeof n[0]&&(a=n[0]),"string"==typeof n[1]&&(i=n[1])),this._n(t,i,a,o)},Object.defineProperties(et.prototype,nt);var rt;return Object.defineProperty(et,"availabilities",{get:function(){if(!rt){var t="undefined"!=typeof Intl;rt={dateTimeFormat:t&&void 0!==Intl.DateTimeFormat,numberFormat:t&&void 0!==Intl.NumberFormat}}return rt}}),et.install=d,et.version="8.7.0",et});
|
package/package.json
CHANGED
package/src/directive.js
CHANGED
|
@@ -26,7 +26,10 @@ export function unbind (el: any, binding: Object, vnode: any, oldVNode: any): vo
|
|
|
26
26
|
return
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
const i18n: any = vnode.context.$i18n || {}
|
|
30
|
+
if (!binding.modifiers.preserve && !i18n.preserveDirectiveContent) {
|
|
31
|
+
el.textContent = ''
|
|
32
|
+
}
|
|
30
33
|
el._vt = undefined
|
|
31
34
|
delete el['_vt']
|
|
32
35
|
el._locale = undefined
|
package/src/index.js
CHANGED
|
@@ -61,6 +61,7 @@ export default class VueI18n {
|
|
|
61
61
|
pluralizationRules: {
|
|
62
62
|
[lang: string]: (choice: number, choicesLength: number) => number
|
|
63
63
|
}
|
|
64
|
+
preserveDirectiveContent: boolean
|
|
64
65
|
|
|
65
66
|
constructor (options: I18nOptions = {}) {
|
|
66
67
|
// Auto install if it is not done yet and `window` has `Vue`.
|
|
@@ -94,6 +95,9 @@ export default class VueI18n {
|
|
|
94
95
|
this._dataListeners = []
|
|
95
96
|
|
|
96
97
|
this.pluralizationRules = options.pluralizationRules || {}
|
|
98
|
+
this.preserveDirectiveContent = options.preserveDirectiveContent === undefined
|
|
99
|
+
? false
|
|
100
|
+
: !!options.preserveDirectiveContent
|
|
97
101
|
|
|
98
102
|
this._exist = (message: Object, key: Path): boolean => {
|
|
99
103
|
if (!message || !key) { return false }
|
package/src/mixin.js
CHANGED
|
@@ -38,6 +38,7 @@ export default {
|
|
|
38
38
|
options.i18n.fallbackLocale = this.$root.$i18n.fallbackLocale
|
|
39
39
|
options.i18n.silentTranslationWarn = this.$root.$i18n.silentTranslationWarn
|
|
40
40
|
options.i18n.pluralizationRules = this.$root.$i18n.pluralizationRules
|
|
41
|
+
options.i18n.preserveDirectiveContent = this.$root.$i18n.preserveDirectiveContent
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
// init locale messages via custom blocks
|
package/types/index.d.ts
CHANGED
|
@@ -93,6 +93,7 @@ declare namespace VueI18n {
|
|
|
93
93
|
sync?: boolean;
|
|
94
94
|
silentTranslationWarn?: boolean;
|
|
95
95
|
pluralizationRules?: PluralizationRulesMap;
|
|
96
|
+
preserveDirectiveContent?: boolean;
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
|
|
@@ -129,6 +130,7 @@ export declare interface IVueI18n {
|
|
|
129
130
|
formatter: VueI18n.Formatter;
|
|
130
131
|
silentTranslationWarn: boolean;
|
|
131
132
|
pluralizationRules: VueI18n.PluralizationRulesMap;
|
|
133
|
+
preserveDirectiveContent: boolean;
|
|
132
134
|
}
|
|
133
135
|
|
|
134
136
|
declare class VueI18n {
|