vue-i18n 11.4.21 → 11.4.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vue-i18n v11.4.21
2
+ * vue-i18n v11.4.23
3
3
  * (c) 2026 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -334,6 +334,169 @@ var VueI18n = (function (exports, Vue) {
334
334
  const valueQuote = quote || '';
335
335
  return `${name}=${valueQuote}${sanitizeAttributeValue(attrName, value)}${valueQuote}`;
336
336
  }
337
+ const HTML = 0;
338
+ const SVG = 1;
339
+ const MATHML = 2;
340
+ // Elements that have no end tag, and elements that the HTML parser does not open in the body
341
+ const notOpenedElementPattern = /^(?:area|base|basefont|bgsound|br|col|embed|frame|hr|image|img|input|keygen|link|meta|param|source|track|wbr|html|head|body|frameset)$/;
342
+ // Start tags that end SVG and MathML content (and `<font>` with `color`, `face` or `size`)
343
+ const breakoutElementPattern = /^(?:b|big|blockquote|body|br|center|code|dd|div|dl|dt|em|embed|h[1-6]|head|hr|i|img|li|listing|menu|meta|nobr|ol|p|pre|ruby|s|small|span|strong|strike|sub|sup|table|tt|u|ul|var)$/;
344
+ // Start tags that close an open `<p>`, and the elements that they do not close a `<p>` through
345
+ const paragraphClosingElementPattern = /^(?:address|article|aside|blockquote|center|details|dialog|dir|div|dl|fieldset|figcaption|figure|footer|header|hgroup|main|menu|nav|ol|p|search|section|summary|ul|h[1-6]|pre|listing|form|li|dd|dt|plaintext|table|hr|xmp)$/;
346
+ const buttonScopeElementPattern = /^(?:applet|caption|html|table|td|th|marquee|object|template|button)$/;
347
+ const svgIntegrationPattern = /^(?:foreignobject|desc|title)$/;
348
+ // The names of SVG and MathML integration points (except `title`, whose content is text in HTML). Read with the
349
+ // HTML rules, they are unknown HTML elements, and their start tags become text: if the browser closed such an
350
+ // element early (for example, `<button>` of the translation closes the `<button>` that the translation is
351
+ // rendered in), its end tag would close an integration point of the page, and the rest of the page would be read
352
+ // as SVG or MathML
353
+ const integrationNamePattern = /^(?:foreignobject|desc|mi|mo|mn|ms|mtext|annotation-xml)$/;
354
+ const mathmlIntegrationPattern = /^(?:mi|mo|mn|ms|mtext)$/;
355
+ const htmlEncodingPattern = /^(?:text\/html|application\/xhtml\+xml)$/i;
356
+ function asciiLowercase(text) {
357
+ return text.replace(/[A-Z]+/g, upper => upper.toLowerCase());
358
+ }
359
+ // Whether a start tag is read with the rules of SVG and MathML content, rather than with the HTML rules
360
+ function isForeignContext(top, name) {
361
+ return (!!top &&
362
+ top.namespace !== HTML &&
363
+ (!top.integration ||
364
+ (mathmlIntegrationPattern.test(top.name) &&
365
+ (name === 'mglyph' || name === 'malignmark'))) &&
366
+ !(top.name === 'annotation-xml' && name === 'svg'));
367
+ }
368
+ function isBreakout(name, attributes) {
369
+ return (breakoutElementPattern.test(name) ||
370
+ (name === 'font' &&
371
+ (attributes.has('color') ||
372
+ attributes.has('face') ||
373
+ attributes.has('size'))));
374
+ }
375
+ // Pop the elements down to `length`, and return their end tags (innermost first).
376
+ // A `<form>` becomes text instead: in a form of the page, browsers ignore the `<form>`,
377
+ // and `</form>` would close the form of the page
378
+ function closeDownTo(stack, length, parts) {
379
+ let endTags = '';
380
+ for (let index = stack.length - 1; index >= length; index--) {
381
+ const element = stack[index];
382
+ if (element.namespace === HTML && element.name === 'form') {
383
+ parts[element.part] = escapeLessThan(parts[element.part]);
384
+ }
385
+ else {
386
+ endTags += `</${element.name}>`;
387
+ }
388
+ }
389
+ stack.length = length;
390
+ return endTags;
391
+ }
392
+ // Pop SVG and MathML elements down to an HTML element or an integration point, as the tree builder does,
393
+ // and return their end tags
394
+ function closeForeign(stack, parts) {
395
+ let length = stack.length;
396
+ while (length > 0 &&
397
+ stack[length - 1].namespace !== HTML &&
398
+ !stack[length - 1].integration) {
399
+ length--;
400
+ }
401
+ return closeDownTo(stack, length, parts);
402
+ }
403
+ /**
404
+ * Open an element for a start tag, as the tree builder does
405
+ *
406
+ * @returns The end tags to write before the start tag: the SVG and MathML elements that it ends, and a `<p>`
407
+ * of the translation that it closes, with the elements in the `<p>` (so that no formatting element in it is
408
+ * made again after it), or `undefined` when the start tag becomes text
409
+ */
410
+ function openElement(stack, parts, name, attributes, selfClosing) {
411
+ // the start tag is written after the end tags
412
+ const part = parts.length + 1;
413
+ let endTags = '';
414
+ const top = stack[stack.length - 1];
415
+ if (isForeignContext(top, name)) {
416
+ if (!isBreakout(name, attributes)) {
417
+ if (!selfClosing) {
418
+ stack.push({
419
+ name,
420
+ namespace: top.namespace,
421
+ integration: top.namespace === SVG
422
+ ? svgIntegrationPattern.test(name)
423
+ : mathmlIntegrationPattern.test(name) ||
424
+ (name === 'annotation-xml' &&
425
+ htmlEncodingPattern.test((attributes.get('encoding') || '').replace(numericCharacterReferencePattern, decodeNumericCharacterReference))),
426
+ part
427
+ });
428
+ }
429
+ return endTags;
430
+ }
431
+ endTags = closeForeign(stack, parts);
432
+ }
433
+ if (paragraphClosingElementPattern.test(name)) {
434
+ for (let index = stack.length - 1; index >= 0; index--) {
435
+ const element = stack[index];
436
+ if (element.namespace === HTML
437
+ ? buttonScopeElementPattern.test(element.name)
438
+ : element.integration) {
439
+ break;
440
+ }
441
+ if (element.namespace === HTML && element.name === 'p') {
442
+ endTags += closeDownTo(stack, index, parts);
443
+ break;
444
+ }
445
+ }
446
+ }
447
+ if (integrationNamePattern.test(name)) {
448
+ return;
449
+ }
450
+ if (name === 'svg' || name === 'math') {
451
+ if (!selfClosing) {
452
+ stack.push({
453
+ name,
454
+ namespace: name === 'svg' ? SVG : MATHML,
455
+ integration: false,
456
+ part
457
+ });
458
+ }
459
+ }
460
+ else if (!notOpenedElementPattern.test(name)) {
461
+ // HTML elements ignore `/>`
462
+ stack.push({ name, namespace: HTML, integration: false, part });
463
+ }
464
+ return endTags;
465
+ }
466
+ /**
467
+ * Close the element of an end tag: an SVG or MathML element with the same name above the innermost HTML
468
+ * element, or else an HTML element with the same name
469
+ *
470
+ * @returns The end tags to write before the end tag (of the elements in the closed element), or `undefined`
471
+ * when the end tag closes nothing in the translation, and is removed
472
+ */
473
+ function closeElement(stack, parts, name) {
474
+ let endTags = '';
475
+ if (name === 'p' || name === 'br') {
476
+ // they end SVG and MathML content
477
+ endTags = closeForeign(stack, parts);
478
+ }
479
+ let index = stack.length - 1;
480
+ while (index >= 0 &&
481
+ stack[index].namespace !== HTML &&
482
+ stack[index].name !== name) {
483
+ index--;
484
+ }
485
+ if (index >= 0 && stack[index].namespace !== HTML) ;
486
+ else {
487
+ while (index >= 0 &&
488
+ !(stack[index].namespace === HTML && stack[index].name === name)) {
489
+ index--;
490
+ }
491
+ }
492
+ if (index < 0) {
493
+ // browsers read `</br>` as `<br>`, and `</p>` without an open `<p>` as `<p></p>`
494
+ return name === 'br' || name === 'p' ? endTags : undefined;
495
+ }
496
+ endTags += closeDownTo(stack, index + 1, parts);
497
+ stack.length = index;
498
+ return endTags;
499
+ }
337
500
  /**
338
501
  * Read a tag with the rules of the HTML tokenizer.
339
502
  * A start tag is written again with its attributes sanitized, and an end tag is kept as it is
@@ -341,7 +504,8 @@ var VueI18n = (function (exports, Vue) {
341
504
  * @param html - The HTML
342
505
  * @param start - The index of `<`
343
506
  * @param neutralized - What has been neutralized
344
- * @returns The tag, the tag name, and the index after the tag (-1 when the tag is not closed),
507
+ * @returns The tag, the tag name, the index after the tag (-1 when the tag is not closed),
508
+ * whether the start tag is self-closing (`/>`), and the attributes of the start tag,
345
509
  * or `undefined` when `<` does not start a tag
346
510
  */
347
511
  function readTag(html, start, neutralized) {
@@ -352,6 +516,7 @@ var VueI18n = (function (exports, Vue) {
352
516
  }
353
517
  const [, slash, tagName] = tagStart;
354
518
  let tag = tagStart[0];
519
+ const attributes = new Map();
355
520
  let step;
356
521
  tagStepPattern.lastIndex = tagStartPattern.lastIndex;
357
522
  while ((step = tagStepPattern.exec(html))) {
@@ -359,17 +524,27 @@ var VueI18n = (function (exports, Vue) {
359
524
  if (close) {
360
525
  const end = tagStepPattern.lastIndex;
361
526
  // browsers ignore the attributes of end tags
362
- return [slash ? html.slice(start, end) : tag + raw, tagName, end];
527
+ return [
528
+ slash ? html.slice(start, end) : tag + raw,
529
+ tagName,
530
+ end,
531
+ !slash && separator.endsWith('/'),
532
+ attributes
533
+ ];
363
534
  }
364
535
  if (quote && !closingQuote) {
365
536
  break;
366
537
  }
367
538
  if (!slash) {
368
539
  const value = quote ? quotedValue : unquotedValue;
540
+ const name = asciiLowercase(attrName);
541
+ if (!attributes.has(name)) {
542
+ attributes.set(name, value || '');
543
+ }
369
544
  tag += separator + serializeAttribute(attrName, value, quote, neutralized);
370
545
  }
371
546
  }
372
- return [tag, tagName, -1];
547
+ return [tag, tagName, -1, false, attributes];
373
548
  }
374
549
  /**
375
550
  * Find the end tag of an element whose content is text, as the HTML tokenizer does:
@@ -394,57 +569,79 @@ var VueI18n = (function (exports, Vue) {
394
569
  * where each tag and each attribute starts and ends, and every attribute of every start tag is checked.
395
570
  * What is still open at the end of the string (a tag, a comment, or an element whose content is text,
396
571
  * like `<textarea>`) becomes text: on the server (SSR), the rest of the page follows the translation,
397
- * and it would be read as a part of what is open
572
+ * and it would be read as a part of what is open.
573
+ * For the same reason, the elements are followed as the tree builder of browsers opens and closes them,
574
+ * including SVG and MathML: an end tag that closes no element of the translation is removed, the elements
575
+ * in the element that an end tag closes are closed before it, and the elements still open at the end are
576
+ * closed. A `<form>` that the translation does not close becomes text, because browsers ignore it in a form
577
+ * of the page, and `</form>` would close that form
398
578
  *
399
579
  * @param html - The translated HTML
400
580
  * @returns The sanitized HTML
401
581
  */
402
582
  function sanitizeTranslatedHtml(html) {
403
583
  const neutralized = {};
404
- let result = '';
584
+ const parts = [];
585
+ const stack = [];
405
586
  let index = 0;
406
587
  let lessThan;
407
588
  while ((lessThan = html.indexOf('<', index)) !== -1) {
408
- result += html.slice(index, lessThan);
589
+ parts.push(html.slice(index, lessThan));
409
590
  index = lessThan + 1;
410
591
  const read = readTag(html, lessThan, neutralized);
411
592
  if (read) {
412
- const [tag, tagName, end] = read;
593
+ const [tag, tagName, end, selfClosing, attributes] = read;
413
594
  if (end === -1) {
414
595
  neutralized.unclosed = true;
415
- result += escapeLessThan(html.slice(lessThan));
596
+ parts.push(escapeLessThan(html.slice(lessThan)));
416
597
  index = html.length;
417
598
  break;
418
599
  }
419
600
  index = end;
420
601
  if (tag[1] === '/') {
421
- result += tag;
602
+ const endTags = closeElement(stack, parts, asciiLowercase(tagName));
603
+ if (endTags === undefined) {
604
+ neutralized.closed = true;
605
+ }
606
+ else {
607
+ if (endTags) {
608
+ neutralized.closed = true;
609
+ }
610
+ parts.push(endTags + tag);
611
+ }
422
612
  }
423
613
  else if (dangerousElementPattern.test(tagName)) {
424
614
  // the start tag becomes text
425
615
  neutralized.element = true;
426
- result += escapeLessThan(tag);
616
+ parts.push(escapeLessThan(tag));
427
617
  }
428
- else if (textContentElementPattern.test(tagName)) {
429
- const contentEnd = findTextContentEnd(html, end, tagName);
430
- if (contentEnd === -1) {
431
- // the start tag becomes text, and the content is read as HTML, as browsers do then
432
- neutralized.unclosed = true;
433
- result += escapeLessThan(tag);
618
+ else {
619
+ let content = '';
620
+ if (textContentElementPattern.test(tagName)) {
621
+ const contentEnd = findTextContentEnd(html, end, tagName);
622
+ if (contentEnd === -1) {
623
+ // the start tag becomes text, and the content is read as HTML, as browsers do then
624
+ neutralized.unclosed = true;
625
+ parts.push(escapeLessThan(tag));
626
+ continue;
627
+ }
628
+ content = escapeLessThan(html.slice(end, contentEnd));
629
+ index = contentEnd;
630
+ }
631
+ const endTags = openElement(stack, parts, asciiLowercase(tagName), attributes, selfClosing);
632
+ if (endTags === undefined) {
633
+ neutralized.closed = true;
634
+ parts.push(escapeLessThan(tag) + content);
434
635
  }
435
636
  else {
436
- result += tag + escapeLessThan(html.slice(end, contentEnd));
437
- index = contentEnd;
637
+ parts.push(endTags, tag + content);
438
638
  }
439
639
  }
440
- else {
441
- result += tag;
442
- }
443
640
  continue;
444
641
  }
445
642
  commentPattern.lastIndex = lessThan;
446
643
  if (commentPattern.test(html)) {
447
- result += html.slice(lessThan, commentPattern.lastIndex);
644
+ parts.push(html.slice(lessThan, commentPattern.lastIndex));
448
645
  index = commentPattern.lastIndex;
449
646
  continue;
450
647
  }
@@ -452,9 +649,21 @@ var VueI18n = (function (exports, Vue) {
452
649
  neutralized.unclosed = true;
453
650
  }
454
651
  // `<!DOCTYPE`, `<![CDATA[`, `<?`, `</` without a tag name, `<` at the end and any other `<` become text
455
- result += '&lt;';
652
+ parts.push('&lt;');
653
+ }
654
+ parts.push(html.slice(index));
655
+ // close the elements that are still open
656
+ for (let open = stack.length - 1; open >= 0; open--) {
657
+ const element = stack[open];
658
+ neutralized.closed = true;
659
+ if (element.namespace === HTML && element.name === 'form') {
660
+ // the browser ignores `<form>` in a form of the page, and `</form>` would close that form
661
+ parts[element.part] = escapeLessThan(parts[element.part]);
662
+ }
663
+ else {
664
+ parts.push(`</${element.name}>`);
665
+ }
456
666
  }
457
- result += html.slice(index);
458
667
  {
459
668
  if (neutralized.eventHandler) {
460
669
  warn('Potentially dangerous event handlers detected in translation. ' +
@@ -472,8 +681,12 @@ var VueI18n = (function (exports, Vue) {
472
681
  warn('Unclosed tag, comment or element (such as <textarea>) detected in translation. ' +
473
682
  'Consider closing it in your translation messages.');
474
683
  }
684
+ if (neutralized.closed) {
685
+ warn('Unclosed or misnested elements detected in translation. ' +
686
+ 'Consider closing every element in the right order in your translation messages.');
687
+ }
475
688
  }
476
- return result;
689
+ return parts.join('');
477
690
  }
478
691
 
479
692
  /**
@@ -1335,7 +1548,7 @@ var VueI18n = (function (exports, Vue) {
1335
1548
  * Intlify core-base version
1336
1549
  * @internal
1337
1550
  */
1338
- const VERSION$1 = '11.4.21';
1551
+ const VERSION$1 = '11.4.23';
1339
1552
  const NOT_REOSLVED = -1;
1340
1553
  const DEFAULT_LOCALE = 'en-US';
1341
1554
  const MISSING_RESOLVE_VALUE = '';
@@ -2473,7 +2686,7 @@ var VueI18n = (function (exports, Vue) {
2473
2686
  *
2474
2687
  * @VueI18nGeneral
2475
2688
  */
2476
- const VERSION = '11.4.21';
2689
+ const VERSION = '11.4.23';
2477
2690
  /**
2478
2691
  * This is only called development env
2479
2692
  * istanbul-ignore-next
@@ -2748,6 +2961,34 @@ var VueI18n = (function (exports, Vue) {
2748
2961
  return Vue.getCurrentInstance();
2749
2962
  }
2750
2963
  }
2964
+ /**
2965
+ * Get the effect scope of a component instance.
2966
+ *
2967
+ * Every component instance has one, but it is not in the published types of Vue.
2968
+ */
2969
+ function getInstanceScope(instance) {
2970
+ return instance.scope;
2971
+ }
2972
+ /**
2973
+ * Run `fn` when the effect scope of a component instance stops.
2974
+ *
2975
+ * Vue stops this scope when it unmounts the component, and also when
2976
+ * `<Suspense>` discards a pending branch. In the second case, Vue drops the
2977
+ * post-render jobs of the branch, so `onUnmounted` hooks never run.
2978
+ *
2979
+ * If the scope has already stopped, `fn` runs right away. This happens when
2980
+ * `<Suspense>` discards a component while its async `setup()` is waiting,
2981
+ * and the `setup()` continues after the `await`.
2982
+ */
2983
+ function onInstanceScopeDispose(instance, fn) {
2984
+ const scope = getInstanceScope(instance);
2985
+ if (scope.active) {
2986
+ scope.run(() => Vue.onScopeDispose(fn));
2987
+ }
2988
+ else {
2989
+ fn();
2990
+ }
2991
+ }
2751
2992
  /* eslint-enable @typescript-eslint/no-explicit-any */
2752
2993
 
2753
2994
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -4246,6 +4487,18 @@ var VueI18n = (function (exports, Vue) {
4246
4487
  this.$n = (...args) => this.$i18n.n(...args);
4247
4488
  this.$tm = (key) => this.$i18n.tm(key);
4248
4489
  i18n.__setInstance(instance, this.$i18n);
4490
+ // Clean up also when the effect scope of the component stops.
4491
+ // `<Suspense>` stops the scope of a component in a discarded pending
4492
+ // branch, but drops its `unmounted` hooks (#2795).
4493
+ const vueI18n = this.$i18n;
4494
+ onInstanceScopeDispose(instance, () => {
4495
+ if (vueI18n.__disposer) {
4496
+ vueI18n.__disposer();
4497
+ delete vueI18n.__disposer;
4498
+ delete vueI18n.__extender;
4499
+ }
4500
+ i18n.__deleteInstance(instance);
4501
+ });
4249
4502
  },
4250
4503
  mounted() {
4251
4504
  /* istanbul ignore if */
@@ -4622,9 +4875,15 @@ var VueI18n = (function (exports, Vue) {
4622
4875
  const register = (el, binding) => {
4623
4876
  const [textContent, composer] = _process(binding);
4624
4877
  if (inBrowser) {
4625
- el.__i18nWatcher = Vue.watch(composer.locale, () => {
4626
- binding.instance && binding.instance.$forceUpdate();
4627
- });
4878
+ // Create the watcher in the effect scope of the component, so that it
4879
+ // also stops when `<Suspense>` discards a pending branch and drops the
4880
+ // `unmounted` hook of this directive (#2795).
4881
+ const scope = getInstanceScope(binding.instance.$);
4882
+ if (scope.active) {
4883
+ el.__i18nWatcher = scope.run(() => Vue.watch(composer.locale, () => {
4884
+ binding.instance && binding.instance.$forceUpdate();
4885
+ }));
4886
+ }
4628
4887
  }
4629
4888
  el.__composer = composer;
4630
4889
  el.textContent = textContent;
@@ -4926,8 +5185,8 @@ var VueI18n = (function (exports, Vue) {
4926
5185
  composer[DisposeSymbol] =
4927
5186
  i18nInternal.__composerExtend(composer);
4928
5187
  }
4929
- setupLifeCycle(i18nInternal, instance, composer);
4930
5188
  i18nInternal.__setInstance(instance, composer);
5189
+ setupLifeCycle(i18nInternal, instance, composer);
4931
5190
  }
4932
5191
  else {
4933
5192
  if (scope === 'local') {
@@ -5031,7 +5290,10 @@ var VueI18n = (function (exports, Vue) {
5031
5290
  emitter.on('*', addTimelineEvent);
5032
5291
  }
5033
5292
  }, target);
5034
- Vue.onUnmounted(() => {
5293
+ // Clean up when the effect scope of the component stops, instead of in
5294
+ // `onUnmounted`. `<Suspense>` stops the scope of a component in a discarded
5295
+ // pending branch, but drops its `onUnmounted` hooks (#2795).
5296
+ onInstanceScopeDispose(target, () => {
5035
5297
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5036
5298
  const _composer = composer;
5037
5299
  // remove composer instance from DOM for intlify-devtools
@@ -5047,7 +5309,7 @@ var VueI18n = (function (exports, Vue) {
5047
5309
  dispose();
5048
5310
  delete _composer[DisposeSymbol];
5049
5311
  }
5050
- }, target);
5312
+ });
5051
5313
  }
5052
5314
  const globalExportProps = [
5053
5315
  'locale',