vue-i18n 11.4.14 → 11.4.16

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vue-i18n v11.4.14
2
+ * vue-i18n v11.4.16
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.14';
33
+ const VERSION = '11.4.16';
34
34
 
35
35
  const I18nErrorCodes = {
36
36
  // composer module errors
@@ -116,30 +116,26 @@ function handleFlatJson(obj) {
116
116
  hasStringValue = true;
117
117
  break;
118
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
+ }
119
128
  currentObj = currentObj[subKeys[i]];
120
129
  }
121
130
  // update last object value, delete old property
122
131
  if (!hasStringValue) {
123
- if (!coreBase.isMessageAST(currentObj)) {
124
- currentObj[subKeys[lastIndex]] = obj[key];
125
- delete obj[key];
126
- }
127
- else {
128
- /**
129
- * NOTE:
130
- * if the last object is a message AST and subKeys[lastIndex] has message AST prop key, ignore to copy and key deletion
131
- */
132
- if (!coreBase.AST_NODE_PROPS_KEYS.includes(subKeys[lastIndex])) {
133
- delete obj[key];
134
- }
135
- }
132
+ currentObj[subKeys[lastIndex]] = obj[key];
133
+ delete obj[key];
136
134
  }
137
135
  // recursive process value if value is also a object
138
- if (!coreBase.isMessageAST(currentObj)) {
139
- const target = currentObj[subKeys[lastIndex]];
140
- if (shared.isObject(target)) {
141
- handleFlatJson(target);
142
- }
136
+ const target = currentObj[subKeys[lastIndex]];
137
+ if (shared.isObject(target)) {
138
+ handleFlatJson(target);
143
139
  }
144
140
  }
145
141
  }
@@ -545,6 +541,15 @@ function createComposer(options = {}) {
545
541
  _pluralRules = rules;
546
542
  _context.pluralRules = _pluralRules;
547
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
+ }
548
553
  // te
549
554
  function te(key, locale) {
550
555
  return wrapWithDeps(() => {
@@ -553,18 +558,12 @@ function createComposer(options = {}) {
553
558
  }
554
559
  const targetLocale = shared.isString(locale) ? locale : _locale.value;
555
560
  // When locale is explicitly specified, check only that locale (no fallback chain)
556
- // When locale is not specified, check the fallback locale chain
561
+ // When locale is not specified, check the locale chain, as `t()` does
557
562
  const locales = shared.isString(locale)
558
563
  ? [targetLocale]
559
- : coreBase.fallbackWithLocaleChain(_context, _fallbackLocale.value, targetLocale);
564
+ : _context.localeFallbacker(_context, _fallbackLocale.value, targetLocale);
560
565
  for (let i = 0; i < locales.length; i++) {
561
- const message = getLocaleMessage(locales[i]);
562
- let resolved = _context.messageResolver(message, key);
563
- // if null, resolve with object key path (for flat keys containing dots)
564
- if (resolved === null) {
565
- resolved = message[key];
566
- }
567
- if (coreBase.isMessageFormat(resolved)) {
566
+ if (coreBase.isMessageFormat(resolveLocaleMessageValue(locales[i], key))) {
568
567
  return true;
569
568
  }
570
569
  }
@@ -575,10 +574,10 @@ function createComposer(options = {}) {
575
574
  }
576
575
  function resolveMessages(key) {
577
576
  let messages = null;
578
- const locales = coreBase.fallbackWithLocaleChain(_context, _fallbackLocale.value, _locale.value);
577
+ // the same locale chain as `t()`
578
+ const locales = _context.localeFallbacker(_context, _fallbackLocale.value, _locale.value);
579
579
  for (let i = 0; i < locales.length; i++) {
580
- const targetLocaleMessages = shared.getOwn(_messages.value, locales[i]) || {};
581
- const messageValue = _context.messageResolver(targetLocaleMessages, key);
580
+ const messageValue = resolveLocaleMessageValue(locales[i], key);
582
581
  if (messageValue != null) {
583
582
  messages = messageValue;
584
583
  break;
@@ -1064,7 +1063,9 @@ function defineMixin(vuei18n, composer, i18n) {
1064
1063
  }
1065
1064
  const options = this.$options;
1066
1065
  if (options.i18n) {
1067
- const optionsI18n = options.i18n;
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);
1068
1069
  if (options.__i18n) {
1069
1070
  optionsI18n.__i18n = options.__i18n;
1070
1071
  }
@@ -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, yet if `translateExistCompatible` is set to `true`, it will return `true` if the key is available, even if the value 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
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vue-i18n v11.4.14
2
+ * vue-i18n v11.4.16
3
3
  * (c) 2026 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -2130,8 +2130,12 @@ function compile(message, context) {
2130
2130
  return !detectError ? (compileCache[cacheKey] = msg) : msg;
2131
2131
  }
2132
2132
  else {
2133
+ // the message compiler is not included in this build (e.g. the runtime-only builds), so return a string message as is
2133
2134
  if (!isMessageAST(message)) {
2134
- warn(`the message that is resolve with key '${context.key}' is not supported for jit compilation`);
2135
+ {
2136
+ warn(`Cannot compile the message of '${context.key}' key, because the message compiler is not included in this build. ` +
2137
+ `Pre-compile the message. So translate function returns the message as is.`);
2138
+ }
2135
2139
  return (() => message);
2136
2140
  }
2137
2141
  // AST case (passed from bundler)
@@ -2586,7 +2590,9 @@ const cache = new Map();
2586
2590
  * @VueI18nGeneral
2587
2591
  */
2588
2592
  function resolveWithKeyValue(obj, path) {
2589
- return isObject(obj) ? obj[path] : null;
2593
+ // read only own properties, so that a key such as `toString` does not
2594
+ // resolve a built-in function
2595
+ return isObject(obj) ? getOwn(obj, path) : null;
2590
2596
  }
2591
2597
  /**
2592
2598
  * message resolver
@@ -2666,7 +2672,7 @@ const CoreWarnCodes = {
2666
2672
  const CORE_WARN_CODES_EXTEND_POINT = 10;
2667
2673
  /** @internal */
2668
2674
  const warnMessages$1 = {
2669
- [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale messages.`,
2675
+ [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale {resource}.`,
2670
2676
  [CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
2671
2677
  [CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
2672
2678
  [CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
@@ -2685,7 +2691,7 @@ function getWarnMessage$1(code, ...args) {
2685
2691
  * Intlify core-base version
2686
2692
  * @internal
2687
2693
  */
2688
- const VERSION$1 = '11.4.14';
2694
+ const VERSION$1 = '11.4.16';
2689
2695
  const NOT_REOSLVED = -1;
2690
2696
  const DEFAULT_LOCALE = 'en-US';
2691
2697
  const MISSING_RESOLVE_VALUE = '';
@@ -2903,7 +2909,15 @@ function handleMissing(context, key, locale, missingWarn, type) {
2903
2909
  }
2904
2910
  else {
2905
2911
  if (isTranslateMissingWarn(missingWarn, key)) {
2906
- onWarn(getWarnMessage$1(CoreWarnCodes.NOT_FOUND_KEY, { key, locale }));
2912
+ onWarn(getWarnMessage$1(CoreWarnCodes.NOT_FOUND_KEY, {
2913
+ key,
2914
+ locale,
2915
+ resource: type === 'datetime format'
2916
+ ? 'datetime formats'
2917
+ : type === 'number format'
2918
+ ? 'number formats'
2919
+ : 'messages'
2920
+ }));
2907
2921
  }
2908
2922
  return key;
2909
2923
  }
@@ -2977,7 +2991,9 @@ function resolveFormatLocale(context, key, locale, formats, missingWarn, fallbac
2977
2991
  });
2978
2992
  }
2979
2993
  }
2980
- const format = (formats[targetLocale] || {})[key];
2994
+ // read only own properties, so that a locale such as `constructor` does not
2995
+ // read a built-in object
2996
+ const format = getOwn(getOwn(formats, targetLocale) || {}, key);
2981
2997
  if (isPlainObject(format) && isString(targetLocale)) {
2982
2998
  return targetLocale;
2983
2999
  }
@@ -3266,7 +3282,9 @@ function getPluralIndex(options) {
3266
3282
  function createMessageContext(options = {}) {
3267
3283
  const locale = options.locale;
3268
3284
  const pluralIndex = getPluralIndex(options);
3269
- const pluralRule = isString(locale) && isFunction(options.pluralRules?.[locale])
3285
+ const pluralRule = isString(locale) &&
3286
+ options.pluralRules &&
3287
+ isFunction(getOwn(options.pluralRules, locale))
3270
3288
  ? options.pluralRules[locale]
3271
3289
  : pluralDefault;
3272
3290
  const orgPluralRule = pluralRule === pluralDefault ? undefined : pluralDefault;
@@ -3274,12 +3292,19 @@ function createMessageContext(options = {}) {
3274
3292
  const _list = options.list || [];
3275
3293
  const list = (index) => _list[index];
3276
3294
  const _named = options.named || create(); // eslint-disable-line @typescript-eslint/no-explicit-any
3277
- // normalize named
3278
- if (isNumber(options.pluralIndex)) {
3279
- _named.count ||= options.pluralIndex;
3280
- _named.n ||= options.pluralIndex;
3281
- }
3282
- const named = (key) => _named[key];
3295
+ // `count` and `n` are the implicit named values of a plural call. supply the
3296
+ // plural index for them, without writing into the named values that the
3297
+ // caller passed
3298
+ const hasPluralIndex = isNumber(options.pluralIndex);
3299
+ const named = (key) => {
3300
+ // read only own properties for the names of Object.prototype properties,
3301
+ // such as `toString`, so that the getters of class instances still work as
3302
+ // named values
3303
+ const value = isObjectPrototypeKey(key) ? getOwn(_named, key) : _named[key];
3304
+ return hasPluralIndex && !value && (key === 'count' || key === 'n')
3305
+ ? options.pluralIndex
3306
+ : value;
3307
+ };
3283
3308
  function message(key, useLinked) {
3284
3309
  // prettier-ignore
3285
3310
  const msg = isFunction(options.messages)
@@ -3294,7 +3319,7 @@ function createMessageContext(options = {}) {
3294
3319
  : msg;
3295
3320
  }
3296
3321
  const _modifier = (name) => options.modifiers
3297
- ? options.modifiers[name]
3322
+ ? getOwn(options.modifiers, name)
3298
3323
  : DEFAULT_MODIFIER;
3299
3324
  const normalize = isFunction(options.processor?.normalize)
3300
3325
  ? options.processor.normalize
@@ -3334,7 +3359,20 @@ function createMessageContext(options = {}) {
3334
3359
  type === 'vnode' && isArray(resolved) && modifier
3335
3360
  ? resolved[0]
3336
3361
  : resolved;
3337
- return modifier ? _modifier(modifier)(msg, type) : msg;
3362
+ if (!modifier) {
3363
+ return msg;
3364
+ }
3365
+ const modify = _modifier(modifier);
3366
+ if (isFunction(modify)) {
3367
+ return modify(msg, type);
3368
+ }
3369
+ // an unknown modifier, such as a typo, does not stop the translation
3370
+ {
3371
+ warnOnce(`Not found '${modifier}' modifier for the linked message of '${key}' key. ` +
3372
+ `Use a built-in modifier, or set a custom modifier with 'modifiers' option. ` +
3373
+ `So the linked message is used as is.`);
3374
+ }
3375
+ return msg;
3338
3376
  };
3339
3377
  const ctx = {
3340
3378
  ["list" /* HelperNameMap.LIST */]: list,
@@ -3345,7 +3383,9 @@ function createMessageContext(options = {}) {
3345
3383
  ["type" /* HelperNameMap.TYPE */]: type,
3346
3384
  ["interpolate" /* HelperNameMap.INTERPOLATE */]: interpolate,
3347
3385
  ["normalize" /* HelperNameMap.NORMALIZE */]: normalize,
3348
- ["values" /* HelperNameMap.VALUES */]: assign(create(), _list, _named)
3386
+ // custom message compilers read the values, so give them the same `count`
3387
+ // and `n` as `named()`
3388
+ ["values" /* HelperNameMap.VALUES */]: assign(create(), _list, _named, hasPluralIndex ? { count: named('count'), n: named('n') } : {})
3349
3389
  };
3350
3390
  return ctx;
3351
3391
  }
@@ -3386,11 +3426,7 @@ function translate(context, ...args) {
3386
3426
  // eslint-disable-next-line prefer-const
3387
3427
  let [formatScope, targetLocale, message] = !resolvedMessage
3388
3428
  ? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn)
3389
- : [
3390
- key,
3391
- locale,
3392
- messages[locale] || create()
3393
- ];
3429
+ : [key, locale, getOwn(messages, locale) || create()];
3394
3430
  // NOTE:
3395
3431
  // Fix to work around `ssrTransfrom` bug in Vite.
3396
3432
  // https://github.com/vitejs/vite/issues/4306
@@ -3410,13 +3446,12 @@ function translate(context, ...args) {
3410
3446
  (!isMessageFormat(format) || !isString(targetLocale))) {
3411
3447
  return unresolving ? NOT_REOSLVED : key;
3412
3448
  }
3413
- // TODO: refactor
3449
+ // without a message compiler, `compileMessageFormat()` returns the message as is
3414
3450
  if (isString(format) && context.messageCompiler == null) {
3415
3451
  warn(`The message format compilation is not supported in this build. ` +
3416
3452
  `Because message compiler isn't included. ` +
3417
3453
  `You need to pre-compilation all message format. ` +
3418
- `So translate function return '${key}'.`);
3419
- return key;
3454
+ `So translate function returns the message as is.`);
3420
3455
  }
3421
3456
  // setup compile error detecting
3422
3457
  let occurred = false;
@@ -3517,8 +3552,9 @@ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn
3517
3552
  });
3518
3553
  }
3519
3554
  }
3520
- message =
3521
- messages[targetLocale] || create();
3555
+ // read only own properties, so that a locale such as `constructor` does not
3556
+ // read a built-in object
3557
+ message = getOwn(messages, targetLocale) || create();
3522
3558
  // for vue-devtools timeline event
3523
3559
  let start = null;
3524
3560
  let startTag;
@@ -3530,8 +3566,8 @@ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn
3530
3566
  mark && mark(startTag);
3531
3567
  }
3532
3568
  if ((format = resolveValue(message, key)) === null) {
3533
- // if null, resolve with object key path
3534
- format = message[key]; // eslint-disable-line @typescript-eslint/no-explicit-any
3569
+ // if null, resolve with object key path, from own properties only
3570
+ format = getOwn(message, key);
3535
3571
  }
3536
3572
  // for vue-devtools timeline event
3537
3573
  if (inBrowser && emitter) {
@@ -3779,7 +3815,7 @@ function getMessageContextOptions(context, locale, message, options) {
3779
3815
  *
3780
3816
  * @VueI18nGeneral
3781
3817
  */
3782
- const VERSION = '11.4.14';
3818
+ const VERSION = '11.4.16';
3783
3819
  /**
3784
3820
  * This is only called development env
3785
3821
  * istanbul-ignore-next
@@ -3935,30 +3971,26 @@ function handleFlatJson(obj) {
3935
3971
  hasStringValue = true;
3936
3972
  break;
3937
3973
  }
3974
+ // NOTE: if the next object is a message AST and the next key is a message AST prop key,
3975
+ // or `cacheKey` (the key to cache the compiled message), do not go into the message AST
3976
+ // and keep the flat key, so that the message AST is not broken
3977
+ if (isMessageAST(currentObj[subKeys[i]]) &&
3978
+ (AST_NODE_PROPS_KEYS.includes(subKeys[i + 1]) ||
3979
+ subKeys[i + 1] === 'cacheKey')) {
3980
+ hasStringValue = true;
3981
+ break;
3982
+ }
3938
3983
  currentObj = currentObj[subKeys[i]];
3939
3984
  }
3940
3985
  // update last object value, delete old property
3941
3986
  if (!hasStringValue) {
3942
- if (!isMessageAST(currentObj)) {
3943
- currentObj[subKeys[lastIndex]] = obj[key];
3944
- delete obj[key];
3945
- }
3946
- else {
3947
- /**
3948
- * NOTE:
3949
- * if the last object is a message AST and subKeys[lastIndex] has message AST prop key, ignore to copy and key deletion
3950
- */
3951
- if (!AST_NODE_PROPS_KEYS.includes(subKeys[lastIndex])) {
3952
- delete obj[key];
3953
- }
3954
- }
3987
+ currentObj[subKeys[lastIndex]] = obj[key];
3988
+ delete obj[key];
3955
3989
  }
3956
3990
  // recursive process value if value is also a object
3957
- if (!isMessageAST(currentObj)) {
3958
- const target = currentObj[subKeys[lastIndex]];
3959
- if (isObject(target)) {
3960
- handleFlatJson(target);
3961
- }
3991
+ const target = currentObj[subKeys[lastIndex]];
3992
+ if (isObject(target)) {
3993
+ handleFlatJson(target);
3962
3994
  }
3963
3995
  }
3964
3996
  }
@@ -4393,6 +4425,15 @@ function createComposer(options = {}) {
4393
4425
  _pluralRules = rules;
4394
4426
  _context.pluralRules = _pluralRules;
4395
4427
  }
4428
+ // resolve the value of `key` in the locale messages of `locale`,
4429
+ // in the same way as `t()`
4430
+ function resolveLocaleMessageValue(locale, key) {
4431
+ const message = getLocaleMessage(locale);
4432
+ const value = _context.messageResolver(message, key);
4433
+ // if null, resolve with object key path (for flat keys containing dots),
4434
+ // from own properties only
4435
+ return value === null ? getOwn(message, key) : value;
4436
+ }
4396
4437
  // te
4397
4438
  function te(key, locale) {
4398
4439
  return wrapWithDeps(() => {
@@ -4401,18 +4442,12 @@ function createComposer(options = {}) {
4401
4442
  }
4402
4443
  const targetLocale = isString(locale) ? locale : _locale.value;
4403
4444
  // When locale is explicitly specified, check only that locale (no fallback chain)
4404
- // When locale is not specified, check the fallback locale chain
4445
+ // When locale is not specified, check the locale chain, as `t()` does
4405
4446
  const locales = isString(locale)
4406
4447
  ? [targetLocale]
4407
- : fallbackWithLocaleChain(_context, _fallbackLocale.value, targetLocale);
4448
+ : _context.localeFallbacker(_context, _fallbackLocale.value, targetLocale);
4408
4449
  for (let i = 0; i < locales.length; i++) {
4409
- const message = getLocaleMessage(locales[i]);
4410
- let resolved = _context.messageResolver(message, key);
4411
- // if null, resolve with object key path (for flat keys containing dots)
4412
- if (resolved === null) {
4413
- resolved = message[key];
4414
- }
4415
- if (isMessageFormat(resolved)) {
4450
+ if (isMessageFormat(resolveLocaleMessageValue(locales[i], key))) {
4416
4451
  return true;
4417
4452
  }
4418
4453
  }
@@ -4423,10 +4458,10 @@ function createComposer(options = {}) {
4423
4458
  }
4424
4459
  function resolveMessages(key) {
4425
4460
  let messages = null;
4426
- const locales = fallbackWithLocaleChain(_context, _fallbackLocale.value, _locale.value);
4461
+ // the same locale chain as `t()`
4462
+ const locales = _context.localeFallbacker(_context, _fallbackLocale.value, _locale.value);
4427
4463
  for (let i = 0; i < locales.length; i++) {
4428
- const targetLocaleMessages = getOwn(_messages.value, locales[i]) || {};
4429
- const messageValue = _context.messageResolver(targetLocaleMessages, key);
4464
+ const messageValue = resolveLocaleMessageValue(locales[i], key);
4430
4465
  if (messageValue != null) {
4431
4466
  messages = messageValue;
4432
4467
  break;
@@ -5483,7 +5518,9 @@ function defineMixin(vuei18n, composer, i18n) {
5483
5518
  }
5484
5519
  const options = this.$options;
5485
5520
  if (options.i18n) {
5486
- const optionsI18n = options.i18n;
5521
+ // copy the option, since it belongs to the component definition,
5522
+ // which every instance and, on the server, every app shares
5523
+ const optionsI18n = assign({}, options.i18n);
5487
5524
  if (options.__i18n) {
5488
5525
  optionsI18n.__i18n = options.__i18n;
5489
5526
  }