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