vue-i18n 11.4.13 → 11.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/vue-i18n.cjs +90 -81
- package/dist/vue-i18n.d.ts +7 -3
- package/dist/vue-i18n.esm-browser.js +216 -138
- package/dist/vue-i18n.esm-browser.prod.js +2 -2
- package/dist/vue-i18n.global.js +216 -138
- package/dist/vue-i18n.global.prod.js +2 -2
- package/dist/vue-i18n.mjs +98 -90
- package/dist/vue-i18n.node.mjs +236 -88
- package/dist/vue-i18n.prod.cjs +90 -81
- package/dist/vue-i18n.runtime.esm-browser.js +215 -135
- package/dist/vue-i18n.runtime.esm-browser.prod.js +2 -2
- package/dist/vue-i18n.runtime.global.js +215 -135
- package/dist/vue-i18n.runtime.global.prod.js +2 -2
- package/dist/vue-i18n.runtime.mjs +98 -90
- package/dist/vue-i18n.runtime.node.mjs +236 -88
- package/package.json +7 -7
package/dist/vue-i18n.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* vue-i18n v11.4.
|
|
2
|
+
* vue-i18n v11.4.15
|
|
3
3
|
* (c) 2026 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -30,7 +30,7 @@ var Vue__namespace = /*#__PURE__*/_interopNamespaceDefault(Vue);
|
|
|
30
30
|
*
|
|
31
31
|
* @VueI18nGeneral
|
|
32
32
|
*/
|
|
33
|
-
const VERSION = '11.4.
|
|
33
|
+
const VERSION = '11.4.15';
|
|
34
34
|
|
|
35
35
|
const I18nErrorCodes = {
|
|
36
36
|
// composer module errors
|
|
@@ -64,6 +64,17 @@ const InejctWithOptionSymbol =
|
|
|
64
64
|
const DisposeSymbol = /* #__PURE__*/ shared.makeSymbol('__dispose');
|
|
65
65
|
|
|
66
66
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
67
|
+
/**
|
|
68
|
+
* Whether `locale` can't be a key of the locale messages and formats.
|
|
69
|
+
* A property name of `Object.prototype`, such as `__proto__` or `constructor`,
|
|
70
|
+
* would read or replace a built-in object, so it is ignored with a warning.
|
|
71
|
+
*/
|
|
72
|
+
function isUnsafeLocale(locale) {
|
|
73
|
+
if (shared.isObjectPrototypeKey(locale)) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
67
78
|
/**
|
|
68
79
|
* Transform flat json in obj to normal json in obj
|
|
69
80
|
*/
|
|
@@ -105,30 +116,26 @@ function handleFlatJson(obj) {
|
|
|
105
116
|
hasStringValue = true;
|
|
106
117
|
break;
|
|
107
118
|
}
|
|
119
|
+
// NOTE: if the next object is a message AST and the next key is a message AST prop key,
|
|
120
|
+
// or `cacheKey` (the key to cache the compiled message), do not go into the message AST
|
|
121
|
+
// and keep the flat key, so that the message AST is not broken
|
|
122
|
+
if (coreBase.isMessageAST(currentObj[subKeys[i]]) &&
|
|
123
|
+
(coreBase.AST_NODE_PROPS_KEYS.includes(subKeys[i + 1]) ||
|
|
124
|
+
subKeys[i + 1] === 'cacheKey')) {
|
|
125
|
+
hasStringValue = true;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
108
128
|
currentObj = currentObj[subKeys[i]];
|
|
109
129
|
}
|
|
110
130
|
// update last object value, delete old property
|
|
111
131
|
if (!hasStringValue) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
delete obj[key];
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
/**
|
|
118
|
-
* NOTE:
|
|
119
|
-
* if the last object is a message AST and subKeys[lastIndex] has message AST prop key, ignore to copy and key deletion
|
|
120
|
-
*/
|
|
121
|
-
if (!coreBase.AST_NODE_PROPS_KEYS.includes(subKeys[lastIndex])) {
|
|
122
|
-
delete obj[key];
|
|
123
|
-
}
|
|
124
|
-
}
|
|
132
|
+
currentObj[subKeys[lastIndex]] = obj[key];
|
|
133
|
+
delete obj[key];
|
|
125
134
|
}
|
|
126
135
|
// recursive process value if value is also a object
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
handleFlatJson(target);
|
|
131
|
-
}
|
|
136
|
+
const target = currentObj[subKeys[lastIndex]];
|
|
137
|
+
if (shared.isObject(target)) {
|
|
138
|
+
handleFlatJson(target);
|
|
132
139
|
}
|
|
133
140
|
}
|
|
134
141
|
}
|
|
@@ -148,7 +155,10 @@ function getLocaleMessages(locale, options) {
|
|
|
148
155
|
if ('locale' in custom && 'resource' in custom) {
|
|
149
156
|
const { locale, resource } = custom;
|
|
150
157
|
if (locale) {
|
|
151
|
-
|
|
158
|
+
if (isUnsafeLocale(locale)) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
ret[locale] = shared.getOwn(ret, locale) || shared.create();
|
|
152
162
|
shared.deepCopy(resource, ret[locale]);
|
|
153
163
|
}
|
|
154
164
|
else {
|
|
@@ -335,7 +345,6 @@ function createComposer(options = {}) {
|
|
|
335
345
|
// pluralRules
|
|
336
346
|
let _pluralRules = options.pluralRules || (__root && __root.pluralRules);
|
|
337
347
|
// runtime context
|
|
338
|
-
// eslint-disable-next-line prefer-const
|
|
339
348
|
let _context;
|
|
340
349
|
const getCoreContext = () => {
|
|
341
350
|
_isGlobal && coreBase.setFallbackContext(null);
|
|
@@ -361,17 +370,12 @@ function createComposer(options = {}) {
|
|
|
361
370
|
{
|
|
362
371
|
ctxOptions.datetimeFormats = _datetimeFormats.value;
|
|
363
372
|
ctxOptions.numberFormats = _numberFormats.value;
|
|
364
|
-
ctxOptions.__datetimeFormatters = shared.isPlainObject(_context)
|
|
365
|
-
? _context.__datetimeFormatters
|
|
366
|
-
: undefined;
|
|
367
|
-
ctxOptions.__numberFormatters = shared.isPlainObject(_context)
|
|
368
|
-
? _context.__numberFormatters
|
|
369
|
-
: undefined;
|
|
370
373
|
}
|
|
371
374
|
const ctx = coreBase.createCoreContext(ctxOptions);
|
|
372
375
|
_isGlobal && coreBase.setFallbackContext(ctx);
|
|
373
376
|
return ctx;
|
|
374
377
|
};
|
|
378
|
+
// eslint-disable-next-line prefer-const
|
|
375
379
|
_context = getCoreContext();
|
|
376
380
|
coreBase.updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
|
|
377
381
|
// track reactivity
|
|
@@ -393,17 +397,12 @@ function createComposer(options = {}) {
|
|
|
393
397
|
_locale.value = val;
|
|
394
398
|
}
|
|
395
399
|
});
|
|
396
|
-
|
|
397
|
-
// translation runs (see `wrapWithDeps`). Point it there while invalidating too,
|
|
398
|
-
// so that the chain the root cached for this composer's fallbackLocale is dropped.
|
|
399
|
-
function updateFallbackLocaleWithRoot(fallback) {
|
|
400
|
+
function withRootFallbackContext(fn) {
|
|
400
401
|
if (!_isGlobal) {
|
|
401
|
-
_context.fallbackContext =
|
|
402
|
-
? coreBase.getFallbackContext()
|
|
403
|
-
: undefined;
|
|
402
|
+
_context.fallbackContext = coreBase.getFallbackContext();
|
|
404
403
|
}
|
|
405
404
|
try {
|
|
406
|
-
|
|
405
|
+
return fn();
|
|
407
406
|
}
|
|
408
407
|
finally {
|
|
409
408
|
if (!_isGlobal) {
|
|
@@ -411,6 +410,12 @@ function createComposer(options = {}) {
|
|
|
411
410
|
}
|
|
412
411
|
}
|
|
413
412
|
}
|
|
413
|
+
// NOTE: `_context.fallbackContext` points at the root context only while a
|
|
414
|
+
// translation runs (see `wrapWithDeps`). Point it there while invalidating too,
|
|
415
|
+
// so that the chain the root cached for this composer's fallbackLocale is dropped.
|
|
416
|
+
function updateFallbackLocaleWithRoot(fallback) {
|
|
417
|
+
withRootFallbackContext(() => coreBase.updateFallbackLocale(_context, _locale.value, fallback));
|
|
418
|
+
}
|
|
414
419
|
// fallbackLocale
|
|
415
420
|
const fallbackLocale = Vue.computed({
|
|
416
421
|
get: () => _fallbackLocale.value,
|
|
@@ -455,17 +460,9 @@ function createComposer(options = {}) {
|
|
|
455
460
|
let ret;
|
|
456
461
|
try {
|
|
457
462
|
if (false || false) ;
|
|
458
|
-
|
|
459
|
-
_context.fallbackContext = __root
|
|
460
|
-
? coreBase.getFallbackContext()
|
|
461
|
-
: undefined;
|
|
462
|
-
}
|
|
463
|
-
ret = fn(_context);
|
|
463
|
+
ret = withRootFallbackContext(() => fn(_context));
|
|
464
464
|
}
|
|
465
465
|
finally {
|
|
466
|
-
if (!_isGlobal) {
|
|
467
|
-
_context.fallbackContext = undefined;
|
|
468
|
-
}
|
|
469
466
|
}
|
|
470
467
|
if ((warnType !== 'translate exists' && // for not `te` (e.g `t`)
|
|
471
468
|
shared.isNumber(ret) &&
|
|
@@ -544,6 +541,15 @@ function createComposer(options = {}) {
|
|
|
544
541
|
_pluralRules = rules;
|
|
545
542
|
_context.pluralRules = _pluralRules;
|
|
546
543
|
}
|
|
544
|
+
// resolve the value of `key` in the locale messages of `locale`,
|
|
545
|
+
// in the same way as `t()`
|
|
546
|
+
function resolveLocaleMessageValue(locale, key) {
|
|
547
|
+
const message = getLocaleMessage(locale);
|
|
548
|
+
const value = _context.messageResolver(message, key);
|
|
549
|
+
// if null, resolve with object key path (for flat keys containing dots),
|
|
550
|
+
// from own properties only
|
|
551
|
+
return value === null ? shared.getOwn(message, key) : value;
|
|
552
|
+
}
|
|
547
553
|
// te
|
|
548
554
|
function te(key, locale) {
|
|
549
555
|
return wrapWithDeps(() => {
|
|
@@ -552,20 +558,12 @@ function createComposer(options = {}) {
|
|
|
552
558
|
}
|
|
553
559
|
const targetLocale = shared.isString(locale) ? locale : _locale.value;
|
|
554
560
|
// When locale is explicitly specified, check only that locale (no fallback chain)
|
|
555
|
-
// When locale is not specified, check the
|
|
561
|
+
// When locale is not specified, check the locale chain, as `t()` does
|
|
556
562
|
const locales = shared.isString(locale)
|
|
557
563
|
? [targetLocale]
|
|
558
|
-
:
|
|
564
|
+
: _context.localeFallbacker(_context, _fallbackLocale.value, targetLocale);
|
|
559
565
|
for (let i = 0; i < locales.length; i++) {
|
|
560
|
-
|
|
561
|
-
let resolved = _context.messageResolver(message, key);
|
|
562
|
-
// if null, resolve with object key path (for flat keys containing dots)
|
|
563
|
-
if (resolved === null) {
|
|
564
|
-
resolved = message[key];
|
|
565
|
-
}
|
|
566
|
-
if (coreBase.isMessageAST(resolved) ||
|
|
567
|
-
coreBase.isMessageFunction(resolved) ||
|
|
568
|
-
shared.isString(resolved)) {
|
|
566
|
+
if (coreBase.isMessageFormat(resolveLocaleMessageValue(locales[i], key))) {
|
|
569
567
|
return true;
|
|
570
568
|
}
|
|
571
569
|
}
|
|
@@ -576,10 +574,10 @@ function createComposer(options = {}) {
|
|
|
576
574
|
}
|
|
577
575
|
function resolveMessages(key) {
|
|
578
576
|
let messages = null;
|
|
579
|
-
|
|
577
|
+
// the same locale chain as `t()`
|
|
578
|
+
const locales = _context.localeFallbacker(_context, _fallbackLocale.value, _locale.value);
|
|
580
579
|
for (let i = 0; i < locales.length; i++) {
|
|
581
|
-
const
|
|
582
|
-
const messageValue = _context.messageResolver(targetLocaleMessages, key);
|
|
580
|
+
const messageValue = resolveLocaleMessageValue(locales[i], key);
|
|
583
581
|
if (messageValue != null) {
|
|
584
582
|
messages = messageValue;
|
|
585
583
|
break;
|
|
@@ -599,66 +597,72 @@ function createComposer(options = {}) {
|
|
|
599
597
|
}
|
|
600
598
|
// getLocaleMessage
|
|
601
599
|
function getLocaleMessage(locale) {
|
|
602
|
-
return (_messages.value
|
|
600
|
+
return (shared.getOwn(_messages.value, locale) || {});
|
|
603
601
|
}
|
|
604
602
|
// setLocaleMessage
|
|
605
603
|
function setLocaleMessage(locale, message) {
|
|
604
|
+
if (isUnsafeLocale(locale)) {
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
606
607
|
if (flatJson) {
|
|
607
|
-
|
|
608
|
-
for (const key in _message) {
|
|
609
|
-
if (shared.hasOwn(_message, key)) {
|
|
610
|
-
handleFlatJson(_message[key]);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
message = _message[locale];
|
|
608
|
+
handleFlatJson(message);
|
|
614
609
|
}
|
|
615
610
|
_messages.value[locale] = message;
|
|
616
611
|
_context.messages = _messages.value;
|
|
617
612
|
}
|
|
618
613
|
// mergeLocaleMessage
|
|
619
614
|
function mergeLocaleMessage(locale, message) {
|
|
620
|
-
|
|
621
|
-
|
|
615
|
+
if (isUnsafeLocale(locale)) {
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
_messages.value[locale] = shared.getOwn(_messages.value, locale) || {};
|
|
622
619
|
if (flatJson) {
|
|
623
|
-
|
|
624
|
-
if (shared.hasOwn(_message, key)) {
|
|
625
|
-
handleFlatJson(_message[key]);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
620
|
+
handleFlatJson(message);
|
|
628
621
|
}
|
|
629
|
-
message = _message[locale];
|
|
630
622
|
shared.deepCopy(message, _messages.value[locale]);
|
|
631
623
|
_context.messages = _messages.value;
|
|
632
624
|
}
|
|
633
625
|
// getDateTimeFormat
|
|
634
626
|
function getDateTimeFormat(locale) {
|
|
635
|
-
return _datetimeFormats.value
|
|
627
|
+
return shared.getOwn(_datetimeFormats.value, locale) || {};
|
|
636
628
|
}
|
|
637
629
|
// setDateTimeFormat
|
|
638
630
|
function setDateTimeFormat(locale, format) {
|
|
631
|
+
if (isUnsafeLocale(locale)) {
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
639
634
|
_datetimeFormats.value[locale] = format;
|
|
640
635
|
_context.datetimeFormats = _datetimeFormats.value;
|
|
641
636
|
coreBase.clearDateTimeFormat(_context, locale, format);
|
|
642
637
|
}
|
|
643
638
|
// mergeDateTimeFormat
|
|
644
639
|
function mergeDateTimeFormat(locale, format) {
|
|
645
|
-
|
|
640
|
+
if (isUnsafeLocale(locale)) {
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
_datetimeFormats.value[locale] = shared.assign(shared.getOwn(_datetimeFormats.value, locale) || {}, format);
|
|
646
644
|
_context.datetimeFormats = _datetimeFormats.value;
|
|
647
645
|
coreBase.clearDateTimeFormat(_context, locale, format);
|
|
648
646
|
}
|
|
649
647
|
// getNumberFormat
|
|
650
648
|
function getNumberFormat(locale) {
|
|
651
|
-
return _numberFormats.value
|
|
649
|
+
return shared.getOwn(_numberFormats.value, locale) || {};
|
|
652
650
|
}
|
|
653
651
|
// setNumberFormat
|
|
654
652
|
function setNumberFormat(locale, format) {
|
|
653
|
+
if (isUnsafeLocale(locale)) {
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
655
656
|
_numberFormats.value[locale] = format;
|
|
656
657
|
_context.numberFormats = _numberFormats.value;
|
|
657
658
|
coreBase.clearNumberFormat(_context, locale, format);
|
|
658
659
|
}
|
|
659
660
|
// mergeNumberFormat
|
|
660
661
|
function mergeNumberFormat(locale, format) {
|
|
661
|
-
|
|
662
|
+
if (isUnsafeLocale(locale)) {
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
_numberFormats.value[locale] = shared.assign(shared.getOwn(_numberFormats.value, locale) || {}, format);
|
|
662
666
|
_context.numberFormats = _numberFormats.value;
|
|
663
667
|
coreBase.clearNumberFormat(_context, locale, format);
|
|
664
668
|
}
|
|
@@ -829,7 +833,10 @@ function convertComposerOptions(options) {
|
|
|
829
833
|
const sharedMessages = options.sharedMessages;
|
|
830
834
|
const locales = Object.keys(sharedMessages);
|
|
831
835
|
messages = locales.reduce((messages, locale) => {
|
|
832
|
-
|
|
836
|
+
if (isUnsafeLocale(locale)) {
|
|
837
|
+
return messages;
|
|
838
|
+
}
|
|
839
|
+
const message = shared.getOwn(messages, locale) || (messages[locale] = {});
|
|
833
840
|
shared.assign(message, sharedMessages[locale]);
|
|
834
841
|
return messages;
|
|
835
842
|
}, (messages || {}));
|
|
@@ -1056,7 +1063,9 @@ function defineMixin(vuei18n, composer, i18n) {
|
|
|
1056
1063
|
}
|
|
1057
1064
|
const options = this.$options;
|
|
1058
1065
|
if (options.i18n) {
|
|
1059
|
-
|
|
1066
|
+
// copy the option, since it belongs to the component definition,
|
|
1067
|
+
// which every instance and, on the server, every app shares
|
|
1068
|
+
const optionsI18n = shared.assign({}, options.i18n);
|
|
1060
1069
|
if (options.__i18n) {
|
|
1061
1070
|
optionsI18n.__i18n = options.__i18n;
|
|
1062
1071
|
}
|
package/dist/vue-i18n.d.ts
CHANGED
|
@@ -284,12 +284,14 @@ export declare interface Composer<Messages extends Record<string, any> = {}, Dat
|
|
|
284
284
|
* @remarks
|
|
285
285
|
* whether do exist locale message on Composer instance [messages](composition#messages).
|
|
286
286
|
*
|
|
287
|
-
* If you specified `locale`, check the locale messages of `locale
|
|
287
|
+
* If you specified `locale`, check the locale messages of `locale`, but not those of its fallback locales.
|
|
288
|
+
*
|
|
289
|
+
* If you did not specify `locale`, check the locale messages of the current `locale` and then those of its fallback locales, as `t` does (see [fallbacking](../guide/essentials/fallback)).
|
|
288
290
|
*
|
|
289
291
|
* @param key - A target locale message key
|
|
290
292
|
* @param locale - A locale, it will be used over than global scope or local scope
|
|
291
293
|
*
|
|
292
|
-
* @returns If found locale message, `true`, else `false`, Note that `false` is returned even if the value present in the key is not translatable
|
|
294
|
+
* @returns If found locale message, `true`, else `false`, Note that `false` is returned even if the value present in the key is not translatable.
|
|
293
295
|
*/
|
|
294
296
|
te<Str extends string, Key extends PickupKeys<Messages> = PickupKeys<Messages>>(key: Str | Key, locale?: Locales): boolean;
|
|
295
297
|
/**
|
|
@@ -2301,7 +2303,9 @@ export declare interface VueI18n<Messages extends Record<string, any> = {}, Date
|
|
|
2301
2303
|
* @remarks
|
|
2302
2304
|
* whether do exist locale message on VueI18n instance [messages](legacy#messages).
|
|
2303
2305
|
*
|
|
2304
|
-
* If you specified `locale`, check the locale messages of `locale
|
|
2306
|
+
* If you specified `locale`, check the locale messages of `locale`, but not those of its fallback locales.
|
|
2307
|
+
*
|
|
2308
|
+
* If you did not specify `locale`, check the locale messages of the current `locale` and then those of its fallback locales, as `t` does (see [fallbacking](../guide/essentials/fallback)).
|
|
2305
2309
|
*
|
|
2306
2310
|
* @param key - A target locale message key
|
|
2307
2311
|
* @param locale - A target locale
|