1/*! 2 * vue-i18n v8.27.0 3 * (c) 2022 kazuya kawaguchi 4 * Released under the MIT License. 5 */ 6(function (global, factory) { 7 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 8 typeof define === 'function' && define.amd ? define(factory) : 9 (global.VueI18n = factory()); 10}(this, (function () { 'use strict'; 11 12 /* */ 13 14 /** 15 * constants 16 */ 17 18 var numberFormatKeys = [ 19 'compactDisplay', 20 'currency', 21 'currencyDisplay', 22 'currencySign', 23 'localeMatcher', 24 'notation', 25 'numberingSystem', 26 'signDisplay', 27 'style', 28 'unit', 29 'unitDisplay', 30 'useGrouping', 31 'minimumIntegerDigits', 32 'minimumFractionDigits', 33 'maximumFractionDigits', 34 'minimumSignificantDigits', 35 'maximumSignificantDigits' 36 ]; 37 38 /** 39 * utilities 40 */ 41 42 function warn (msg, err) { 43 if (typeof console !== 'undefined') { 44 console.warn('[vue-i18n] ' + msg); 45 /* istanbul ignore if */ 46 if (err) { 47 console.warn(err.stack); 48 } 49 } 50 } 51 52 function error (msg, err) { 53 if (typeof console !== 'undefined') { 54 console.error('[vue-i18n] ' + msg); 55 /* istanbul ignore if */ 56 if (err) { 57 console.error(err.stack); 58 } 59 } 60 } 61 62 var isArray = Array.isArray; 63 64 function isObject (obj) { 65 return obj !== null && typeof obj === 'object' 66 } 67 68 function isBoolean (val) { 69 return typeof val === 'boolean' 70 } 71 72 function isString (val) { 73 return typeof val === 'string' 74 } 75 76 var toString = Object.prototype.toString; 77 var OBJECT_STRING = '[object Object]'; 78 function isPlainObject (obj) { 79 return toString.call(obj) === OBJECT_STRING 80 } 81 82 function isNull (val) { 83 return val === null || val === undefined 84 } 85 86 function isFunction (val) { 87 return typeof val === 'function' 88 } 89 90 function parseArgs () { 91 var args = [], len = arguments.length; 92 while ( len-- ) args[ len ] = arguments[ len ]; 93 94 var locale = null; 95 var params = null; 96 if (args.length === 1) { 97 if (isObject(args[0]) || isArray(args[0])) { 98 params = args[0]; 99 } else if (typeof args[0] === 'string') { 100 locale = args[0]; 101 } 102 } else if (args.length === 2) { 103 if (typeof args[0] === 'string') { 104 locale = args[0]; 105 } 106 /* istanbul ignore if */ 107 if (isObject(args[1]) || isArray(args[1])) { 108 params = args[1]; 109 } 110 } 111 112 return { locale: locale, params: params } 113 } 114 115 function looseClone (obj) { 116 return JSON.parse(JSON.stringify(obj)) 117 } 118 119 function remove (arr, item) { 120 if (arr.delete(item)) { 121 return arr 122 } 123 } 124 125 function arrayFrom (arr) { 126 var ret = []; 127 arr.forEach(function (a) { return ret.push(a); }); 128 return ret 129 } 130 131 function includes (arr, item) { 132 return !!~arr.indexOf(item) 133 } 134 135 var hasOwnProperty = Object.prototype.hasOwnProperty; 136 function hasOwn (obj, key) { 137 return hasOwnProperty.call(obj, key) 138 } 139 140 function merge (target) { 141 var arguments$1 = arguments; 142 143 var output = Object(target); 144 for (var i = 1; i < arguments.length; i++) { 145 var source = arguments$1[i]; 146 if (source !== undefined && source !== null) { 147 var key = (void 0); 148 for (key in source) { 149 if (hasOwn(source, key)) { 150 if (isObject(source[key])) { 151 output[key] = merge(output[key], source[key]); 152 } else { 153 output[key] = source[key]; 154 } 155 } 156 } 157 } 158 } 159 return output 160 } 161 162 function looseEqual (a, b) { 163 if (a === b) { return true } 164 var isObjectA = isObject(a); 165 var isObjectB = isObject(b); 166 if (isObjectA && isObjectB) { 167 try { 168 var isArrayA = isArray(a); 169 var isArrayB = isArray(b); 170 if (isArrayA && isArrayB) { 171 return a.length === b.length && a.every(function (e, i) { 172 return looseEqual(e, b[i]) 173 }) 174 } else if (!isArrayA && !isArrayB) { 175 var keysA = Object.keys(a); 176 var keysB = Object.keys(b); 177 return keysA.length === keysB.length && keysA.every(function (key) { 178 return looseEqual(a[key], b[key]) 179 }) 180 } else { 181 /* istanbul ignore next */ 182 return false 183 } 184 } catch (e) { 185 /* istanbul ignore next */ 186 return false 187 } 188 } else if (!isObjectA && !isObjectB) { 189 return String(a) === String(b) 190 } else { 191 return false 192 } 193 } 194 195 /** 196 * Sanitizes html special characters from input strings. For mitigating risk of XSS attacks. 197 * @param rawText The raw input from the user that should be escaped. 198 */ 199 function escapeHtml(rawText) { 200 return rawText 201 .replace(/</g, '<') 202 .replace(/>/g, '>') 203 .replace(/"/g, '"') 204 .replace(/'/g, ''') 205 } 206 207 /** 208 * Escapes html tags and special symbols from all provided params which were returned from parseArgs().params. 209 * This method performs an in-place operation on the params object. 210 * 211 * @param {any} params Parameters as provided from `parseArgs().params`.
212 * May be either an array of strings or a string->any map. 213 * 214 * @returns The manipulated `params` object. 215 */ 216 function escapeParams(params) { 217 if(params != null) { 218 Object.keys(params).forEach(function (key) { 219 if(typeof(params[key]) == 'string') { 220 params[key] = escapeHtml(params[key]); 221 } 222 }); 223 } 224 return params 225 } 226 227 /* */ 228 229 function extend (Vue) { 230 if (!Vue.prototype.hasOwnProperty('$i18n')) { 231 // $FlowFixMe 232 Object.defineProperty(Vue.prototype, '$i18n', { 233 get: function get () { return this._i18n } 234 }); 235 } 236 237 Vue.prototype.$t = function (key) { 238 var values = [], len = arguments.length - 1; 239 while ( len-- > 0 ) values[ len ] = arguments[ len + 1 ]; 240 241 var i18n = this.$i18n; 242 return i18n._t.apply(i18n, [ key, i18n.locale, i18n._getMessages(), this ].concat( values )) 243 }; 244 245 Vue.prototype.$tc = function (key, choice) { 246 var values = [], len = arguments.length - 2; 247 while ( len-- > 0 ) values[ len ] = arguments[ len + 2 ]; 248 249 var i18n = this.$i18n; 250 return i18n._tc.apply(i18n, [ key, i18n.locale, i18n._getMessages(), this, choice ].concat( values )) 251 }; 252 253 Vue.prototype.$te = function (key, locale) { 254 var i18n = this.$i18n; 255 return i18n._te(key, i18n.locale, i18n._getMessages(), locale) 256 }; 257 258 Vue.prototype.$d = function (value) { 259 var ref; 260 261 var args = [], len = arguments.length - 1; 262 while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; 263 return (ref = this.$i18n).d.apply(ref, [ value ].concat( args )) 264 }; 265 266 Vue.prototype.$n = function (value) { 267 var ref; 268 269 var args = [], len = arguments.length - 1; 270 while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; 271 return (ref = this.$i18n).n.apply(ref, [ value ].concat( args )) 272 }; 273 } 274 275 /* */ 276 277 /** 278 * Mixin 279 * 280 * If `bridge` mode, empty mixin is returned, 281 * else regulary mixin implementation is returned. 282 */ 283 function defineMixin (bridge) { 284 if ( bridge === void 0 ) bridge = false; 285 286 function mounted () { 287 if (this !== this.$root && this.$options.__INTLIFY_META__ && this.$el) { 288 this.$el.setAttribute('data-intlify', this.$options.__INTLIFY_META__); 289 } 290 } 291 292 return bridge 293 ? { mounted: mounted } // delegate `vue-i18n-bridge` mixin implementation 294 : { // regulary 295 beforeCreate: function beforeCreate () { 296 var options = this.$options; 297 options.i18n = options.i18n || ((options.__i18nBridge || options.__i18n) ? {} : null); 298 299 if (options.i18n) { 300 if (options.i18n instanceof VueI18n) { 301 // init locale messages via custom blocks 302 if ((options.__i18nBridge || options.__i18n)) { 303 try { 304 var localeMessages = options.i18n && options.i18n.messages ? options.i18n.messages : {}; 305 var _i18n = options.__i18nBridge || options.__i18n; 306 _i18n.forEach(function (resource) { 307 localeMessages = merge(localeMessages, JSON.parse(resource)); 308 }); 309 Object.keys(localeMessages).forEach(function (locale) { 310 options.i18n.mergeLocaleMessage(locale, localeMessages[locale]); 311 }); 312 } catch (e) { 313 { 314 error("Cannot parse locale messages via custom blocks.", e); 315 } 316 } 317 } 318 this._i18n = options.i18n; 319 this._i18nWatcher = this._i18n.watchI18nData(); 320 } else if (isPlainObject(options.i18n)) { 321 var rootI18n = this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n 322 ? this.$root.$i18n 323 : null; 324 // component local i18n 325 if (rootI18n) { 326 options.i18n.root = this.$root; 327 options.i18n.formatter = rootI18n.formatter; 328 options.i18n.fallbackLocale = rootI18n.fallbackLocale; 329 options.i18n.formatFallbackMessages = rootI18n.formatFallbackMessages; 330 options.i18n.silentTranslationWarn = rootI18n.silentTranslationWarn; 331 options.i18n.silentFallbackWarn = rootI18n.silentFallbackWarn; 332 options.i18n.pluralizationRules = rootI18n.pluralizationRules; 333 options.i18n.preserveDirectiveContent = rootI18n.preserveDirectiveContent; 334 } 335 336 // init locale messages via custom blocks 337 if ((options.__i18nBridge || options.__i18n)) { 338 try { 339 var localeMessages$1 = options.i18n && options.i18n.messages ? options.i18n.messages : {}; 340 var _i18n$1 = options.__i18nBridge || options.__i18n;
341 _i18n$1.forEach(function (resource) { 342 localeMessages$1 = merge(localeMessages$1, JSON.parse(resource)); 343 }); 344 options.i18n.messages = localeMessages$1; 345 } catch (e) { 346 { 347 warn("Cannot parse locale messages via custom blocks.", e); 348 } 349 } 350 } 351 352 var ref = options.i18n; 353 var sharedMessages = ref.sharedMessages; 354 if (sharedMessages && isPlainObject(sharedMessages)) { 355 options.i18n.messages = merge(options.i18n.messages, sharedMessages); 356 } 357 358 this._i18n = new VueI18n(options.i18n); 359 this._i18nWatcher = this._i18n.watchI18nData(); 360 361 if (options.i18n.sync === undefined || !!options.i18n.sync) { 362 this._localeWatcher = this.$i18n.watchLocale(); 363 } 364 365 if (rootI18n) { 366 rootI18n.onComponentInstanceCreated(this._i18n); 367 } 368 } else { 369 { 370 warn("Cannot be interpreted 'i18n' option."); 371 } 372 } 373 } else if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) { 374 // root i18n 375 this._i18n = this.$root.$i18n; 376 } else if (options.parent && options.parent.$i18n && options.parent.$i18n instanceof VueI18n) { 377 // parent i18n 378 this._i18n = options.parent.$i18n; 379 } 380 }, 381 382 beforeMount: function beforeMount () { 383 var options = this.$options; 384 options.i18n = options.i18n || ((options.__i18nBridge || options.__i18n) ? {} : null); 385 386 if (options.i18n) { 387 if (options.i18n instanceof VueI18n) { 388 // init locale messages via custom blocks 389 this._i18n.subscribeDataChanging(this); 390 this._subscribing = true; 391 } else if (isPlainObject(options.i18n)) { 392 this._i18n.subscribeDataChanging(this); 393 this._subscribing = true; 394 } else { 395 { 396 warn("Cannot be interpreted 'i18n' option."); 397 } 398 } 399 } else if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) { 400 this._i18n.subscribeDataChanging(this); 401 this._subscribing = true; 402 } else if (options.parent && options.parent.$i18n && options.parent.$i18n instanceof VueI18n) { 403 this._i18n.subscribeDataChanging(this); 404 this._subscribing = true; 405 } 406 }, 407 408 mounted: mounted, 409 410 beforeDestroy: function beforeDestroy () { 411 if (!this._i18n) { return } 412 413 var self = this; 414 this.$nextTick(function () { 415 if (self._subscribing) { 416 self._i18n.unsubscribeDataChanging(self); 417 delete self._subscribing; 418 } 419 420 if (self._i18nWatcher) { 421 self._i18nWatcher(); 422 self._i18n.destroyVM(); 423 delete self._i18nWatcher; 424 } 425 426 if (self._localeWatcher) { 427 self._localeWatcher(); 428 delete self._localeWatcher; 429 } 430 }); 431 } 432 } 433 } 434 435 /* */ 436 437 var interpolationComponent = { 438 name: 'i18n', 439 functional: true, 440 props: { 441 tag: { 442 type: [String, Boolean, Object],
443 default: 'span' 444 }, 445 path: { 446 type: String, 447 required: true 448 }, 449 locale: { 450 type: String 451 }, 452 places: { 453 type: [Array, Object] 454 } 455 }, 456 render: function render (h, ref) { 457 var data = ref.data; 458 var parent = ref.parent; 459 var props = ref.props; 460 var slots = ref.slots; 461 462 var $i18n = parent.$i18n; 463 if (!$i18n) { 464 { 465 warn('Cannot find VueI18n instance!'); 466 } 467 return 468 } 469 470 var path = props.path; 471 var locale = props.locale; 472 var places = props.places; 473 var params = slots(); 474 var children = $i18n.i( 475 path, 476 locale, 477 onlyHasDefaultPlace(params) || places 478 ? useLegacyPlaces(params.default, places) 479 : params 480 ); 481 482 var tag = (!!props.tag && props.tag !== true) || props.tag === false ? props.tag : 'span'; 483 return tag ? h(tag, data, children) : children 484 } 485 }; 486 487 function onlyHasDefaultPlace (params) { 488 var prop; 489 for (prop in params) { 490 if (prop !== 'default') { return false } 491 } 492 return Boolean(prop) 493 } 494 495 function useLegacyPlaces (children, places) { 496 var params = places ? createParamsFromPlaces(places) : {}; 497 498 if (!children) { return params } 499 500 // Filter empty text nodes 501 children = children.filter(function (child) { 502 return child.tag || child.text.trim() !== '' 503 }); 504 505 var everyPlace = children.every(vnodeHasPlaceAttribute); 506 if (everyPlace) { 507 warn('`place` attribute is deprecated in next major version. Please switch to Vue slots.'); 508 } 509 510 return children.reduce( 511 everyPlace ? assignChildPlace : assignChildIndex, 512 params 513 ) 514 } 515 516 function createParamsFromPlaces (places) { 517 { 518 warn('`places` prop is deprecated in next major version. Please switch to Vue slots.'); 519 } 520 521 return Array.isArray(places) 522 ? places.reduce(assignChildIndex, {}) 523 : Object.assign({}, places) 524 } 525 526 function assignChildPlace (params, child) { 527 if (child.data && child.data.attrs && child.data.attrs.place) { 528 params[child.data.attrs.place] = child; 529 } 530 return params 531 } 532 533 function assignChildIndex (params, child, index) { 534 params[index] = child; 535 return params 536 } 537 538 function vnodeHasPlaceAttribute (vnode) { 539 return Boolean(vnode.data && vnode.data.attrs && vnode.data.attrs.place) 540 } 541 542 /* */ 543 544 var numberComponent = { 545 name: 'i18n-n', 546 functional: true, 547 props: { 548 tag: { 549 type: [String, Boolean, Object], 550 default: 'span' 551 }, 552 value: { 553 type: Number, 554 required: true 555 }, 556 format: { 557 type: [String, Object] 558 }, 559 locale: { 560 type: String 561 } 562 }, 563 render: function render (h, ref) { 564 var props = ref.props; 565 var parent = ref.parent; 566 var data = ref.data; 567 568 var i18n = parent.$i18n; 569 570 if (!i18n) { 571 { 572 warn('Cannot find VueI18n instance!'); 573 } 574 return null 575 } 576 577 var key = null; 578 var options = null; 579 580 if (isString(props.format)) { 581 key = props.format; 582 } else if (isObject(props.format)) { 583 if (props.format.key) { 584 key = props.format.key; 585 } 586 587 // Filter out number format options only 588 options = Object.keys(props.format).reduce(function (acc, prop
588) { 589 var obj; 590 591 if (includes(numberFormatKeys, prop)) { 592 return Object.assign({}, acc, ( obj = {}, obj[prop] = props.format[prop], obj )) 593 } 594 return acc 595 }, null); 596 } 597 598 var locale = props.locale || i18n.locale; 599 var parts = i18n._ntp(props.value, locale, key, options); 600 601 var values = parts.map(function (part, index) { 602 var obj; 603 604 var slot = data.scopedSlots && data.scopedSlots[part.type]; 605 return slot ? slot(( obj = {}, obj[part.type] = part.value, obj.index = index, obj.parts = parts, obj )) : part.value 606 }); 607 608 var tag = (!!props.tag && props.tag !== true) || props.tag === false ? props.tag : 'span'; 609 return tag 610 ? h(tag, { 611 attrs: data.attrs, 612 'class': data['class'], 613 staticClass: data.staticClass 614 }, values) 615 : values 616 } 617 }; 618 619 /* */ 620 621 function bind (el, binding, vnode) { 622 if (!assert(el, vnode)) { return } 623 624 t(el, binding, vnode); 625 } 626 627 function update (el, binding, vnode, oldVNode) { 628 if (!assert(el, vnode)) { return } 629 630 var i18n = vnode.context.$i18n; 631 if (localeEqual(el, vnode) && 632 (looseEqual(binding.value, binding.oldValue) && 633 looseEqual(el._localeMessage, i18n.getLocaleMessage(i18n.locale)))) { return } 634 635 t(el, binding, vnode); 636 } 637 638 function unbind (el, binding, vnode, oldVNode) { 639 var vm = vnode.context; 640 if (!vm) { 641 warn('Vue instance does not exists in VNode context'); 642 return 643 } 644 645 var i18n = vnode.context.$i18n || {}; 646 if (!binding.modifiers.preserve && !i18n.preserveDirectiveContent) { 647 el.textContent = ''; 648 } 649 el._vt = undefined; 650 delete el['_vt']; 651 el._locale = undefined; 652 delete el['_locale']; 653 el._localeMessage = undefined; 654 delete el['_localeMessage']; 655 } 656 657 function assert (el, vnode) { 658 var vm = vnode.context; 659 if (!vm) { 660 warn('Vue instance does not exists in VNode context'); 661 return false 662 } 663 664 if (!vm.$i18n) { 665 warn('VueI18n instance does not exists in Vue instance'); 666 return false 667 } 668 669 return true 670 } 671 672 function localeEqual (el, vnode) { 673 var vm = vnode.context; 674 return el._locale === vm.$i18n.locale 675 } 676 677 function t (el, binding, vnode) { 678 var ref$1, ref$2; 679 680 var value = binding.value; 681 682 var ref = parseValue(value); 683 var path = ref.path; 684 var locale = ref.locale; 685 var args = ref.args; 686 var choice = ref.choice; 687 if (!path && !locale && !args) { 688 warn('value type not supported'); 689 return 690 } 691 692 if (!path) { 693 warn('`path` is required in v-t directive'); 694 return 695 } 696 697 var vm = vnode.context; 698 if (choice != null) { 699 el._vt = el.textContent = (ref$1 = vm.$i18n).tc.apply(ref$1, [ path, choice ].concat( makeParams(locale, args) )); 700 } else { 701 el._vt = el.textContent = (ref$2 = vm.$i18n).t.apply(ref$2, [ path ].concat( makeParams(locale, args) )); 702 } 703 el._locale = vm.$i18n.locale; 704 el._localeMessage = vm.$i18n.getLocaleMessage(vm.$i18n.locale); 705 } 706 707 function parseValue (value) { 708 var path; 709 var locale; 710 var args; 711 var choice; 712 713 if (isString(value)) { 714 path = value; 715 } else if (isPlainObject(value)) { 716 path = value.path; 717 locale = value.locale; 718 args = value.args; 719 choice = value.choice; 720 } 721 722 return { path: path, locale: locale, args: args, choice: choice } 723 } 724 725 function makeParams (locale, args) { 726 var params = []; 727 728 locale && params.push(locale); 729 if (args && (Array.isArray(args) || isPlainObject(args))) { 730 params.push(args); 731 } 732 733 return params 734 } 735 736 var Vue; 737 738 function install (_Vue, options) { 739 if ( options === void 0 ) options = { bridge: false }; 740 741 /* istanbul ignore if */ 742 if (install.installed && _Vue === Vue) { 743 warn('already installed.'); 744 return 745 } 746 install.installed = true; 747 748 Vue = _Vue; 749 750 var version = (Vue.version && Number(Vue.version.split('.')[0])) || -1; 751 /* istanbul ignore if */ 752 if (version < 2) { 753 warn(("vue-i18n (" + (install.version) + ") need to use Vue 2.0 or later (Vue: " + (Vue.version) + ")."));
754 return 755 } 756 757 extend(Vue); 758 Vue.mixin(defineMixin(options.bridge)); 759 Vue.directive('t', { bind: bind, update: update, unbind: unbind }); 760 Vue.component(interpolationComponent.name, interpolationComponent); 761 Vue.component(numberComponent.name, numberComponent); 762 763 // use simple mergeStrategies to prevent i18n instance lose '__proto__' 764 var strats = Vue.config.optionMergeStrategies; 765 strats.i18n = function (parentVal, childVal) { 766 return childVal === undefined 767 ? parentVal 768 : childVal 769 }; 770 } 771 772 /* */ 773 774 var BaseFormatter = function BaseFormatter () { 775 this._caches = Object.create(null); 776 }; 777 778 BaseFormatter.prototype.interpolate = function interpolate (message, values) { 779 if (!values) { 780 return [message] 781 } 782 var tokens = this._caches[message]; 783 if (!tokens) { 784 tokens = parse(message); 785 this._caches[message] = tokens; 786 } 787 return compile(tokens, values) 788 }; 789 790 791 792 var RE_TOKEN_LIST_VALUE = /^(?:\d)+/; 793 var RE_TOKEN_NAMED_VALUE = /^(?:\w)+/; 794 795 function parse (format) { 796 var tokens = []; 797 var position = 0; 798 799 var text = ''; 800 while (position < format.length) { 801 var char = format[position++]; 802 if (char === '{') { 803 if (text) { 804 tokens.push({ type: 'text', value: text }); 805 } 806 807 text = ''; 808 var sub = ''; 809 char = format[position++]; 810 while (char !== undefined && char !== '}') { 811 sub += char; 812 char = format[position++]; 813 } 814 var isClosed = char === '}'; 815 816 var type = RE_TOKEN_LIST_VALUE.test(sub) 817 ? 'list' 818 : isClosed && RE_TOKEN_NAMED_VALUE.test(sub) 819 ? 'named' 820 : 'unknown'; 821 tokens.push({ value: sub, type: type }); 822 } else if (char === '%') { 823 // when found rails i18n syntax, skip text capture 824 if (format[(position)] !== '{') { 825 text += char; 826 } 827 } else { 828 text += char; 829 } 830 } 831 832 text && tokens.push({ type: 'text', value: text }); 833 834 return tokens 835 } 836 837 function compile (tokens, values) { 838 var compiled = []; 839 var index = 0; 840 841 var mode = Array.isArray(values) 842 ? 'list' 843 : isObject(values) 844 ? 'named' 845 : 'unknown'; 846 if (mode === 'unknown') { return compiled } 847 848 while (index < tokens.length) { 849 var token = tokens[index]; 850 switch (token.type) { 851 case 'text': 852 compiled.push(token.value); 853 break 854 case 'list': 855 compiled.push(values[parseInt(token.value, 10)]); 856 break 857 case 'named': 858 if (mode === 'named') { 859 compiled.push((values)[token.value]); 860 } else { 861 { 862 warn(("Type of token '" + (token.type) + "' and format of value '" + mode + "' don't match!")); 863 } 864 } 865 break 866 case 'unknown': 867 { 868 warn("Detect 'unknown' type of token!"); 869 } 870 break 871 } 872 index++; 873 } 874 875 return compiled 876 } 877 878 /* */ 879 880 /** 881 * Path parser 882 * - Inspired: 883 * Vue.js Path parser 884 */ 885 886 // actions 887 var APPEND = 0; 888 var PUSH = 1; 889 var INC_SUB_PATH_DEPTH = 2; 890 var PUSH_SUB_PATH = 3; 891 892 // states 893 var BEFORE_PATH = 0; 894 var IN_PATH = 1; 895 var BEFORE_IDENT = 2; 896 var IN_IDENT = 3; 897 var IN_SUB_PATH = 4; 898 var IN_SINGLE_QUOTE = 5; 899 var IN_DOUBLE_QUOTE = 6;
900 var AFTER_PATH = 7; 901 var ERROR = 8; 902 903 var pathStateMachine = []; 904 905 pathStateMachine[BEFORE_PATH] = { 906 'ws': [BEFORE_PATH], 907 'ident': [IN_IDENT, APPEND], 908 '[': [IN_SUB_PATH], 909 'eof': [AFTER_PATH] 910 }; 911 912 pathStateMachine[IN_PATH] = { 913 'ws': [IN_PATH], 914 '.': [BEFORE_IDENT], 915 '[': [IN_SUB_PATH], 916 'eof': [AFTER_PATH] 917 }; 918 919 pathStateMachine[BEFORE_IDENT] = { 920 'ws': [BEFORE_IDENT], 921 'ident': [IN_IDENT, APPEND], 922 '0': [IN_IDENT, APPEND], 923 'number': [IN_IDENT, APPEND] 924 }; 925 926 pathStateMachine[IN_IDENT] = { 927 'ident': [IN_IDENT, APPEND], 928 '0': [IN_IDENT, APPEND], 929 'number': [IN_IDENT, APPEND], 930 'ws': [IN_PATH, PUSH], 931 '.': [BEFORE_IDENT, PUSH], 932 '[': [IN_SUB_PATH, PUSH], 933 'eof': [AFTER_PATH, PUSH] 934 }; 935 936 pathStateMachine[IN_SUB_PATH] = { 937 "'": [IN_SINGLE_QUOTE, APPEND], 938 '"': [IN_DOUBLE_QUOTE, APPEND], 939 '[': [IN_SUB_PATH, INC_SUB_PATH_DEPTH], 940 ']': [IN_PATH, PUSH_SUB_PATH], 941 'eof': ERROR, 942 'else': [IN_SUB_PATH, APPEND] 943 }; 944 945 pathStateMachine[IN_SINGLE_QUOTE] = { 946 "'": [IN_SUB_PATH, APPEND], 947 'eof': ERROR, 948 'else': [IN_SINGLE_QUOTE, APPEND] 949 }; 950 951 pathStateMachine[IN_DOUBLE_QUOTE] = { 952 '"': [IN_SUB_PATH, APPEND], 953 'eof': ERROR, 954 'else': [IN_DOUBLE_QUOTE, APPEND] 955 }; 956 957 /** 958 * Check if an expression is a literal value. 959 */ 960 961 var literalValueRE = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/; 962 function isLiteral (exp) { 963 return literalValueRE.test(exp) 964 } 965 966 /** 967 * Strip quotes from a string 968 */ 969 970 function stripQuotes (str) { 971 var a = str.charCodeAt(0); 972 var b = str.charCodeAt(str.length - 1); 973 return a === b && (a === 0x22 || a === 0x27) 974 ? str.slice(1, -1) 975 : str 976 } 977 978 /** 979 * Determine the type of a character in a keypath. 980 */ 981 982 function getPathCharType (ch) { 983 if (ch === undefined || ch === null) { return 'eof' } 984 985 var code = ch.charCodeAt(0); 986 987 switch (code) { 988 case 0x5B: // [ 989 case 0x5D: // ] 990 case 0x2E: // . 991 case 0x22: // " 992 case 0x27: // ' 993 return ch 994 995 case 0x5F: // _ 996 case 0x24: // $ 997 case 0x2D: // - 998 return 'ident' 999 1000 case 0x09: // Tab 1001 case 0x0A: // Newline 1002 case 0x0D: // Return 1003 case 0xA0: // No-break space 1004 case 0xFEFF: // Byte Order Mark 1005 case 0x2028: // Line Separator 1006 case 0x2029: // Paragraph Separator 1007 return 'ws' 1008 } 1009 1010 return 'ident' 1011 } 1012 1013 /** 1014 * Format a subPath, return its plain form if it is 1015 * a literal string or number. Otherwise prepend the 1016 * dynamic indicator (*). 1017 */ 1018 1019 function formatSubPath (path) { 1020 var trimmed = path.trim(); 1021 // invalid leading 0 1022 if (path.charAt(0) === '0' && isNaN(path)) { return false } 1023 1024 return isLiteral(trimmed) ? stripQuotes(trimmed) : '*' + trimmed 1025 } 1026 1027 /** 1028 * Parse a string path into an array of segments 1029 */ 1030 1031 function parse$1 (path) { 1032 var keys = []; 1033 var index = -1; 1034 var mode = BEFORE_PATH; 1035 var subPathDepth = 0; 1036 var c; 1037 var key; 1038 var newChar; 1039 var type; 1040 var transition; 1041 var action; 1042 var typeMap; 1043 var actions = []; 1044 1045 actions[PUSH] = function () { 1046 if (key !== undefined) { 1047 keys.push(key); 1048 key = undefined; 1049 } 1050 }; 1051 1052 actions[APPEND] = function () { 1053 if (key === undefined) { 1054 key = newChar; 1055 } else { 1056 key += newChar; 1057 } 1058 }; 1059 1060 actions[INC_SUB_PATH_DEPTH] = function () { 1061 actions[APPEND]();
1062 subPathDepth++; 1063 }; 1064 1065 actions[PUSH_SUB_PATH] = function () { 1066 if (subPathDepth > 0) { 1067 subPathDepth--; 1068 mode = IN_SUB_PATH; 1069 actions[APPEND](); 1070 } else { 1071 subPathDepth = 0; 1072 if (key === undefined) { return false } 1073 key = formatSubPath(key); 1074 if (key === false) { 1075 return false 1076 } else { 1077 actions[PUSH](); 1078 } 1079 } 1080 }; 1081 1082 function maybeUnescapeQuote () { 1083 var nextChar = path[index + 1]; 1084 if ((mode === IN_SINGLE_QUOTE && nextChar === "'") || 1085 (mode === IN_DOUBLE_QUOTE && nextChar === '"')) { 1086 index++; 1087 newChar = '\\' + nextChar; 1088 actions[APPEND](); 1089 return true 1090 } 1091 } 1092 1093 while (mode !== null) { 1094 index++; 1095 c = path[index]; 1096 1097 if (c === '\\' && maybeUnescapeQuote()) { 1098 continue 1099 } 1100 1101 type = getPathCharType(c); 1102 typeMap = pathStateMachine[mode]; 1103 transition = typeMap[type] || typeMap['else'] || ERROR; 1104 1105 if (transition === ERROR) { 1106 return // parse error 1107 } 1108 1109 mode = transition[0]; 1110 action = actions[transition[1]]; 1111 if (action) { 1112 newChar = transition[2]; 1113 newChar = newChar === undefined 1114 ? c 1115 : newChar; 1116 if (action() === false) { 1117 return 1118 } 1119 } 1120 1121 if (mode === AFTER_PATH) { 1122 return keys 1123 } 1124 } 1125 } 1126 1127 1128 1129 1130 1131 var I18nPath = function I18nPath () { 1132 this._cache = Object.create(null); 1133 }; 1134 1135 /** 1136 * External parse that check for a cache hit first 1137 */ 1138 I18nPath.prototype.parsePath = function parsePath (path) { 1139 var hit = this._cache[path]; 1140 if (!hit) { 1141 hit = parse$1(path); 1142 if (hit) { 1143 this._cache[path] = hit; 1144 } 1145 } 1146 return hit || [] 1147 }; 1148 1149 /** 1150 * Get path value from path string 1151 */ 1152 I18nPath.prototype.getPathValue = function getPathValue (obj, path) { 1153 if (!isObject(obj)) { return null } 1154 1155 var paths = this.parsePath(path); 1156 if (paths.length === 0) { 1157 return null 1158 } else { 1159 var length = paths.length; 1160 var last = obj; 1161 var i = 0; 1162 while (i < length) { 1163 var value = last[paths[i]]; 1164 if (value === undefined || value === null) { 1165 return null 1166 } 1167 last = value; 1168 i++; 1169 } 1170 1171 return last 1172 } 1173 }; 1174 1175 /* */ 1176 1177 1178 1179 var htmlTagMatcher = /<\/?[\w\s="/.':;#-\/]+>/; 1180 var linkKeyMatcher = /(?:@(?:\.[a-z]+)?:(?:[\w\-_|./]+|\([\w\-_|./]+\)))/g; 1181 var linkKeyPrefixMatcher = /^@(?:\.([a-z]+))?:/; 1182 var bracketsMatcher = /[()]/g; 1183 var defaultModifiers = { 1184 'upper': function (str) { return str.toLocaleUpperCase(); }, 1185 'lower': function (str) { return str.toLocaleLowerCase(); }, 1186 'capitalize': function (str) { return ("" + (str.charAt(0).toLocaleUpperCase()) + (str.substr(1))); } 1187 }; 1188 1189 var defaultFormatter = new BaseFormatter(); 1190 1191 var VueI18n = function VueI18n (options) { 1192 var this$1 = this; 1193 if ( options === void 0 ) options = {}; 1194 1195 // Auto install if it is not done yet and `window` has `Vue`. 1196 // To allow users to avoid auto-installation in some cases, 1197 // this code should be placed here. See #290 1198 /* istanbul ignore if */ 1199 if (!Vue && typeof window !== 'undefined' && window.Vue) { 1200 install(window.Vue); 1201 } 1202 1203 var locale = options.locale || 'es-ES'; 1204 var fallbackLocale = options.fallbackLocale === false 1205 ? false 1206 : options.fallbackLocale || 'es-ES'; 1207 var messages = options.messages || {}; 1208 var dateTimeFormats = options.dateTimeFormats || options.datetimeFormats || {}; 1209 var numberFormats = options.numberFormats || {}; 1210 1211 this._vm = null; 1212 this._formatter = options.formatter || defaultFormatter; 1213 this._modifiers = options.modifiers || {}; 1214 this._missing = options.missing || null; 1215 this._root = options.root || null; 1216 this._sync = options.sync === undefined ? true : !!options.sync; 1217 this._fallbackRoot = options.fallbackRoot === undefined 1218 ? true 1219 : !!options.fallbackRoot; 1220 this._fallbackRootWithEmptyString = options.fallbackRootWithEmptyString === undefined 1221 ? true 1222 : !!options.fallbackRootWithEmptyString; 1223 this._formatFallbackMessages = options.formatFallbackMessages === undefined 1224 ? false 1225 : !!options.formatFallbackMessages; 1226 this._silentTranslationWarn = options.silentTranslationWarn === undefined 1227 ? false 1228 : options.silentTranslationWarn; 1229 this._silentFallbackWarn = options.silentFallbackWarn === undefined 1230 ? false 1231 : !!options.silentFallbackWarn; 1232 this._dateTimeFormatters = {}; 1233 this._numberFormatters = {}; 1234 this._path = new I18nPath(); 1235 this._dataListeners = new Set(); 1236 this._componentInstanceCreatedListener = options.componentInstanceCreatedListener || null; 1237 this._preserveDirectiveContent = options.preserveDirectiveContent === undefined 1238 ? false 1239 : !!options.preserveDirectiveContent; 1240 this.pluralizationRules = options.pluralizationRules || {}; 1241 this._warnHtmlInMessage = options.warnHtmlInMessage || 'off'; 1242 this._postTranslation = options.postTranslation || null; 1243 this._escapeParameterHtml = options.escapeParameterHtml || false; 1244 1245 if ('__VUE_I18N_BRIDGE__' in options) { 1246 this.__VUE_I18N_BRIDGE__ = options.__VUE_I18N_BRIDGE__; 1247 } 1248 1249 /** 1250 * @param choice {number} a choice index given by the input to $tc: `$tc('path.to.rule', choiceIndex)` 1251 * @param choicesLength {number} an overall amount of available choices 1252 * @returns a final choice index 1253 */ 1254 this.getChoiceIndex = function (choice, choicesLength) { 1255 var thisPrototype = Object.getPrototypeOf(this$1); 1256 if (thisPrototype && thisPrototype.getChoiceIndex) { 1257 var prototypeGetChoiceIndex = (thisPrototype.getChoiceIndex); 1258 return (prototypeGetChoiceIndex).call(this$1, choice, choicesLength) 1259 } 1260 1261 // Default (old) getChoiceIndex implementation - english-compatible 1262 var defaultImpl = function (_choice, _choicesLength) { 1263 _choice = Math.abs(_choice); 1264 1265 if (_choicesLength === 2) { 1266 return _choice 1267 ? _choice > 1 1268 ? 1 1269 : 0 1270 : 1 1271 } 1272 1273 return _choice ? Math.min(_choice, 2) : 0 1274 }; 1275 1276 if (this$1.locale in this$1.pluralizationRules) { 1277 return this$1.pluralizationRules[this$1.locale].apply(this$1, [choice, choicesLength]) 1278 } else { 1279 return defaultImpl(choice, choicesLength) 1280 } 1281 }; 1282 1283 1284 this._exist = function (message, key) { 1285 if (!message || !key) { return false } 1286 if (!isNull(this$1._path.getPathValue(message, key))) { return true } 1287 // fallback for flat key 1288 if (message[key]) { return true } 1289 return false 1290 }; 1291 1292 if (this._warnHtmlInMessage === 'warn' || this._warnHtmlInMessage === 'error') {
1293 Object.keys(messages).forEach(function (locale) { 1294 this$1._checkLocaleMessage(locale, this$1._warnHtmlInMessage, messages[locale]); 1295 }); 1296 } 1297 1298 this._initVM({ 1299 locale: locale, 1300 fallbackLocale: fallbackLocale, 1301 messages: messages, 1302 dateTimeFormats: dateTimeFormats, 1303 numberFormats: numberFormats 1304 }); 1305 }; 1306 1307 var prototypeAccessors = { vm: { configurable: true },messages: { configurable: true },dateTimeFormats: { configurable: true },numberFormats: { configurable: true },availableLocales: { configurable: true },locale: { configurable: true },fallbackLocale: { configurable: true },formatFallbackMessages: { configurable: true },missing: { configurable: true },formatter: { configurable: true },silentTranslationWarn: { configurable: true },silentFallbackWarn: { configurable: true },preserveDirectiveContent: { configurable: true },warnHtmlInMessage: { configurable: true },postTranslation: { configurable: true },sync: { configurable: true } }; 1308 1309 VueI18n.prototype._checkLocaleMessage = function _checkLocaleMessage (locale, level, message) { 1310 var paths = []; 1311 1312 var fn = function (level, locale, message, paths) { 1313 if (isPlainObject(message)) { 1314 Object.keys(message).forEach(function (key) { 1315 var val = message[key]; 1316 if (isPlainObject(val)) { 1317 paths.push(key); 1318 paths.push('.'); 1319 fn(level, locale, val, paths); 1320 paths.pop(); 1321 paths.pop(); 1322 } else { 1323 paths.push(key); 1324 fn(level, locale, val, paths); 1325 paths.pop(); 1326 } 1327 }); 1328 } else if (isArray(message)) { 1329 message.forEach(function (item, index) { 1330 if (isPlainObject(item)) { 1331 paths.push(("[" + index + "]")); 1332 paths.push('.'); 1333 fn(level, locale, item, paths); 1334 paths.pop(); 1335 paths.pop(); 1336 } else { 1337 paths.push(("[" + index + "]")); 1338 fn(level, locale, item, paths); 1339 paths.pop(); 1340 } 1341 }); 1342 } else if (isString(message)) { 1343 var ret = htmlTagMatcher.test(message); 1344 if (ret) { 1345 var msg = "Detected HTML in message '" + message + "' of keypath '" + (paths.join('')) + "' at '" + locale + "'. Consider component interpolation with '<i18n>' to avoid XSS. See https://bit.ly/2ZqJzkp"; 1346 if (level === 'warn') { 1347 warn(msg); 1348 } else if (level === 'error') { 1349 error(msg); 1350 } 1351 } 1352 } 1353 }; 1354 1355 fn(level, locale, message, paths); 1356 }; 1357 1358 VueI18n.prototype._initVM = function _initVM (data) { 1359 var silent = Vue.config.silent; 1360 Vue.config.silent = true; 1361 this._vm = new Vue({ data: data, __VUE18N__INSTANCE__: true }); 1362 Vue.config.silent = silent; 1363 }; 1364 1365 VueI18n.prototype.destroyVM = function destroyVM () { 1366 this._vm.$destroy(); 1367 }; 1368 1369 VueI18n.prototype.subscribeDataChanging = function subscribeDataChanging (vm) { 1370 this._dataListeners.add(vm); 1371 }; 1372 1373 VueI18n.prototype.unsubscribeDataChanging = function unsubscribeDataChanging (vm) { 1374 remove(this._dataListeners, vm); 1375 }; 1376 1377 VueI18n.prototype.watchI18nData = function watchI18nData () { 1378 var this$1 = this; 1379 return this._vm.$watch('$data', function () { 1380 var listeners = arrayFrom(this$1._dataListeners); 1381 var i = listeners.length; 1382 while(i--) { 1383 Vue.nextTick(function () { 1384 listeners[i] && listeners[i].$forceUpdate(); 1385 }); 1386 } 1387 }, { deep: true }) 1388 }; 1389 1390 VueI18n.prototype.watchLocale = function watchLocale (composer) { 1391 if (!composer) { 1392 /* istanbul ignore if */ 1393 if (!this._sync || !this._root) { return null } 1394 var target = this._vm; 1395 return this._root.$i18n.vm.$watch('locale', function (val) { 1396 target.$set(target, 'locale', val); 1397 target.$forceUpdate(); 1398 }, { immediate: true }) 1399 } else { 1400 // deal with vue-i18n-bridge 1401 if (!this.__VUE_I18N_BRIDGE__) { return null } 1402 var self = this; 1403 var target$1 = this._vm; 1404 return this.vm.$watch('locale', function (val) { 1405 target$1.$set(target$1, 'locale', val); 1406 if (self.__VUE_I18N_BRIDGE__ && composer) { 1407 composer.locale.value = val; 1408 } 1409 target$1.$forceUpdate(); 1410 }, { immediate: true }) 1411 } 1412 }; 1413 1414 VueI18n.prototype.onComponentInstanceCreated = function onComponentInstanceCreated (newI18n) { 1415 if (this._componentInstanceCreatedListener) { 1416 this._componentInstanceCreatedListener(newI18n, this); 1417 } 1418 }; 1419 1420 prototypeAccessors.vm.get = function () { return this._vm }; 1421 1422 prototypeAccessors.messages.get = function () { return looseClone(this._getMessages()) }; 1423 prototypeAccessors.dateTimeFormats.get = function () { return looseClone(this._getDateTimeFormats()) }; 1424 prototypeAccessors.numberFormats.get = function () { return looseClone(this._getNumberFormats()) }; 1425 prototypeAccessors.availableLocales.get = function () { return Object.keys(this.messages).sort() }; 1426 1427 prototypeAccessors.locale.get = function () { return this._vm.locale }; 1428 prototypeAccessors.locale.set = function (locale) { 1429 this._vm.$set(this._vm, 'locale', locale); 1430 }; 1431 1432 prototypeAccessors.fallbackLocale.get = function () { return this._vm.fallbackLocale }; 1433 prototypeAccessors.fallbackLocale.set = function (locale) { 1434 this._localeChainCache = {}; 1435 this._vm.$set(this._vm, 'fallbackLocale', locale); 1436 }; 1437 1438 prototypeAccessors.formatFallbackMessages.get = function () { return this._formatFallbackMessages }; 1439 prototypeAccessors.formatFallbackMessages.set = function (fallback) { this._formatFallbackMessages = fallback; }; 1440 1441 prototypeAccessors.missing.get = function () { return this._missing }; 1442 prototypeAccessors.missing.set = function (handler) { this._missing = handler; }; 1443 1444 prototypeAccessors.formatter.get = function () { return this._formatter }; 1445 prototypeAccessors.formatter.set = function (formatter) { this._formatter = formatter; }; 1446 1447 prototypeAccessors.silentTranslationWarn.get = function () { return this._silentTranslationWarn }; 1448 prototypeAccessors.silentTranslationWarn.set = function (silent) { this._silentTranslationWarn = silent; }; 1449 1450 prototypeAccessors.silentFallbackWarn.get = function () { return this._silentFallbackWarn }; 1451 prototypeAccessors.silentFallbackWarn.set = function (silent) { this._silentFallbackWarn = silent; }; 1452 1453 prototypeAccessors.preserveDirectiveContent.get = function () { return this._preserveDirectiveContent }; 1454 prototypeAccessors.preserveDirectiveContent.set = function (preserve) { this._preserveDirectiveContent = preserve; }; 1455 1456 prototypeAccessors.warnHtmlInMessage.get = function () { return this._warnHtmlInMessage }; 1457 prototypeAccessors.warnHtmlInMessage.set = function (level) { 1458 var this$1 = this; 1459 1460 var orgLevel = this._warnHtmlInMessage; 1461 this._warnHtmlInMessage = level; 1462 if (orgLevel !== level && (level === 'warn' || level === 'error')) { 1463 var messages = this._getMessages();
1464 Object.keys(messages).forEach(function (locale) { 1465 this$1._checkLocaleMessage(locale, this$1._warnHtmlInMessage, messages[locale]); 1466 }); 1467 } 1468 }; 1469 1470 prototypeAccessors.postTranslation.get = function () { return this._postTranslation }; 1471 prototypeAccessors.postTranslation.set = function (handler) { this._postTranslation = handler; }; 1472 1473 prototypeAccessors.sync.get = function () { return this._sync }; 1474 prototypeAccessors.sync.set = function (val) { this._sync = val; }; 1475 1476 VueI18n.prototype._getMessages = function _getMessages () { return this._vm.messages }; 1477 VueI18n.prototype._getDateTimeFormats = function _getDateTimeFormats () { return this._vm.dateTimeFormats }; 1478 VueI18n.prototype._getNumberFormats = function _getNumberFormats () { return this._vm.numberFormats }; 1479 1480 VueI18n.prototype._warnDefault = function _warnDefault (locale, key, result, vm, values, interpolateMode) { 1481 if (!isNull(result)) { return result } 1482 if (this._missing) { 1483 var missingRet = this._missing.apply(null, [locale, key, vm, values]); 1484 if (isString(missingRet)) { 1485 return missingRet 1486 } 1487 } else { 1488 if (!this._isSilentTranslationWarn(key)) { 1489 warn( 1490 "Cannot translate the value of keypath '" + key + "'. " + 1491 'Use the value of keypath as default.' 1492 ); 1493 } 1494 } 1495 1496 if (this._formatFallbackMessages) { 1497 var parsedArgs = parseArgs.apply(void 0, values); 1498 return this._render(key, interpolateMode, parsedArgs.params, key) 1499 } else { 1500 return key 1501 } 1502 }; 1503 1504 VueI18n.prototype._isFallbackRoot = function _isFallbackRoot (val) { 1505 return (this._fallbackRootWithEmptyString? !val : isNull(val)) && !isNull(this._root) && this._fallbackRoot 1506 }; 1507 1508 VueI18n.prototype._isSilentFallbackWarn = function _isSilentFallbackWarn (key) { 1509 return this._silentFallbackWarn instanceof RegExp 1510 ? this._silentFallbackWarn.test(key) 1511 : this._silentFallbackWarn 1512 }; 1513 1514 VueI18n.prototype._isSilentFallback = function _isSilentFallback (locale, key) { 1515 return this._isSilentFallbackWarn(key) && (this._isFallbackRoot() || locale !== this.fallbackLocale) 1516 }; 1517 1518 VueI18n.prototype._isSilentTranslationWarn = function _isSilentTranslationWarn (key) { 1519 return this._silentTranslationWarn instanceof RegExp 1520 ? this._silentTranslationWarn.test(key) 1521 : this._silentTranslationWarn 1522 }; 1523 1524 VueI18n.prototype._interpolate = function _interpolate ( 1525 locale, 1526 message, 1527 key, 1528 host, 1529 interpolateMode, 1530 values, 1531 visitedLinkStack 1532 ) { 1533 if (!message) { return null } 1534 1535 var pathRet = this._path.getPathValue(message, key); 1536 if (isArray(pathRet) || isPlainObject(pathRet)) { return pathRet } 1537 1538 var ret; 1539 if (isNull(pathRet)) { 1540 /* istanbul ignore else */ 1541 if (isPlainObject(message)) { 1542 ret = message[key]; 1543 if (!(isString(ret) || isFunction(ret))) { 1544 if (!this._isSilentTranslationWarn(key) && !this._isSilentFallback(locale, key)) { 1545 warn(("Value of key '" + key + "' is not a string or function !")); 1546 } 1547 return null 1548 } 1549 } else { 1550 return null 1551 } 1552 } else { 1553 /* istanbul ignore else */ 1554 if (isString(pathRet) || isFunction(pathRet)) { 1555 ret = pathRet; 1556 } else { 1557 if (!this._isSilentTranslationWarn(key) && !this._isSilentFallback(locale, key)) { 1558 warn(("Value of key '" + key + "' is not a string or function!")); 1559 } 1560 return null 1561 } 1562 } 1563 1564 // Check for the existence of links within the translated string 1565 if (isString(ret) && (ret.indexOf('@:') >= 0 || ret.indexOf('@.') >= 0)) { 1566 ret = this._link(locale, message, ret, host, 'raw', values, visitedLinkStack); 1567 } 1568 1569 return this._render(ret, interpolateMode, values, key) 1570 }; 1571 1572 VueI18n.prototype._link = function _link ( 1573 locale, 1574 message, 1575 str, 1576 host, 1577 interpolateMode, 1578 values, 1579 visitedLinkStack 1580 ) { 1581 var ret = str; 1582 1583 // Match all the links within the local 1584 // We are going to replace each of 1585 // them with its translation 1586 var matches = ret.match(linkKeyMatcher); 1587 1588 // eslint-disable-next-line no-autofix/prefer-const 1589 for (var idx in matches) { 1590 // ie compatible: filter custom array 1591 // prototype method 1592 if (!matches.hasOwnProperty(idx)) { 1593 continue 1594 } 1595 var link = matches[idx]; 1596 var linkKeyPrefixMatches = link.match(linkKeyPrefixMatcher); 1597 var linkPrefix = linkKeyPrefixMatches[0]; 1598 var formatterName = linkKeyPrefixMatches[1]; 1599 1600 // Remove the leading @:, @.case: and the brackets 1601 var linkPlaceholder = link.replace(linkPrefix, '').replace(bracketsMatcher, ''); 1602 1603 if (includes(visitedLinkStack, linkPlaceholder)) { 1604 { 1605 warn(("Circular reference found. \"" + link + "\" is already visited in the chain of " + (visitedLinkStack.reverse().join(' <- ')))); 1606 } 1607 return ret 1608 } 1609 visitedLinkStack.push(linkPlaceholder); 1610 1611 // Translate the link 1612 var translated = this._interpolate( 1613 locale, message, linkPlaceholder, host, 1614 interpolateMode === 'raw' ? 'string' : interpolateMode, 1615 interpolateMode === 'raw' ? undefined : values, 1616 visitedLinkStack 1617 ); 1618 1619 if (this._isFallbackRoot(translated)) { 1620 if (!this._isSilentTranslationWarn(linkPlaceholder)) { 1621 warn(("Fall back to translate the link placeholder '" + linkPlaceholder + "' with root locale.")); 1622 } 1623 /* istanbul ignore if */ 1624 if (!this._root) { throw Error('unexpected error') } 1625 var root = this._root.$i18n; 1626 translated = root._translate( 1627 root._getMessages(), root.locale, root.fallbackLocale, 1628 linkPlaceholder, host, interpolateMode, values 1629 ); 1630 } 1631 translated = this._warnDefault( 1632 locale, linkPlaceholder, translated, host, 1633 isArray(values) ? values : [values], 1634 interpolateMode 1635 ); 1636 1637 if (this._modifiers.hasOwnProperty(formatterName)) { 1638 translated = this._modifiers[formatterName](translated); 1639 } else if (defaultModifiers.hasOwnProperty(formatterName)) { 1640 translated = defaultModifiers[formatterName](translated); 1641 } 1642 1643 visitedLinkStack.pop(); 1644 1645 // Replace the link with the translated 1646 ret = !translated ? ret : ret.replace(link, translated); 1647 } 1648 1649 return ret 1650 }; 1651 1652 VueI18n.prototype._createMessageContext = function _createMessageContext (values, formatter, path, interpolateMode) { 1653 var this$1 = this; 1654 1655 var _list = isArray(values) ? values : []; 1656 var _named = isObject(values) ? values : {}; 1657 var list = function (index) { return _list[index]; }; 1658 var named = function (key) { return _named[key]; }; 1659 var messages = this._getMessages();
1660 var locale = this.locale; 1661 1662 return { 1663 list: list, 1664 named: named, 1665 values: values, 1666 formatter: formatter, 1667 path: path, 1668 messages: messages, 1669 locale: locale, 1670 linked: function (linkedKey) { return this$1._interpolate(locale, messages[locale] || {}, linkedKey, null, interpolateMode, undefined, [linkedKey]); } 1671 } 1672 }; 1673 1674 VueI18n.prototype._render = function _render (message, interpolateMode, values, path) { 1675 if (isFunction(message)) { 1676 return message( 1677 this._createMessageContext(values, this._formatter || defaultFormatter, path, interpolateMode) 1678 ) 1679 } 1680 1681 var ret = this._formatter.interpolate(message, values, path); 1682 1683 // If the custom formatter refuses to work - apply the default one 1684 if (!ret) { 1685 ret = defaultFormatter.interpolate(message, values, path); 1686 } 1687 1688 // if interpolateMode is **not** 'string' ('row'), 1689 // return the compiled data (e.g. ['foo', VNode, 'bar']) with formatter 1690 return interpolateMode === 'string' && !isString(ret) ? ret.join('') : ret 1691 }; 1692 1693 VueI18n.prototype._appendItemToChain = function _appendItemToChain (chain, item, blocks) { 1694 var follow = false; 1695 if (!includes(chain, item)) { 1696 follow = true; 1697 if (item) { 1698 follow = item[item.length - 1] !== '!'; 1699 item = item.replace(/!/g, ''); 1700 chain.push(item); 1701 if (blocks && blocks[item]) { 1702 follow = blocks[item]; 1703 } 1704 } 1705 } 1706 return follow 1707 }; 1708 1709 VueI18n.prototype._appendLocaleToChain = function _appendLocaleToChain (chain, locale, blocks) { 1710 var follow; 1711 var tokens = locale.split('-'); 1712 do { 1713 var item = tokens.join('-'); 1714 follow = this._appendItemToChain(chain, item, blocks); 1715 tokens.splice(-1, 1); 1716 } while (tokens.length && (follow === true)) 1717 return follow 1718 }; 1719 1720 VueI18n.prototype._appendBlockToChain = function _appendBlockToChain (chain, block, blocks) { 1721 var follow = true; 1722 for (var i = 0; (i < block.length) && (isBoolean(follow)); i++) { 1723 var locale = block[i]; 1724 if (isString(locale)) { 1725 follow = this._appendLocaleToChain(chain, locale, blocks); 1726 } 1727 } 1728 return follow 1729 }; 1730 1731 VueI18n.prototype._getLocaleChain = function _getLocaleChain (start, fallbackLocale) { 1732 if (start === '') { return [] } 1733 1734 if (!this._localeChainCache) { 1735 this._localeChainCache = {}; 1736 } 1737 1738 var chain = this._localeChainCache[start]; 1739 if (!chain) { 1740 if (!fallbackLocale) { 1741 fallbackLocale = this.fallbackLocale; 1742 } 1743 chain = []; 1744 1745 // first block defined by start 1746 var block = [start]; 1747 1748 // while any intervening block found 1749 while (isArray(block)) { 1750 block = this._appendBlockToChain( 1751 chain, 1752 block, 1753 fallbackLocale 1754 ); 1755 } 1756 1757 // last block defined by default 1758 var defaults; 1759 if (isArray(fallbackLocale)) { 1760 defaults = fallbackLocale; 1761 } else if (isObject(fallbackLocale)) { 1762 /* $FlowFixMe */ 1763 if (fallbackLocale['default']) { 1764 defaults = fallbackLocale['default']; 1765 } else { 1766 defaults = null; 1767 } 1768 } else { 1769 defaults = fallbackLocale; 1770 } 1771 1772 // convert defaults to array 1773 if (isString(defaults)) { 1774 block = [defaults]; 1775 } else { 1776 block = defaults; 1777 } 1778 if (block) { 1779 this._appendBlockToChain( 1780 chain, 1781 block, 1782 null 1783 ); 1784 } 1785 this._localeChainCache[start] = chain; 1786 } 1787 return chain 1788 }; 1789 1790 VueI18n.prototype._translate = function _translate ( 1791 messages, 1792 locale, 1793 fallback, 1794 key, 1795 host, 1796 interpolateMode, 1797 args 1798 ) { 1799 var chain = this._getLocaleChain(locale, fallback); 1800 var res; 1801 for (var i = 0; i < chain.length; i++) { 1802 var step = chain[i]; 1803 res = 1804 this._interpolate(step, messages[step], key, host, interpolateMode, args, [key]); 1805 if (!isNull(res)) { 1806 if (step !== locale && "development" !== 'production' && !this._isSilentTranslationWarn(key) && !this._isSilentFallbackWarn(key)) { 1807 warn(("Fall back to translate the keypath '" + key + "' with '" + step + "' locale.")); 1808 } 1809 return res 1810 } 1811 } 1812 return null 1813 }; 1814 1815 VueI18n.prototype._t = function _t (key, _locale, messages, host) { 1816 var ref; 1817 1818 var values = [], len = arguments.length - 4; 1819 while ( len-- > 0 ) values[ len ] = arguments[ len + 4 ]; 1820 if (!key) { return '' } 1821 1822 var parsedArgs = parseArgs.apply(void 0, values); 1823 if(this._escapeParameterHtml) { 1824 parsedArgs.params = escapeParams(parsedArgs.params); 1825 } 1826 1827 var locale = parsedArgs.locale || _locale; 1828 1829 var ret = this._translate( 1830 messages, locale, this.fallbackLocale, key, 1831 host, 'string', parsedArgs.params 1832 ); 1833 if (this._isFallbackRoot(ret)) { 1834 if (!this._isSilentTranslationWarn(key) && !this._isSilentFallbackWarn(key)) { 1835 warn(("Fall back to translate the keypath '" + key + "' with root locale.")); 1836 } 1837 /* istanbul ignore if */ 1838 if (!this._root) { throw Error('unexpected error') } 1839 return (ref = this._root).$t.apply(ref, [ key ].concat( values )) 1840 } else { 1841 ret = this._warnDefault(locale, key, ret, host, values, 'string'); 1842 if (this._postTranslation && ret !== null && ret !== undefined) { 1843 ret = this._postTranslation(ret, key); 1844 } 1845 return ret 1846 } 1847 }; 1848 1849 VueI18n.prototype.t = function t (key) { 1850 var ref; 1851 1852 var values = [], len = arguments.length - 1; 1853 while ( len-- > 0 ) values[ len ] = arguments[ len + 1 ]; 1854 return (ref = this)._t.apply(ref, [ key, this.locale, this._getMessages(), null ].concat( values )) 1855 }; 1856 1857 VueI18n.prototype._i = function _i (key, locale, messages, host, values) { 1858 var ret = 1859 this._translate(messages, locale, this.fallbackLocale, key, host, 'raw', values); 1860 if (this._isFallbackRoot(ret)) { 1861 if (!this._isSilentTranslationWarn(key)) { 1862 warn(("Fall back to interpolate the keypath '" + key + "' with root locale.")); 1863 } 1864 if (!this._root) { throw Error('unexpected error') } 1865 return this._root.$i18n.i(key, locale, values) 1866 } else { 1867 return this._warnDefault(locale, key, ret, host, [values], 'raw') 1868 } 1869 }; 1870 1871 VueI18n.prototype.i = function i (key, locale, values) { 1872 /* istanbul ignore if */ 1873 if (!key) { return '' } 1874 1875 if (!isString(locale)) { 1876 locale = this.locale; 1877 } 1878 1879 return this._i(key, locale, this._getMessages(), null, values) 1880 }; 1881 1882 VueI18n.prototype._tc = function _tc ( 1883 key, 1884 _locale, 1885 messages, 1886 host, 1887 choice 1888 ) { 1889 var ref; 1890 1891 var values = [], len = arguments.length - 5; 1892 while ( len-- > 0 ) values[ len ] = arguments[ len + 5 ]; 1893 if (!key) { return '' } 1894 if (choice === undefined) { 1895 choice = 1; 1896 } 1897 1898 var predefined = { 'count': choice, 'n': choice }; 1899 var parsedArgs = parseArgs.apply(void 0, values); 1900 parsedArgs.params = Object.assign(predefined, parsedArgs.params); 1901 values = parsedArgs.locale === null ? [parsedArgs.params] : [parsedArgs.locale, parsedArgs.params]; 1902 return this.fetchChoice((ref = this)._t.apply(ref, [ key, _locale, messages, host ].concat( values )), choice) 1903 }; 1904 1905 VueI18n.prototype.fetchChoice = function fetchChoice (message, choice) { 1906 /* istanbul ignore if */ 1907 if (!message || !isString(message)) { return null } 1908 var choices = message.split('|'); 1909 1910 choice = this.getChoiceIndex(choice, choices.length); 1911 if (!choices[choice]) { return message } 1912 return choices[choice].trim() 1913 }; 1914 1915 VueI18n.prototype.tc = function tc (key, choice) { 1916 var ref; 1917 1918 var values = [], len = arguments.length - 2; 1919 while ( len-- > 0 ) values[ len ] = arguments[ len + 2 ]; 1920 return (ref = this)._tc.apply(ref, [ key, this.locale, this._getMessages(), null, choice ].concat( values )) 1921 }; 1922 1923 VueI18n.prototype._te = function _te (key, locale, messages) { 1924 var args = [], len = arguments.length - 3; 1925 while ( len-- > 0 ) args[ len ] = arguments[ len + 3 ]; 1926 1927 var _locale = parseArgs.apply(void 0, args).locale || locale; 1928 return this._exist(messages[_locale], key) 1929 }; 1930 1931 VueI18n.prototype.te = function te (key, locale) { 1932 return this._te(key, this.locale, this._getMessages(), locale) 1933 }; 1934 1935 VueI18n.prototype.getLocaleMessage = function getLocaleMessage (locale) { 1936 return looseClone(this._vm.messages[locale] || {}) 1937 }; 1938 1939 VueI18n.prototype.setLocaleMessage = function setLocaleMessage (locale, message) { 1940 if (this._warnHtmlInMessage === 'warn' || this._warnHtmlInMessage === 'error') { 1941 this._checkLocaleMessage(locale, this._warnHtmlInMessage, message); 1942 } 1943 this._vm.$set(this._vm.messages, locale, message); 1944 }; 1945 1946 VueI18n.prototype.mergeLocaleMessage = function mergeLocaleMessage (locale, message) { 1947 if (this._warnHtmlInMessage === 'warn' || this._warnHtmlInMessage === 'error') { 1948 this._checkLocaleMessage(locale, this._warnHtmlInMessage, message); 1949 } 1950 this._vm.$set(this._vm.messages, locale, merge( 1951 typeof this._vm.messages[locale] !== 'undefined' && Object.keys(this._vm.messages[locale]).length 1952 ? Object.assign({}, this._vm.messages[locale]) 1953 : {}, 1954 message 1955 )); 1956 }; 1957 1958 VueI18n.prototype.getDateTimeFormat = function getDateTimeFormat (locale) { 1959 return looseClone(this._vm.dateTimeFormats[locale] || {}) 1960 }; 1961 1962 VueI18n.prototype.setDateTimeFormat = function setDateTimeFormat (locale, format) { 1963 this._vm.$set(this._vm.dateTimeFormats, locale, format); 1964 this._clearDateTimeFormat(locale, format); 1965 }; 1966 1967 VueI18n.prototype.mergeDateTimeFormat = function mergeDateTimeFormat (locale, format) { 1968 this._vm.$set(this._vm.dateTimeFormats, locale, merge(this._vm.dateTimeFormats[locale] || {}, format)); 1969 this._clearDateTimeFormat(locale, format); 1970 }; 1971 1972 VueI18n.prototype._clearDateTimeFormat = function _clearDateTimeFormat (locale, format) { 1973 // eslint-disable-next-line no-autofix/prefer-const 1974 for (var key in format) { 1975 var id = locale + "__" + key; 1976 1977 if (!this._dateTimeFormatters.hasOwnProperty(id)) { 1978 continue 1979 } 1980 1981 delete this._dateTimeFormatters[id]; 1982 } 1983 }; 1984 1985 VueI18n.prototype._localizeDateTime = function _localizeDateTime ( 1986 value, 1987 locale, 1988 fallback, 1989 dateTimeFormats, 1990 key 1991 ) { 1992 var _locale = locale; 1993 var formats = dateTimeFormats[_locale]; 1994 1995 var chain = this._getLocaleChain(locale, fallback); 1996 for (var i = 0; i < chain.length; i++) { 1997 var current = _locale; 1998 var step = chain[i]; 1999 formats = dateTimeFormats[step]; 2000 _locale = step; 2001 // fallback locale 2002 if (isNull(formats) || isNull(formats[key])) { 2003 if (step !== locale && "development" !== 'production' && !this._isSilentTranslationWarn(key) && !this._isSilentFallbackWarn(key)) { 2004 warn(("Fall back to '" + step + "' datetime formats from '" + current + "' datetime formats.")); 2005 } 2006 } else { 2007 break 2008 } 2009 } 2010 2011 if (isNull(formats) || isNull(formats[key])) { 2012 return null 2013 } else { 2014 var format = formats[key]; 2015 var id = _locale + "__" + key; 2016 var formatter = this._dateTimeFormatters[id]; 2017 if (!formatter) { 2018 formatter = this._dateTimeFormatters[id] = new Intl.DateTimeFormat(_locale, format); 2019 } 2020 return formatter.format(value) 2021 } 2022 }; 2023 2024 VueI18n.prototype._d = function _d (value, locale, key) { 2025 /* istanbul ignore if */ 2026 if (!VueI18n.availabilities.dateTimeFormat) { 2027 warn('Cannot format a Date value due to not supported Intl.DateTimeFormat.'); 2028 return '' 2029 } 2030 2031 if (!key) { 2032 return new Intl.DateTimeFormat(locale).format(value) 2033 } 2034 2035 var ret = 2036 this._localizeDateTime(value, locale, this.fallbackLocale, this._getDateTimeFormats(), key); 2037 if (this._isFallbackRoot(ret)) { 2038 if (!this._isSilentTranslationWarn(key) && !this._isSilentFallbackWarn(key)) { 2039 warn(("Fall back to datetime localization of root: key '" + key + "'.")); 2040 } 2041 /* istanbul ignore if */ 2042 if (!this._root) { throw Error('unexpected error') } 2043 return this._root.$i18n.d(value, key, locale) 2044 } else { 2045 return ret || '' 2046 } 2047 }; 2048 2049 VueI18n.prototype.d = function d (value) { 2050 var args = [], len = arguments.length - 1; 2051 while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; 2052 2053 var locale = this.locale; 2054 var key = null; 2055 2056 if (args.length === 1) { 2057 if (isString(args[0])) { 2058 key = args[0]; 2059 } else if (isObject(args[0])) { 2060 if (args[0].locale) { 2061 locale = args[0].locale; 2062 } 2063 if (args[0].key) { 2064 key = args[0].key; 2065 } 2066 } 2067 } else if (args.length === 2) { 2068 if (isString(args[0])) { 2069 key = args[0]; 2070 } 2071 if (isString(args[1])) { 2072 locale = args[1]; 2073 } 2074 } 2075 2076 return this._d(value, locale, key) 2077 }; 2078 2079 VueI18n.prototype.getNumberFormat = function getNumberFormat (locale) { 2080 return looseClone(this._vm.numberFormats[locale] || {}) 2081 }; 2082 2083 VueI18n.prototype.setNumberFormat = function setNumberFormat (locale, format) { 2084 this._vm.$set(this._vm.numberFormats, locale, format); 2085 this._clearNumberFormat(locale, format); 2086 }; 2087 2088 VueI18n.prototype.mergeNumberFormat = function mergeNumberFormat (locale, format) { 2089 this._vm.$set(this._vm.numberFormats, locale, merge(this._vm.numberFormats[locale] || {}, format)); 2090 this._clearNumberFormat(locale, format); 2091 }; 2092 2093 VueI18n.prototype._clearNumberFormat = function _clearNumberFormat (locale, format) { 2094 // eslint-disable-next-line no-autofix/prefer-const 2095 for (var key in format) { 2096 var id = locale + "__" + key; 2097 2098 if (!this._numberFormatters.hasOwnProperty(id)) { 2099 continue 2100 } 2101 2102 delete this._numberFormatters[id]; 2103 } 2104 }; 2105 2106 VueI18n.prototype._getNumberFormatter = function _getNumberFormatter ( 2107 value, 2108 locale, 2109 fallback, 2110 numberFormats, 2111 key,
2112 options 2113 ) { 2114 var _locale = locale; 2115 var formats = numberFormats[_locale]; 2116 2117 var chain = this._getLocaleChain(locale, fallback); 2118 for (var i = 0; i < chain.length; i++) { 2119 var current = _locale; 2120 var step = chain[i]; 2121 formats = numberFormats[step]; 2122 _locale = step; 2123 // fallback locale 2124 if (isNull(formats) || isNull(formats[key])) { 2125 if (step !== locale && "development" !== 'production' && !this._isSilentTranslationWarn(key) && !this._isSilentFallbackWarn(key)) { 2126 warn(("Fall back to '" + step + "' number formats from '" + current + "' number formats.")); 2127 } 2128 } else { 2129 break 2130 } 2131 } 2132 2133 if (isNull(formats) || isNull(formats[key])) { 2134 return null 2135 } else { 2136 var format = formats[key]; 2137 2138 var formatter; 2139 if (options) { 2140 // If options specified - create one time number formatter 2141 formatter = new Intl.NumberFormat(_locale, Object.assign({}, format, options)); 2142 } else { 2143 var id = _locale + "__" + key; 2144 formatter = this._numberFormatters[id]; 2145 if (!formatter) { 2146 formatter = this._numberFormatters[id] = new Intl.NumberFormat(_locale, format); 2147 } 2148 } 2149 return formatter 2150 } 2151 }; 2152 2153 VueI18n.prototype._n = function _n (value, locale, key, options) { 2154 /* istanbul ignore if */ 2155 if (!VueI18n.availabilities.numberFormat) { 2156 { 2157 warn('Cannot format a Number value due to not supported Intl.NumberFormat.'); 2158 } 2159 return '' 2160 } 2161 2162 if (!key) { 2163 var nf = !options ? new Intl.NumberFormat(locale) : new Intl.NumberFormat(locale, options); 2164 return nf.format(value) 2165 } 2166 2167 var formatter = this._getNumberFormatter(value, locale, this.fallbackLocale, this._getNumberFormats(), key, options); 2168 var ret = formatter && formatter.format(value); 2169 if (this._isFallbackRoot(ret)) { 2170 if (!this._isSilentTranslationWarn(key) && !this._isSilentFallbackWarn(key)) { 2171 warn(("Fall back to number localization of root: key '" + key + "'.")); 2172 } 2173 /* istanbul ignore if */ 2174 if (!this._root) { throw Error('unexpected error') } 2175 return this._root.$i18n.n(value, Object.assign({}, { key: key, locale: locale }, options)) 2176 } else { 2177 return ret || '' 2178 } 2179 }; 2180 2181 VueI18n.prototype.n = function n (value) { 2182 var args = [], len = arguments.length - 1; 2183 while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; 2184 2185 var locale = this.locale; 2186 var key = null; 2187 var options = null; 2188 2189 if (args.length === 1) { 2190 if (isString(args[0])) { 2191 key = args[0]; 2192 } else if (isObject(args[0])) { 2193 if (args[0].locale) { 2194 locale = args[0].locale; 2195 } 2196 if (args[0].key) { 2197 key = args[0].key; 2198 } 2199 2200 // Filter out number format options only 2201 options = Object.keys(args[0]).reduce(function (acc, key) { 2202 var obj; 2203 2204 if (includes(numberFormatKeys, key)) { 2205 return Object.assign({}, acc, ( obj = {}, obj[key] = args[0][key], obj )) 2206 } 2207 return acc 2208 }, null); 2209 } 2210 } else if (args.length === 2) { 2211 if (isString(args[0])) { 2212 key = args[0]; 2213 } 2214 if (isString(args[1])) { 2215 locale = args[1]; 2216 } 2217 } 2218 2219 return this._n(value, locale, key, options) 2220 }; 2221 2222 VueI18n.prototype._ntp = function _ntp (value, locale, key, options) { 2223 /* istanbul ignore if */ 2224 if (!VueI18n.availabilities.numberFormat) { 2225 { 2226 warn('Cannot format to parts a Number value due to not supported Intl.NumberFormat.'); 2227 } 2228 return [] 2229 } 2230 2231 if (!key) { 2232 var nf = !options ? new Intl.NumberFormat(locale) : new Intl.NumberFormat(locale, options); 2233 return nf.formatToParts(value) 2234 } 2235 2236 var formatter = this._getNumberFormatter(value, locale, this.fallbackLocale, this._getNumberFormats(), key, options); 2237 var ret = formatter && formatter.formatToParts(value); 2238 if (this._isFallbackRoot(ret)) { 2239 if (!this._isSilentTranslationWarn(key)) { 2240 warn(("Fall back to format number to parts of root: key '" + key + "' .")); 2241 } 2242 /* istanbul ignore if */ 2243 if (!this._root) { throw Error('unexpected error') } 2244 return this._root.$i18n._ntp(value, locale, key, options) 2245 } else { 2246 return ret || [] 2247 } 2248 }; 2249
2250 Object.defineProperties( VueI18n.prototype, prototypeAccessors ); 2251 2252 var availabilities; 2253 // $FlowFixMe 2254 Object.defineProperty(VueI18n, 'availabilities', { 2255 get: function get () { 2256 if (!availabilities) { 2257 var intlDefined = typeof Intl !== 'undefined'; 2258 availabilities = { 2259 dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined', 2260 numberFormat: intlDefined && typeof Intl.NumberFormat !== 'undefined' 2261 }; 2262 } 2263 2264 return availabilities 2265 } 2266 }); 2267 2268 VueI18n.install = install; 2269 VueI18n.version = '8.27.0'; 2270 2271 return VueI18n; 2272 2273})));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.