From e1e43a27e7bd24974de7ce8df692e3fb6a3eb05a Mon Sep 17 00:00:00 2001 From: kemar Date: Tue, 25 Jul 2017 18:09:08 +0200 Subject: [PATCH] [build] 2.0.20 --- dist/vue-gettext.js | 26 +++++++++++++++++++++++--- dist/vue-gettext.min.js | 4 ++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/dist/vue-gettext.js b/dist/vue-gettext.js index dda30ac..5f0fb0c 100644 --- a/dist/vue-gettext.js +++ b/dist/vue-gettext.js @@ -1,5 +1,5 @@ /** - * vue-gettext v2.0.19 + * vue-gettext v2.0.20 * (c) 2017 Polyconseil * @license MIT */ @@ -381,6 +381,10 @@ var Component = { type: String, required: false, }, + translateParams: { + type: Object, + required: false, + }, // `translateComment` is used exclusively by `easygettext`'s `gettext-extract`. translateComment: { type: String, @@ -397,7 +401,14 @@ var Component = { this.isPlural ? this.translatePlural : null, this.$language.current ); - return this.$gettextInterpolate(translation, this.$parent) + + var context = this.$parent; + + if (this.translateParams) { + context = Object.assign({}, this.$parent, this.translateParams); + } + + return this.$gettextInterpolate(translation, context) }, }, @@ -503,11 +514,20 @@ var updateTranslation = function (el, binding, vnode) { var translateN = attrs['translate-n']; var translatePlural = attrs['translate-plural']; var isPlural = translateN !== undefined && translatePlural !== undefined; + var context = vnode.context; if (!isPlural && (translateN || translatePlural)) { throw new Error('`translate-n` and `translate-plural` attributes must be used together:' + msgid + '.') } + if (!_Vue.config.getTextPluginSilent && attrs['translate-params']) { + console.warn(("`translate-params` is required as an expression for v-translate directive. Please change to `v-translate='params'`: " + msgid)); + } + + if (binding.value && typeof binding.value === 'object') { + context = Object.assign({}, vnode.context, binding.value); + } + var translation = translate.getTranslation( msgid, translateN, @@ -516,7 +536,7 @@ var updateTranslation = function (el, binding, vnode) { el.dataset.currentLanguage ); - var msg = interpolate(translation, vnode.context); + var msg = interpolate(translation, context); el.innerHTML = msg; diff --git a/dist/vue-gettext.min.js b/dist/vue-gettext.min.js index fc6033e..8674de8 100644 --- a/dist/vue-gettext.min.js +++ b/dist/vue-gettext.min.js @@ -1,6 +1,6 @@ /** - * vue-gettext v2.0.19 + * vue-gettext v2.0.20 * (c) 2017 Polyconseil * @license MIT */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueGettext=t()}(this,function(){"use strict";function shareVueInstance(e){_Vue=e}function uuid(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}var plurals={getTranslationIndex:function(e,t){switch(t=Number.isNaN(parseInt(t))?1:parseInt(t),e.length>2&&"pt_BR"!==e&&(e=e.split("_")[0]),e){case"ay":case"bo":case"cgg":case"dz":case"fa":case"id":case"ja":case"jbo":case"ka":case"kk":case"km":case"ko":case"ky":case"lo":case"ms":case"my":case"sah":case"su":case"th":case"tt":case"ug":case"vi":case"wo":case"zh":return 0;case"is":return t%10!==1||t%100===11?1:0;case"jv":return 0!==t?1:0;case"mk":return 1===t||t%10===1?0:1;case"ach":case"ak":case"am":case"arn":case"br":case"fil":case"fr":case"gun":case"ln":case"mfe":case"mg":case"mi":case"oc":case"pt_BR":case"tg":case"ti":case"tr":case"uz":case"wa":case"zh":return t>1?1:0;case"lv":return t%10===1&&t%100!==11?0:0!==t?1:2;case"lt":return t%10===1&&t%100!==11?0:t%10>=2&&(t%100<10||t%100>=20)?1:2;case"be":case"bs":case"hr":case"ru":case"sr":case"uk":return t%10===1&&t%100!==11?0:t%10>=2&&t%10<=4&&(t%100<10||t%100>=20)?1:2;case"mnk":return 0===t?0:1===t?1:2;case"ro":return 1===t?0:0===t||t%100>0&&t%100<20?1:2;case"pl":return 1===t?0:t%10>=2&&t%10<=4&&(t%100<10||t%100>=20)?1:2;case"cs":case"sk":return 1===t?0:t>=2&&t<=4?1:2;case"csb":return 1===t?0:t%10>=2&&t%10<=4&&(t%100<10||t%100>=20)?1:2;case"sl":return t%100===1?0:t%100===2?1:t%100===3||t%100===4?2:3;case"mt":return 1===t?0:0===t||t%100>1&&t%100<11?1:t%100>10&&t%100<20?2:3;case"gd":return 1===t||11===t?0:2===t||12===t?1:t>2&&t<20?2:3;case"cy":return 1===t?0:2===t?1:8!==t&&11!==t?2:3;case"kw":return 1===t?0:2===t?1:3===t?2:3;case"ga":return 1===t?0:2===t?1:t>2&&t<7?2:t>6&&t<11?3:4;case"ar":return 0===t?0:1===t?1:2===t?2:t%100>=3&&t%100<=10?3:t%100>=11?4:5;default:return 1!==t?1:0}}},_Vue,translate={getTranslation:function(e,t,n,a,r){if(void 0===t&&(t=1),void 0===n&&(n=null),void 0===a&&(a=null),void 0===r&&(r=_Vue.config.language),!e)return"";var s=_Vue.$translations[r]||_Vue.$translations[r.split("_")[0]];if(!s)return _Vue.config.getTextPluginSilent||console.warn("No translations found for "+r),a&&plurals.getTranslationIndex(r,t)>0?a:e;var i=s[e];return!i&&/\s{2,}/g.test(e)&&Object.keys(s).some(function(t){if(t.replace(/\s{2,}/g," ")===e.replace(/\s{2,}/g," "))return i=s[t]}),i?(n&&(i=i[n]),"string"==typeof i&&(i=[i]),i instanceof Array||!i.hasOwnProperty("")||(i=[i[""]]),i[plurals.getTranslationIndex(r,t)]):(_Vue.config.getTextPluginSilent||console.warn("Untranslated "+r+" key found:\n"+e),a&&plurals.getTranslationIndex(r,t)>0?a:e)},gettext:function(e){return this.getTranslation(e)},pgettext:function(e,t){return this.getTranslation(t,1,e)},ngettext:function(e,t,n){return this.getTranslation(e,n,null,t)},npgettext:function(e,t,n,a){return this.getTranslation(t,a,e,n)}},Component={name:"translate",created:function(){if(this.msgid="",this.$options._renderChildren&&(this.$options._renderChildren[0].hasOwnProperty("text")?this.msgid=this.$options._renderChildren[0].text.trim():this.msgid=this.$options._renderChildren[0].trim()),this.isPlural=void 0!==this.translateN&&void 0!==this.translatePlural,!this.isPlural&&(this.translateN||this.translatePlural))throw new Error("`translate-n` and `translate-plural` attributes must be used together: "+this.msgid+".")},props:{tag:{type:String,default:"span"},translateN:{type:Number,required:!1},translatePlural:{type:String,required:!1},translateContext:{type:String,required:!1},translateComment:{type:String,required:!1}},computed:{translation:function(){var e=translate.getTranslation(this.msgid,this.translateN,this.translateContext,this.isPlural?this.translatePlural:null,this.$language.current);return this.$gettextInterpolate(e,this.$parent)}},render:function(e){return this.$vnode.key||(this.$vnode.key=uuid()),e(this.tag,[this.translation])}},INTERPOLATION_RE=/%\{((?:.|\n)+?)\}/g,MUSTACHE_SYNTAX_RE=/\{\{((?:.|\n)+?)\}\}/g,interpolate=function(msgid,context){void 0===context&&(context={}),!_Vue.config.getTextPluginSilent&&MUSTACHE_SYNTAX_RE.test(msgid)&&console.warn('Mustache syntax cannot be used with vue-gettext. Please use "%{}" instead of "{{}}" in: '+msgid);var result=msgid.replace(INTERPOLATION_RE,function(match,token){function evalInContext(expression){try{evaluated=eval("this."+expression)}catch(e){}if(void 0===evaluated){if(this.$parent)return evalInContext.call(this.$parent,expression);console.warn("Cannot evaluate expression: "+expression),evaluated=expression}return evaluated}var expression=token.trim(),evaluated;return evalInContext.call(context,expression)});return result};interpolate.INTERPOLATION_RE=INTERPOLATION_RE,interpolate.INTERPOLATION_PREFIX="%{";var updateTranslation=function(e,t,n){var a=n.data.attrs||{},r=e.dataset.msgid,s=a["translate-context"],i=a["translate-n"],o=a["translate-plural"],l=void 0!==i&&void 0!==o;if(!l&&(i||o))throw new Error("`translate-n` and `translate-plural` attributes must be used together:"+r+".");var u=translate.getTranslation(r,i,s,l?o:null,e.dataset.currentLanguage),c=interpolate(u,n.context);e.innerHTML=c},Directive={bind:function(e,t,n){n.key||(n.key=uuid());var a=e.innerHTML;if(e.dataset.msgid=a,e.dataset.currentLanguage=_Vue.config.language,!_Vue.config.getTextPluginSilent){var r=a.indexOf(interpolate.INTERPOLATION_PREFIX)!==-1;r&&!t.expression&&console.info("No expression is provided for change detection. The translation for this key will be static:\n"+a)}updateTranslation(e,t,n)},update:function(e,t,n){var a=!1;e.dataset.currentLanguage!==_Vue.config.language&&(e.dataset.currentLanguage=_Vue.config.language,a=!0),!a&&t.expression&&t.value!==t.oldValue&&(a=!0),a&&updateTranslation(e,t,n)}},Config=function(e,t,n){Object.defineProperty(e.config,"language",{enumerable:!0,configurable:!0,get:function(){return t.current},set:function(e){t.current=e}}),Object.defineProperty(e.config,"getTextPluginSilent",{enumerable:!0,writable:!0,value:n})},Override=function(e,t){var n=e.prototype._init;e.prototype._init=function(e){void 0===e&&(e={});var a=e._parent||e.parent||this;this.$language=a.$language||t,n.call(this,e)};var a=e.prototype._destroy;e.prototype._destroy=function(){this.$language=null,a.apply(this,arguments)}},languageVm,GetTextPlugin=function(e,t){void 0===t&&(t={});var n={availableLanguages:{en_US:"English"},defaultLanguage:"en_US",languageVmMixin:{},silent:e.config.silent,translations:null};if(Object.keys(t).forEach(function(e){if(Object.keys(n).indexOf(e)===-1)throw new Error(e+" is an invalid option for the translate plugin.")}),!t.translations)throw new Error("No translations available.");t=Object.assign(n,t),languageVm=new e({created:function(){this.available=t.availableLanguages},data:{current:t.defaultLanguage},mixins:[t.languageVmMixin]}),shareVueInstance(e),Override(e,languageVm),Config(e,languageVm,t.silent),e.component("translate",Component),e.directive("translate",Directive),e.$translations=t.translations,e.prototype.$gettext=translate.gettext.bind(translate),e.prototype.$pgettext=translate.pgettext.bind(translate),e.prototype.$ngettext=translate.ngettext.bind(translate),e.prototype.$npgettext=translate.npgettext.bind(translate),e.prototype.$gettextInterpolate=interpolate.bind(interpolate)};return GetTextPlugin}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueGettext=t()}(this,function(){"use strict";function shareVueInstance(e){_Vue=e}function uuid(){var e,t,a="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(a+="-"),a+=(12===e?4:16===e?3&t|8:t).toString(16);return a}var plurals={getTranslationIndex:function(e,t){switch(t=Number.isNaN(parseInt(t))?1:parseInt(t),e.length>2&&"pt_BR"!==e&&(e=e.split("_")[0]),e){case"ay":case"bo":case"cgg":case"dz":case"fa":case"id":case"ja":case"jbo":case"ka":case"kk":case"km":case"ko":case"ky":case"lo":case"ms":case"my":case"sah":case"su":case"th":case"tt":case"ug":case"vi":case"wo":case"zh":return 0;case"is":return t%10!==1||t%100===11?1:0;case"jv":return 0!==t?1:0;case"mk":return 1===t||t%10===1?0:1;case"ach":case"ak":case"am":case"arn":case"br":case"fil":case"fr":case"gun":case"ln":case"mfe":case"mg":case"mi":case"oc":case"pt_BR":case"tg":case"ti":case"tr":case"uz":case"wa":case"zh":return t>1?1:0;case"lv":return t%10===1&&t%100!==11?0:0!==t?1:2;case"lt":return t%10===1&&t%100!==11?0:t%10>=2&&(t%100<10||t%100>=20)?1:2;case"be":case"bs":case"hr":case"ru":case"sr":case"uk":return t%10===1&&t%100!==11?0:t%10>=2&&t%10<=4&&(t%100<10||t%100>=20)?1:2;case"mnk":return 0===t?0:1===t?1:2;case"ro":return 1===t?0:0===t||t%100>0&&t%100<20?1:2;case"pl":return 1===t?0:t%10>=2&&t%10<=4&&(t%100<10||t%100>=20)?1:2;case"cs":case"sk":return 1===t?0:t>=2&&t<=4?1:2;case"csb":return 1===t?0:t%10>=2&&t%10<=4&&(t%100<10||t%100>=20)?1:2;case"sl":return t%100===1?0:t%100===2?1:t%100===3||t%100===4?2:3;case"mt":return 1===t?0:0===t||t%100>1&&t%100<11?1:t%100>10&&t%100<20?2:3;case"gd":return 1===t||11===t?0:2===t||12===t?1:t>2&&t<20?2:3;case"cy":return 1===t?0:2===t?1:8!==t&&11!==t?2:3;case"kw":return 1===t?0:2===t?1:3===t?2:3;case"ga":return 1===t?0:2===t?1:t>2&&t<7?2:t>6&&t<11?3:4;case"ar":return 0===t?0:1===t?1:2===t?2:t%100>=3&&t%100<=10?3:t%100>=11?4:5;default:return 1!==t?1:0}}},_Vue,translate={getTranslation:function(e,t,a,n,r){if(void 0===t&&(t=1),void 0===a&&(a=null),void 0===n&&(n=null),void 0===r&&(r=_Vue.config.language),!e)return"";var s=_Vue.$translations[r]||_Vue.$translations[r.split("_")[0]];if(!s)return _Vue.config.getTextPluginSilent||console.warn("No translations found for "+r),n&&plurals.getTranslationIndex(r,t)>0?n:e;var i=s[e];return!i&&/\s{2,}/g.test(e)&&Object.keys(s).some(function(t){if(t.replace(/\s{2,}/g," ")===e.replace(/\s{2,}/g," "))return i=s[t]}),i?(a&&(i=i[a]),"string"==typeof i&&(i=[i]),i instanceof Array||!i.hasOwnProperty("")||(i=[i[""]]),i[plurals.getTranslationIndex(r,t)]):(_Vue.config.getTextPluginSilent||console.warn("Untranslated "+r+" key found:\n"+e),n&&plurals.getTranslationIndex(r,t)>0?n:e)},gettext:function(e){return this.getTranslation(e)},pgettext:function(e,t){return this.getTranslation(t,1,e)},ngettext:function(e,t,a){return this.getTranslation(e,a,null,t)},npgettext:function(e,t,a,n){return this.getTranslation(t,n,e,a)}},Component={name:"translate",created:function(){if(this.msgid="",this.$options._renderChildren&&(this.$options._renderChildren[0].hasOwnProperty("text")?this.msgid=this.$options._renderChildren[0].text.trim():this.msgid=this.$options._renderChildren[0].trim()),this.isPlural=void 0!==this.translateN&&void 0!==this.translatePlural,!this.isPlural&&(this.translateN||this.translatePlural))throw new Error("`translate-n` and `translate-plural` attributes must be used together: "+this.msgid+".")},props:{tag:{type:String,default:"span"},translateN:{type:Number,required:!1},translatePlural:{type:String,required:!1},translateContext:{type:String,required:!1},translateParams:{type:Object,required:!1},translateComment:{type:String,required:!1}},computed:{translation:function(){var e=translate.getTranslation(this.msgid,this.translateN,this.translateContext,this.isPlural?this.translatePlural:null,this.$language.current),t=this.$parent;return this.translateParams&&(t=Object.assign({},this.$parent,this.translateParams)),this.$gettextInterpolate(e,t)}},render:function(e){return this.$vnode.key||(this.$vnode.key=uuid()),e(this.tag,[this.translation])}},INTERPOLATION_RE=/%\{((?:.|\n)+?)\}/g,MUSTACHE_SYNTAX_RE=/\{\{((?:.|\n)+?)\}\}/g,interpolate=function(msgid,context){void 0===context&&(context={}),!_Vue.config.getTextPluginSilent&&MUSTACHE_SYNTAX_RE.test(msgid)&&console.warn('Mustache syntax cannot be used with vue-gettext. Please use "%{}" instead of "{{}}" in: '+msgid);var result=msgid.replace(INTERPOLATION_RE,function(match,token){function evalInContext(expression){try{evaluated=eval("this."+expression)}catch(e){}if(void 0===evaluated){if(this.$parent)return evalInContext.call(this.$parent,expression);console.warn("Cannot evaluate expression: "+expression),evaluated=expression}return evaluated}var expression=token.trim(),evaluated;return evalInContext.call(context,expression)});return result};interpolate.INTERPOLATION_RE=INTERPOLATION_RE,interpolate.INTERPOLATION_PREFIX="%{";var updateTranslation=function(e,t,a){var n=a.data.attrs||{},r=e.dataset.msgid,s=n["translate-context"],i=n["translate-n"],o=n["translate-plural"],l=void 0!==i&&void 0!==o,u=a.context;if(!l&&(i||o))throw new Error("`translate-n` and `translate-plural` attributes must be used together:"+r+".");!_Vue.config.getTextPluginSilent&&n["translate-params"]&&console.warn("`translate-params` is required as an expression for v-translate directive. Please change to `v-translate='params'`: "+r),t.value&&"object"==typeof t.value&&(u=Object.assign({},a.context,t.value));var c=translate.getTranslation(r,i,s,l?o:null,e.dataset.currentLanguage),g=interpolate(c,u);e.innerHTML=g},Directive={bind:function(e,t,a){a.key||(a.key=uuid());var n=e.innerHTML;if(e.dataset.msgid=n,e.dataset.currentLanguage=_Vue.config.language,!_Vue.config.getTextPluginSilent){var r=n.indexOf(interpolate.INTERPOLATION_PREFIX)!==-1;r&&!t.expression&&console.info("No expression is provided for change detection. The translation for this key will be static:\n"+n)}updateTranslation(e,t,a)},update:function(e,t,a){var n=!1;e.dataset.currentLanguage!==_Vue.config.language&&(e.dataset.currentLanguage=_Vue.config.language,n=!0),!n&&t.expression&&t.value!==t.oldValue&&(n=!0),n&&updateTranslation(e,t,a)}},Config=function(e,t,a){Object.defineProperty(e.config,"language",{enumerable:!0,configurable:!0,get:function(){return t.current},set:function(e){t.current=e}}),Object.defineProperty(e.config,"getTextPluginSilent",{enumerable:!0,writable:!0,value:a})},Override=function(e,t){var a=e.prototype._init;e.prototype._init=function(e){void 0===e&&(e={});var n=e._parent||e.parent||this;this.$language=n.$language||t,a.call(this,e)};var n=e.prototype._destroy;e.prototype._destroy=function(){this.$language=null,n.apply(this,arguments)}},languageVm,GetTextPlugin=function(e,t){void 0===t&&(t={});var a={availableLanguages:{en_US:"English"},defaultLanguage:"en_US",languageVmMixin:{},silent:e.config.silent,translations:null};if(Object.keys(t).forEach(function(e){if(Object.keys(a).indexOf(e)===-1)throw new Error(e+" is an invalid option for the translate plugin.")}),!t.translations)throw new Error("No translations available.");t=Object.assign(a,t),languageVm=new e({created:function(){this.available=t.availableLanguages},data:{current:t.defaultLanguage},mixins:[t.languageVmMixin]}),shareVueInstance(e),Override(e,languageVm),Config(e,languageVm,t.silent),e.component("translate",Component),e.directive("translate",Directive),e.$translations=t.translations,e.prototype.$gettext=translate.gettext.bind(translate),e.prototype.$pgettext=translate.pgettext.bind(translate),e.prototype.$ngettext=translate.ngettext.bind(translate),e.prototype.$npgettext=translate.npgettext.bind(translate),e.prototype.$gettextInterpolate=interpolate.bind(interpolate)};return GetTextPlugin}); \ No newline at end of file