@intlify/core 12.0.0-alpha.5 → 12.0.0-alpha.6

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/core.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @intlify/core v12.0.0-alpha.5
2
+ * @intlify/core v12.0.0-alpha.6
3
3
  * (c) 2016-present kazuya kawaguchi and contributors
4
4
  * @license MIT
5
5
  **/
package/dist/core.node.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @intlify/core v12.0.0-alpha.5
2
+ * @intlify/core v12.0.0-alpha.6
3
3
  * (c) 2016-present kazuya kawaguchi and contributors
4
4
  * @license MIT
5
5
  **/
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @intlify/core v12.0.0-alpha.5
2
+ * @intlify/core v12.0.0-alpha.6
3
3
  * (c) 2016-present kazuya kawaguchi and contributors
4
4
  * @license MIT
5
5
  **/
@@ -418,7 +418,7 @@ function clearCompileCache() {
418
418
  function compile(message, context) {
419
419
  {
420
420
  if (!isMessageAST(message)) {
421
- warn(`the message that is resolve with key '${context.key}' is not supported for jit compilation`);
421
+ warn(`Cannot compile the message of '${context.key}' key, because the message compiler is not included in this build. Pre-compile the message. So translate function returns the message as is.`);
422
422
  return (() => message);
423
423
  }
424
424
  const cacheKey = message.cacheKey;
@@ -749,7 +749,7 @@ const cache = /* @__PURE__ */ new Map();
749
749
  * @VueI18nGeneral
750
750
  */
751
751
  function resolveWithKeyValue(obj, path) {
752
- return isObject(obj) ? obj[path] : null;
752
+ return isObject(obj) ? getOwn(obj, path) : null;
753
753
  }
754
754
  /**
755
755
  * message resolver
@@ -804,12 +804,15 @@ const CoreWarnCodes = {
804
804
  FALLBACK_TO_DATE_FORMAT: 6,
805
805
  EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER: 7,
806
806
  INVALID_NUMBER_ARGUMENT: 8,
807
- INVALID_DATE_ARGUMENT: 9
807
+ INVALID_DATE_ARGUMENT: 9,
808
+ IGNORE_UNSAFE_LOCALE: 10,
809
+ FALLBACK_TO_DEFAULT_PLURAL_RULE: 11,
810
+ FALLBACK_FROM_INVALID_LOCALE: 12
808
811
  };
809
- const CORE_WARN_CODES_EXTEND_POINT = 10;
812
+ const CORE_WARN_CODES_EXTEND_POINT = 13;
810
813
  /** @internal */
811
814
  const warnMessages = {
812
- [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale messages.`,
815
+ [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale {resource}.`,
813
816
  [CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
814
817
  [CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
815
818
  [CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
@@ -817,7 +820,10 @@ const warnMessages = {
817
820
  [CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`,
818
821
  [CoreWarnCodes.EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER]: `This project is using Custom Message Compiler, which is an experimental feature. It may receive breaking changes or be removed in the future.`,
819
822
  [CoreWarnCodes.INVALID_NUMBER_ARGUMENT]: `Invalid argument for number formatting: expected a number but received '{value}'.`,
820
- [CoreWarnCodes.INVALID_DATE_ARGUMENT]: `Invalid argument for datetime formatting: expected a Date, number, or ISO string but received '{value}'.`
823
+ [CoreWarnCodes.INVALID_DATE_ARGUMENT]: `Invalid argument for datetime formatting: expected a Date, number, or ISO string but received '{value}'.`,
824
+ [CoreWarnCodes.IGNORE_UNSAFE_LOCALE]: `Ignore '{locale}' locale: it is a property name of Object.prototype`,
825
+ [CoreWarnCodes.FALLBACK_TO_DEFAULT_PLURAL_RULE]: `Fall back to the default plural rule for '{locale}' locale: Intl.PluralRules does not support it`,
826
+ [CoreWarnCodes.FALLBACK_FROM_INVALID_LOCALE]: `Fall back to '{target}' locale for {type} formatting with '{locale}' locale: it is not a BCP 47 language tag`
821
827
  };
822
828
  function getWarnMessage(code, ...args) {
823
829
  return format$1(warnMessages[code], ...args);
@@ -828,7 +834,7 @@ function getWarnMessage(code, ...args) {
828
834
  * Intlify core-base version
829
835
  * @internal
830
836
  */
831
- const VERSION = "12.0.0-alpha.5";
837
+ const VERSION = "12.0.0-alpha.6";
832
838
  const NOT_RESOLVED = -1;
833
839
  const DEFAULT_LOCALE = "en-US";
834
840
  const MISSING_RESOLVE_VALUE = "";
@@ -894,15 +900,15 @@ function createCoreContext(options = {}) {
894
900
  const version = isString(options.version) ? options.version : VERSION;
895
901
  const locale = isString(options.locale) || isFunction(options.locale) ? options.locale : DEFAULT_LOCALE;
896
902
  const _locale = isFunction(locale) ? DEFAULT_LOCALE : locale;
897
- const fallbackLocale = isArray(options.fallbackLocale) || isPlainObject(options.fallbackLocale) || isString(options.fallbackLocale) || options.fallbackLocale === false ? options.fallbackLocale : _locale;
903
+ const fallbackLocale = isFallbackLocale(options.fallbackLocale) ? options.fallbackLocale : _locale;
898
904
  const messages = isPlainObject(options.messages) ? options.messages : createResources(_locale);
899
905
  const datetimeFormats = isPlainObject(options.datetimeFormats) ? options.datetimeFormats : createResources(_locale);
900
906
  const numberFormats = isPlainObject(options.numberFormats) ? options.numberFormats : createResources(_locale);
901
907
  const modifiers = assign(create(), options.modifiers, getDefaultLinkedModifiers());
902
908
  const pluralRules = options.pluralRules || create();
903
909
  const missing = isFunction(options.missing) ? options.missing : null;
904
- const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn) ? options.missingWarn : true;
905
- const fallbackWarn = isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn) ? options.fallbackWarn : true;
910
+ const missingWarn = isWarnOption(options.missingWarn) ? options.missingWarn : true;
911
+ const fallbackWarn = isWarnOption(options.fallbackWarn) ? options.fallbackWarn : true;
906
912
  const fallbackFormat = !!options.fallbackFormat;
907
913
  const unresolving = !!options.unresolving;
908
914
  const postTranslation = isFunction(options.postTranslation) ? options.postTranslation : null;
@@ -910,13 +916,9 @@ function createCoreContext(options = {}) {
910
916
  const warnHtmlMessage = isBoolean(options.warnHtmlMessage) ? options.warnHtmlMessage : true;
911
917
  const escapeParameter = !!options.escapeParameter;
912
918
  const messageCompiler = isFunction(options.messageCompiler) ? options.messageCompiler : _compiler || null;
913
- if (isFunction(options.messageCompiler)) warnOnce(getWarnMessage(CoreWarnCodes.EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER));
914
919
  const messageResolver = isFunction(options.messageResolver) ? options.messageResolver : _resolver || resolveWithKeyValue;
915
920
  const localeFallbacker = isFunction(options.localeFallbacker) ? options.localeFallbacker : _fallbacker || fallbackWithSimple;
916
921
  const fallbackContext = isObject(options.fallbackContext) ? options.fallbackContext : void 0;
917
- const internalOptions = options;
918
- const __datetimeFormatters = isObject(internalOptions.__datetimeFormatters) ? internalOptions.__datetimeFormatters : /* @__PURE__ */ new Map();
919
- const __numberFormatters = isObject(internalOptions.__numberFormatters) ? internalOptions.__numberFormatters : /* @__PURE__ */ new Map();
920
922
  _cid++;
921
923
  const context = {
922
924
  version,
@@ -943,9 +945,8 @@ function createCoreContext(options = {}) {
943
945
  };
944
946
  context.datetimeFormats = datetimeFormats;
945
947
  context.numberFormats = numberFormats;
946
- context.__datetimeFormatters = __datetimeFormatters;
947
- context.__numberFormatters = __numberFormatters;
948
- context.__v_emitter = internalOptions.__v_emitter != null ? internalOptions.__v_emitter : void 0;
948
+ context.__datetimeFormatters = /* @__PURE__ */ new Map();
949
+ context.__numberFormatters = /* @__PURE__ */ new Map();
949
950
  return context;
950
951
  }
951
952
  const createResources = (locale) => ({ [locale]: create() });
@@ -963,10 +964,21 @@ function getLocaleMessage(ctx, locale) {
963
964
  * @version 12.0.0
964
965
  */
965
966
  function setLocaleMessage(ctx, locale, messages) {
966
- if (isObjectPrototypeKey(locale)) return;
967
+ if (isObjectPrototypeKey(locale)) {
968
+ ctx.onWarn(getWarnMessage(CoreWarnCodes.IGNORE_UNSAFE_LOCALE, { locale }));
969
+ return;
970
+ }
967
971
  ctx.messages[locale] = messages;
968
972
  }
969
973
  /** @internal */
974
+ function isFallbackLocale(val) {
975
+ return isString(val) || isArray(val) || isPlainObject(val) || val === false;
976
+ }
977
+ /** @internal */
978
+ function isWarnOption(val) {
979
+ return isBoolean(val) || isRegExp(val);
980
+ }
981
+ /** @internal */
970
982
  function isTranslateFallbackWarn(fallback, key) {
971
983
  return isRegExp(fallback) ? fallback.test(key) : fallback;
972
984
  }
@@ -992,7 +1004,8 @@ function handleMissing(context, key, locale, missingWarn, type) {
992
1004
  } else {
993
1005
  if (isTranslateMissingWarn(missingWarn, key)) onWarn(getWarnMessage(CoreWarnCodes.NOT_FOUND_KEY, {
994
1006
  key,
995
- locale
1007
+ locale,
1008
+ resource: type === "datetime format" ? "datetime formats" : type === "number format" ? "number formats" : "messages"
996
1009
  }));
997
1010
  return key;
998
1011
  }
@@ -1006,6 +1019,11 @@ function invalidateLocaleChainCache(ctx, fallback) {
1006
1019
  function updateFallbackLocale(ctx, locale, fallback) {
1007
1020
  invalidateLocaleChainCache(ctx, fallback);
1008
1021
  if (ctx.fallbackContext) invalidateLocaleChainCache(ctx.fallbackContext, fallback);
1022
+ {
1023
+ const { __datetimeFormatters, __numberFormatters } = ctx;
1024
+ __datetimeFormatters.clear();
1025
+ __numberFormatters.clear();
1026
+ }
1009
1027
  ctx.localeFallbacker(ctx, fallback, locale);
1010
1028
  }
1011
1029
  /** @internal */
@@ -1042,13 +1060,69 @@ function resolveFormatLocale(context, key, locale, formats, missingWarn, fallbac
1042
1060
  groupId: toDevtoolsGroupId(type, key)
1043
1061
  });
1044
1062
  }
1045
- const format = (formats[targetLocale] || {})[key];
1063
+ const format = getOwn(getOwn(formats, targetLocale) || {}, key);
1046
1064
  if (isPlainObject(format) && isString(targetLocale)) return targetLocale;
1047
1065
  handleMissing(context, key, targetLocale, missingWarn, type);
1048
1066
  from = targetLocale;
1049
1067
  }
1050
1068
  return null;
1051
1069
  }
1070
+ function isLanguageTag(locale) {
1071
+ try {
1072
+ Intl.getCanonicalLocales(locale);
1073
+ return true;
1074
+ } catch {
1075
+ return false;
1076
+ }
1077
+ }
1078
+ /**
1079
+ * Create an `Intl.DateTimeFormat` or `Intl.NumberFormat` formatter
1080
+ *
1081
+ * @remarks
1082
+ * `Intl` throws a RangeError for a locale that is not a BCP 47 language tag (e.g. `pt_BR`),
1083
+ * so fall back to the first language tag in the locale chain, or the default locale
1084
+ */
1085
+ function createFormatter(context, IntlFormatter, locale, options, type) {
1086
+ try {
1087
+ return new IntlFormatter(locale, options);
1088
+ } catch (error) {
1089
+ if (isLanguageTag(locale)) throw error;
1090
+ const { fallbackLocale, localeFallbacker, onWarn } = context;
1091
+ const target = localeFallbacker(context, fallbackLocale, locale).find(isLanguageTag) || "en-US";
1092
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_FROM_INVALID_LOCALE, {
1093
+ locale,
1094
+ target,
1095
+ type: type === "datetime format" ? "datetime" : "number"
1096
+ }));
1097
+ return new IntlFormatter(target, options);
1098
+ }
1099
+ }
1100
+ /**
1101
+ * Format a value with the format of a key, or only with the overrides when no key is given
1102
+ *
1103
+ * @remarks
1104
+ * The common part of `datetime()` and `number()`, after they check and parse the arguments
1105
+ */
1106
+ function formatValue(context, [key, value, options, overrides], IntlFormatter, formatters, formats, type) {
1107
+ const missingWarn = isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn;
1108
+ const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
1109
+ const part = !!options.part;
1110
+ const locale = getLocale(context, options);
1111
+ if (!isString(key) || key === "") {
1112
+ const formatter = createFormatter(context, IntlFormatter, locale.replace(/!/g, ""), overrides, type);
1113
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
1114
+ }
1115
+ const targetLocale = resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type);
1116
+ if (!isString(targetLocale)) return context.unresolving ? -1 : key;
1117
+ const format = formats[targetLocale][key];
1118
+ const id = getFormatterCacheKey(targetLocale, key, overrides);
1119
+ let formatter = formatters.get(id);
1120
+ if (!formatter) {
1121
+ formatter = createFormatter(context, IntlFormatter, targetLocale, assign({}, format, overrides), type);
1122
+ formatters.set(id, formatter);
1123
+ }
1124
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
1125
+ }
1052
1126
  function getFormatterCacheKey(locale, key, overrides) {
1053
1127
  let id = `${locale}__${key}`;
1054
1128
  if (isPlainObject(overrides) && !isKeylessObject(overrides)) id = `${id}__${JSON.stringify(overrides)}`;
@@ -1083,7 +1157,7 @@ const Availabilities = {
1083
1157
  //#endregion
1084
1158
  //#region packages/core-base/src/datetime.ts
1085
1159
  function datetime(context, ...args) {
1086
- const { datetimeFormats, unresolving, onWarn } = context;
1160
+ const { datetimeFormats, onWarn } = context;
1087
1161
  const { __datetimeFormatters } = context;
1088
1162
  if (!Availabilities.dateTimeFormat) {
1089
1163
  onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
@@ -1093,25 +1167,7 @@ function datetime(context, ...args) {
1093
1167
  onWarn(getWarnMessage(CoreWarnCodes.INVALID_DATE_ARGUMENT, { value: String(args[0]) }));
1094
1168
  return "";
1095
1169
  }
1096
- const [key, value, options, overrides] = parseDateTimeArgs(...args);
1097
- const missingWarn = isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn;
1098
- const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
1099
- const part = !!options.part;
1100
- const locale = getLocale(context, options);
1101
- if (!isString(key) || key === "") {
1102
- const formatter = new Intl.DateTimeFormat(locale.replace(/!/g, ""), overrides);
1103
- return !part ? formatter.format(value) : formatter.formatToParts(value);
1104
- }
1105
- const targetLocale = resolveFormatLocale(context, key, locale, datetimeFormats, missingWarn, fallbackWarn, "datetime format");
1106
- if (!isString(targetLocale)) return unresolving ? -1 : key;
1107
- const format = datetimeFormats[targetLocale][key];
1108
- const id = getFormatterCacheKey(targetLocale, key, overrides);
1109
- let formatter = __datetimeFormatters.get(id);
1110
- if (!formatter) {
1111
- formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
1112
- __datetimeFormatters.set(id, formatter);
1113
- }
1114
- return !part ? formatter.format(value) : formatter.formatToParts(value);
1170
+ return formatValue(context, parseDateTimeArgs(...args), Intl.DateTimeFormat, __datetimeFormatters, datetimeFormats, "datetime format");
1115
1171
  }
1116
1172
  /** @internal */
1117
1173
  const DATETIME_FORMAT_OPTIONS_KEYS = [
@@ -1172,7 +1228,7 @@ function clearDateTimeFormat(ctx, locale, format) {
1172
1228
  //#endregion
1173
1229
  //#region packages/core-base/src/number.ts
1174
1230
  function number(context, ...args) {
1175
- const { numberFormats, unresolving, onWarn } = context;
1231
+ const { numberFormats, onWarn } = context;
1176
1232
  const { __numberFormatters } = context;
1177
1233
  if (!Availabilities.numberFormat) {
1178
1234
  onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
@@ -1182,25 +1238,7 @@ function number(context, ...args) {
1182
1238
  onWarn(getWarnMessage(CoreWarnCodes.INVALID_NUMBER_ARGUMENT, { value: String(args[0]) }));
1183
1239
  return "";
1184
1240
  }
1185
- const [key, value, options, overrides] = parseNumberArgs(...args);
1186
- const missingWarn = isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn;
1187
- const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
1188
- const part = !!options.part;
1189
- const locale = getLocale(context, options);
1190
- if (!isString(key) || key === "") {
1191
- const formatter = new Intl.NumberFormat(locale.replace(/!/g, ""), overrides);
1192
- return !part ? formatter.format(value) : formatter.formatToParts(value);
1193
- }
1194
- const targetLocale = resolveFormatLocale(context, key, locale, numberFormats, missingWarn, fallbackWarn, "number format");
1195
- if (!isString(targetLocale)) return unresolving ? -1 : key;
1196
- const format = numberFormats[targetLocale][key];
1197
- const id = getFormatterCacheKey(targetLocale, key, overrides);
1198
- let formatter = __numberFormatters.get(id);
1199
- if (!formatter) {
1200
- formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
1201
- __numberFormatters.set(id, formatter);
1202
- }
1203
- return !part ? formatter.format(value) : formatter.formatToParts(value);
1241
+ return formatValue(context, parseNumberArgs(...args), Intl.NumberFormat, __numberFormatters, numberFormats, "number format");
1204
1242
  }
1205
1243
  /** @internal */
1206
1244
  const NUMBER_FORMAT_OPTIONS_KEYS = [
@@ -1265,14 +1303,25 @@ const PLURAL_CATEGORY_ORDER = [
1265
1303
  "other"
1266
1304
  ];
1267
1305
  const intlPluralRulesCache = /* @__PURE__ */ new Map();
1268
- function getIntlPluralRules(locale) {
1269
- let cached = intlPluralRulesCache.get(locale);
1270
- if (!cached) {
1306
+ const INTL_PLURAL_RULES_CACHE_SIZE = 1e3;
1307
+ function createIntlPluralRules(locale) {
1308
+ try {
1309
+ if (Intl.PluralRules.supportedLocalesOf(locale).length === 0) return null;
1271
1310
  const rules = new Intl.PluralRules(locale);
1272
- cached = {
1311
+ return {
1273
1312
  rules,
1274
1313
  categories: rules.resolvedOptions().pluralCategories.slice().sort((a, b) => PLURAL_CATEGORY_ORDER.indexOf(a) - PLURAL_CATEGORY_ORDER.indexOf(b))
1275
1314
  };
1315
+ } catch {
1316
+ return null;
1317
+ }
1318
+ }
1319
+ function getIntlPluralRules(locale) {
1320
+ let cached = intlPluralRulesCache.get(locale);
1321
+ if (cached === void 0) {
1322
+ cached = createIntlPluralRules(locale);
1323
+ if (cached === null) warn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DEFAULT_PLURAL_RULE, { locale }));
1324
+ if (intlPluralRulesCache.size >= INTL_PLURAL_RULES_CACHE_SIZE) intlPluralRulesCache.delete(intlPluralRulesCache.keys().next().value);
1276
1325
  intlPluralRulesCache.set(locale, cached);
1277
1326
  }
1278
1327
  return cached;
@@ -1285,10 +1334,11 @@ function createMessageContext(options = {}) {
1285
1334
  const locale = options.locale;
1286
1335
  const pluralIndex = getPluralIndex(options);
1287
1336
  let resolvedPluralRule;
1288
- if (isString(locale) && isFunction(options.pluralRules?.[locale])) resolvedPluralRule = options.pluralRules[locale];
1337
+ if (isString(locale) && options.pluralRules && isFunction(getOwn(options.pluralRules, locale))) resolvedPluralRule = options.pluralRules[locale];
1289
1338
  else if (isString(locale) && typeof Intl !== "undefined" && typeof Intl.PluralRules !== "undefined") resolvedPluralRule = (choice, choicesLength) => {
1290
- const { rules, categories } = getIntlPluralRules(locale);
1291
- if (choicesLength > categories.length) return pluralDefault(choice, choicesLength);
1339
+ const intlPluralRules = getIntlPluralRules(locale);
1340
+ if (intlPluralRules === null || choicesLength > intlPluralRules.categories.length) return pluralDefault(choice, choicesLength);
1341
+ const { rules, categories } = intlPluralRules;
1292
1342
  const category = rules.select(Math.abs(choice));
1293
1343
  const index = categories.indexOf(category);
1294
1344
  return Math.min(index === -1 ? choicesLength - 1 : index, choicesLength - 1);
@@ -1299,16 +1349,16 @@ function createMessageContext(options = {}) {
1299
1349
  const _list = options.list || [];
1300
1350
  const list = (index) => _list[index];
1301
1351
  const _named = options.named || create();
1302
- if (isNumber(options.pluralIndex)) {
1303
- _named.count ??= options.pluralIndex;
1304
- _named.n ??= options.pluralIndex;
1305
- }
1306
- const named = (key) => _named[key];
1352
+ const hasPluralIndex = isNumber(options.pluralIndex);
1353
+ const named = (key) => {
1354
+ const value = isObjectPrototypeKey(key) ? getOwn(_named, key) : _named[key];
1355
+ return hasPluralIndex && value == null && (key === "count" || key === "n") ? options.pluralIndex : value;
1356
+ };
1307
1357
  function message(key, useLinked) {
1308
1358
  const msg = isFunction(options.messages) ? options.messages(key, !!useLinked) : isObject(options.messages) ? options.messages[key] : false;
1309
1359
  return !msg ? options.parent ? options.parent.message(key) : DEFAULT_MESSAGE : msg;
1310
1360
  }
1311
- const _modifier = (name) => options.modifiers ? options.modifiers[name] : DEFAULT_MODIFIER;
1361
+ const _modifier = (name) => options.modifiers ? getOwn(options.modifiers, name) : DEFAULT_MODIFIER;
1312
1362
  const normalize = isFunction(options.processor?.normalize) ? options.processor.normalize : DEFAULT_NORMALIZE;
1313
1363
  const interpolate = isFunction(options.processor?.interpolate) ? options.processor.interpolate : DEFAULT_INTERPOLATE;
1314
1364
  const type = isString(options.processor?.type) ? options.processor.type : DEFAULT_MESSAGE_DATA_TYPE;
@@ -1328,7 +1378,11 @@ function createMessageContext(options = {}) {
1328
1378
  const ret = message(key, true)(ctx);
1329
1379
  const resolved = ret === "" || ret === void 0 ? key : ret;
1330
1380
  const msg = type === "vnode" && isArray(resolved) && modifier ? resolved[0] : resolved;
1331
- return modifier ? _modifier(modifier)(msg, type) : msg;
1381
+ if (!modifier) return msg;
1382
+ const modify = _modifier(modifier);
1383
+ if (isFunction(modify)) return modify(msg, type);
1384
+ warnOnce(`Not found '${modifier}' modifier for the linked message of '${key}' key. Use a built-in modifier, or set a custom modifier with 'modifiers' option. So the linked message is used as is.`);
1385
+ return msg;
1332
1386
  };
1333
1387
  const ctx = {
1334
1388
  ["list"]: list,
@@ -1339,7 +1393,10 @@ function createMessageContext(options = {}) {
1339
1393
  ["type"]: type,
1340
1394
  ["interpolate"]: interpolate,
1341
1395
  ["normalize"]: normalize,
1342
- ["values"]: assign(create(), _list, _named)
1396
+ ["values"]: assign(create(), _list, _named, hasPluralIndex ? {
1397
+ count: named("count"),
1398
+ n: named("n")
1399
+ } : {})
1343
1400
  };
1344
1401
  return ctx;
1345
1402
  }
@@ -1358,7 +1415,7 @@ function translate(context, ...args) {
1358
1415
  let [format, targetLocale, message] = !resolvedMessage ? resolveMessageFormat(context, key, locale, context.fallbackLocale, isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn, isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn) : [
1359
1416
  key,
1360
1417
  locale,
1361
- context.messages[locale] || create()
1418
+ getOwn(context.messages, locale) || create()
1362
1419
  ];
1363
1420
  let cacheBaseKey = key;
1364
1421
  if (!resolvedMessage && !isMessageFormat(format)) {
@@ -1369,10 +1426,7 @@ function translate(context, ...args) {
1369
1426
  }
1370
1427
  }
1371
1428
  if (!resolvedMessage && (!isMessageFormat(format) || !isString(targetLocale))) return context.unresolving ? -1 : key;
1372
- if (isString(format) && context.messageCompiler == null) {
1373
- warn(`The message format compilation is not supported in this build. Because message compiler isn't included. You need to pre-compilation all message format. So translate function return '${stringifyKey(key)}'.`);
1374
- return key;
1375
- }
1429
+ if (isString(format) && context.messageCompiler == null) warn(`Cannot compile the message of '${stringifyKey(key)}' key, because no message compiler is set. Use 'messageCompiler' option of 'createCoreContext', or pre-compile the message. So translate function returns the message as is.`);
1376
1430
  let occurred = false;
1377
1431
  const onError = () => {
1378
1432
  occurred = true;
@@ -1380,7 +1434,14 @@ function translate(context, ...args) {
1380
1434
  const msg = !isMessageFunction(format) ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError) : format;
1381
1435
  if (occurred) return format;
1382
1436
  const msgContext = createMessageContext(getMessageContextOptions(context, targetLocale, message, options));
1383
- const messaged = inBrowser ? measureEvaluateMessage(context, msg, msgContext) : msg(msgContext);
1437
+ const timeline = startTimelineMeasure(context, "evaluation");
1438
+ const messaged = msg(msgContext);
1439
+ if (timeline) timeline.emitter.emit("message-evaluation", {
1440
+ type: "message-evaluation",
1441
+ value: messaged,
1442
+ time: endTimelineMeasure(timeline),
1443
+ groupId: toDevtoolsGroupId("translate", msg.key)
1444
+ });
1384
1445
  let ret = context.postTranslation ? context.postTranslation(messaged, key) : messaged;
1385
1446
  if (escapeParameter && isString(ret)) ret = sanitizeTranslatedHtml(ret);
1386
1447
  return ret;
@@ -1421,31 +1482,18 @@ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn
1421
1482
  groupId: toDevtoolsGroupId(type, key)
1422
1483
  });
1423
1484
  }
1424
- message = messages[targetLocale] || create();
1425
- let start = null;
1426
- let startTag;
1427
- let endTag;
1428
- if (inBrowser) {
1429
- start = window.performance.now();
1430
- startTag = "intlify-message-resolve-start";
1431
- endTag = "intlify-message-resolve-end";
1432
- mark?.(startTag);
1433
- }
1434
- if ((format = resolveValue(message, key)) === null) format = message[key];
1435
- if (inBrowser) {
1436
- const end = window.performance.now();
1437
- const emitter = context.__v_emitter;
1438
- if (emitter && start && format) emitter.emit("message-resolve", {
1485
+ message = getOwn(messages, targetLocale) || create();
1486
+ const timeline = startTimelineMeasure(context, "resolve");
1487
+ if ((format = resolveValue(message, key)) === null) format = getOwn(message, key);
1488
+ if (timeline) {
1489
+ const time = endTimelineMeasure(timeline);
1490
+ if (format) timeline.emitter.emit("message-resolve", {
1439
1491
  type: "message-resolve",
1440
1492
  key,
1441
1493
  message: format,
1442
- time: end - start,
1494
+ time,
1443
1495
  groupId: toDevtoolsGroupId(type, key)
1444
1496
  });
1445
- if (startTag && endTag && mark && measure) {
1446
- mark(endTag);
1447
- measure("intlify message resolve", startTag, endTag);
1448
- }
1449
1497
  }
1450
1498
  if (isMessageFormat(format)) break;
1451
1499
  if (!isImplicitFallback(targetLocale, locales)) {
@@ -1476,55 +1524,40 @@ function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey,
1476
1524
  msg.key = key;
1477
1525
  return msg;
1478
1526
  }
1479
- let start = null;
1480
- let startTag;
1481
- let endTag;
1482
- if (inBrowser && mark) {
1483
- start = window.performance.now();
1484
- startTag = "intlify-message-compilation-start";
1485
- endTag = "intlify-message-compilation-end";
1486
- mark?.(startTag);
1487
- }
1527
+ const timeline = startTimelineMeasure(context, "compilation");
1488
1528
  const msg = context.messageCompiler(format, getCompileContext(context, targetLocale, cacheBaseKey, format, context.warnHtmlMessage, onError));
1489
- if (inBrowser) {
1490
- const end = window.performance.now();
1491
- const emitter = context.__v_emitter;
1492
- if (emitter && start) emitter.emit("message-compilation", {
1493
- type: "message-compilation",
1494
- message: format,
1495
- time: end - start,
1496
- groupId: toDevtoolsGroupId("translate", key)
1497
- });
1498
- if (startTag && endTag && mark && measure) {
1499
- mark(endTag);
1500
- measure("intlify message compilation", startTag, endTag);
1501
- }
1502
- }
1529
+ if (timeline) timeline.emitter.emit("message-compilation", {
1530
+ type: "message-compilation",
1531
+ message: format,
1532
+ time: endTimelineMeasure(timeline),
1533
+ groupId: toDevtoolsGroupId("translate", key)
1534
+ });
1503
1535
  msg.locale = targetLocale;
1504
1536
  msg.key = key;
1505
1537
  msg.source = format;
1506
1538
  return msg;
1507
1539
  }
1508
- let measureEvaluateMessage;
1509
- if (inBrowser) {
1510
- const startTag = "intlify-message-evaluation-start";
1511
- const endTag = "intlify-message-evaluation-end";
1512
- measureEvaluateMessage = (context, msg, msgCtx) => {
1513
- const start = window.performance.now();
1514
- mark(startTag);
1515
- const messaged = msg(msgCtx);
1516
- const end = window.performance.now();
1517
- context.__v_emitter?.emit("message-evaluation", {
1518
- type: "message-evaluation",
1519
- value: messaged,
1520
- time: end - start,
1521
- groupId: toDevtoolsGroupId("translate", msg.key)
1522
- });
1523
- mark(endTag);
1524
- measure("intlify message evaluation", startTag, endTag);
1525
- return messaged;
1540
+ function startTimelineMeasure(context, name) {
1541
+ const emitter = context.__v_emitter;
1542
+ if (!inBrowser || !emitter) return null;
1543
+ const start = window.performance.now();
1544
+ mark?.(`intlify-message-${name}-start`);
1545
+ return {
1546
+ emitter,
1547
+ name,
1548
+ start
1526
1549
  };
1527
1550
  }
1551
+ function endTimelineMeasure({ name, start }) {
1552
+ const time = window.performance.now() - start;
1553
+ if (mark && measure) {
1554
+ const startTag = `intlify-message-${name}-start`;
1555
+ const endTag = `intlify-message-${name}-end`;
1556
+ mark(endTag);
1557
+ measure(`intlify message ${name}`, startTag, endTag);
1558
+ }
1559
+ return time;
1560
+ }
1528
1561
  /** @internal */
1529
1562
  function parseTranslateArgs(...args) {
1530
1563
  const [arg1, arg2, arg3] = args;
@@ -1599,9 +1632,4 @@ function getMessageContextOptions(context, locale, message, options) {
1599
1632
  };
1600
1633
  }
1601
1634
  //#endregion
1602
- //#region packages/core/src/runtime.ts
1603
- registerMessageCompiler(compile);
1604
- registerMessageResolver(resolveValue);
1605
- registerLocaleFallbacker(fallbackWithLocaleChain);
1606
- //#endregion
1607
- export { AST_NODE_PROPS_KEYS, CORE_ERROR_CODES_EXTEND_POINT, CORE_WARN_CODES_EXTEND_POINT, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_RESOLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compile, createCompileError, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getLocale, getLocaleMessage, getWarnMessage, handleMissing, isAlmostSameLocale, isImplicitFallback, isMessageAST, isMessageFormat, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveLocale, resolveValue, resolveWithKeyValue, setLocaleMessage, translate, updateFallbackLocale };
1635
+ export { AST_NODE_PROPS_KEYS, CORE_ERROR_CODES_EXTEND_POINT, CORE_WARN_CODES_EXTEND_POINT, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_RESOLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compile, createCompileError, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getLocale, getLocaleMessage, getWarnMessage, handleMissing, isAlmostSameLocale, isFallbackLocale, isImplicitFallback, isMessageAST, isMessageFormat, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, isWarnOption, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveLocale, resolveValue, resolveWithKeyValue, setLocaleMessage, translate, updateFallbackLocale };