@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.
@@ -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
  **/
@@ -1387,7 +1387,7 @@ var IntlifyCore = (function(exports) {
1387
1387
  return !detectError ? compileCache[cacheKey] = msg : msg;
1388
1388
  } else {
1389
1389
  if (!isMessageAST(message)) {
1390
- warn(`the message that is resolve with key '${context.key}' is not supported for jit compilation`);
1390
+ 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.`);
1391
1391
  return (() => message);
1392
1392
  }
1393
1393
  const cacheKey = message.cacheKey;
@@ -1718,7 +1718,7 @@ var IntlifyCore = (function(exports) {
1718
1718
  * @VueI18nGeneral
1719
1719
  */
1720
1720
  function resolveWithKeyValue(obj, path) {
1721
- return isObject(obj) ? obj[path] : null;
1721
+ return isObject(obj) ? getOwn(obj, path) : null;
1722
1722
  }
1723
1723
  /**
1724
1724
  * message resolver
@@ -1773,12 +1773,15 @@ var IntlifyCore = (function(exports) {
1773
1773
  FALLBACK_TO_DATE_FORMAT: 6,
1774
1774
  EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER: 7,
1775
1775
  INVALID_NUMBER_ARGUMENT: 8,
1776
- INVALID_DATE_ARGUMENT: 9
1776
+ INVALID_DATE_ARGUMENT: 9,
1777
+ IGNORE_UNSAFE_LOCALE: 10,
1778
+ FALLBACK_TO_DEFAULT_PLURAL_RULE: 11,
1779
+ FALLBACK_FROM_INVALID_LOCALE: 12
1777
1780
  };
1778
- const CORE_WARN_CODES_EXTEND_POINT = 10;
1781
+ const CORE_WARN_CODES_EXTEND_POINT = 13;
1779
1782
  /** @internal */
1780
1783
  const warnMessages = {
1781
- [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale messages.`,
1784
+ [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale {resource}.`,
1782
1785
  [CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
1783
1786
  [CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
1784
1787
  [CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
@@ -1786,7 +1789,10 @@ var IntlifyCore = (function(exports) {
1786
1789
  [CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`,
1787
1790
  [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.`,
1788
1791
  [CoreWarnCodes.INVALID_NUMBER_ARGUMENT]: `Invalid argument for number formatting: expected a number but received '{value}'.`,
1789
- [CoreWarnCodes.INVALID_DATE_ARGUMENT]: `Invalid argument for datetime formatting: expected a Date, number, or ISO string but received '{value}'.`
1792
+ [CoreWarnCodes.INVALID_DATE_ARGUMENT]: `Invalid argument for datetime formatting: expected a Date, number, or ISO string but received '{value}'.`,
1793
+ [CoreWarnCodes.IGNORE_UNSAFE_LOCALE]: `Ignore '{locale}' locale: it is a property name of Object.prototype`,
1794
+ [CoreWarnCodes.FALLBACK_TO_DEFAULT_PLURAL_RULE]: `Fall back to the default plural rule for '{locale}' locale: Intl.PluralRules does not support it`,
1795
+ [CoreWarnCodes.FALLBACK_FROM_INVALID_LOCALE]: `Fall back to '{target}' locale for {type} formatting with '{locale}' locale: it is not a BCP 47 language tag`
1790
1796
  };
1791
1797
  function getWarnMessage(code, ...args) {
1792
1798
  return format$1(warnMessages[code], ...args);
@@ -1797,7 +1803,7 @@ var IntlifyCore = (function(exports) {
1797
1803
  * Intlify core-base version
1798
1804
  * @internal
1799
1805
  */
1800
- const VERSION = "12.0.0-alpha.5";
1806
+ const VERSION = "12.0.0-alpha.6";
1801
1807
  const NOT_RESOLVED = -1;
1802
1808
  const DEFAULT_LOCALE = "en-US";
1803
1809
  const MISSING_RESOLVE_VALUE = "";
@@ -1863,15 +1869,15 @@ var IntlifyCore = (function(exports) {
1863
1869
  const version = isString(options.version) ? options.version : VERSION;
1864
1870
  const locale = isString(options.locale) || isFunction(options.locale) ? options.locale : DEFAULT_LOCALE;
1865
1871
  const _locale = isFunction(locale) ? DEFAULT_LOCALE : locale;
1866
- const fallbackLocale = isArray(options.fallbackLocale) || isPlainObject(options.fallbackLocale) || isString(options.fallbackLocale) || options.fallbackLocale === false ? options.fallbackLocale : _locale;
1872
+ const fallbackLocale = isFallbackLocale(options.fallbackLocale) ? options.fallbackLocale : _locale;
1867
1873
  const messages = isPlainObject(options.messages) ? options.messages : createResources(_locale);
1868
1874
  const datetimeFormats = isPlainObject(options.datetimeFormats) ? options.datetimeFormats : createResources(_locale);
1869
1875
  const numberFormats = isPlainObject(options.numberFormats) ? options.numberFormats : createResources(_locale);
1870
1876
  const modifiers = assign(create(), options.modifiers, getDefaultLinkedModifiers());
1871
1877
  const pluralRules = options.pluralRules || create();
1872
1878
  const missing = isFunction(options.missing) ? options.missing : null;
1873
- const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn) ? options.missingWarn : true;
1874
- const fallbackWarn = isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn) ? options.fallbackWarn : true;
1879
+ const missingWarn = isWarnOption(options.missingWarn) ? options.missingWarn : true;
1880
+ const fallbackWarn = isWarnOption(options.fallbackWarn) ? options.fallbackWarn : true;
1875
1881
  const fallbackFormat = !!options.fallbackFormat;
1876
1882
  const unresolving = !!options.unresolving;
1877
1883
  const postTranslation = isFunction(options.postTranslation) ? options.postTranslation : null;
@@ -1882,9 +1888,6 @@ var IntlifyCore = (function(exports) {
1882
1888
  const messageResolver = isFunction(options.messageResolver) ? options.messageResolver : _resolver || resolveWithKeyValue;
1883
1889
  const localeFallbacker = isFunction(options.localeFallbacker) ? options.localeFallbacker : _fallbacker || fallbackWithSimple;
1884
1890
  const fallbackContext = isObject(options.fallbackContext) ? options.fallbackContext : void 0;
1885
- const internalOptions = options;
1886
- const __datetimeFormatters = isObject(internalOptions.__datetimeFormatters) ? internalOptions.__datetimeFormatters : /* @__PURE__ */ new Map();
1887
- const __numberFormatters = isObject(internalOptions.__numberFormatters) ? internalOptions.__numberFormatters : /* @__PURE__ */ new Map();
1888
1891
  _cid++;
1889
1892
  const context = {
1890
1893
  version,
@@ -1911,9 +1914,8 @@ var IntlifyCore = (function(exports) {
1911
1914
  };
1912
1915
  context.datetimeFormats = datetimeFormats;
1913
1916
  context.numberFormats = numberFormats;
1914
- context.__datetimeFormatters = __datetimeFormatters;
1915
- context.__numberFormatters = __numberFormatters;
1916
- context.__v_emitter = internalOptions.__v_emitter != null ? internalOptions.__v_emitter : void 0;
1917
+ context.__datetimeFormatters = /* @__PURE__ */ new Map();
1918
+ context.__numberFormatters = /* @__PURE__ */ new Map();
1917
1919
  return context;
1918
1920
  }
1919
1921
  const createResources = (locale) => ({ [locale]: create() });
@@ -1931,10 +1933,21 @@ var IntlifyCore = (function(exports) {
1931
1933
  * @version 12.0.0
1932
1934
  */
1933
1935
  function setLocaleMessage(ctx, locale, messages) {
1934
- if (isObjectPrototypeKey(locale)) return;
1936
+ if (isObjectPrototypeKey(locale)) {
1937
+ ctx.onWarn(getWarnMessage(CoreWarnCodes.IGNORE_UNSAFE_LOCALE, { locale }));
1938
+ return;
1939
+ }
1935
1940
  ctx.messages[locale] = messages;
1936
1941
  }
1937
1942
  /** @internal */
1943
+ function isFallbackLocale(val) {
1944
+ return isString(val) || isArray(val) || isPlainObject(val) || val === false;
1945
+ }
1946
+ /** @internal */
1947
+ function isWarnOption(val) {
1948
+ return isBoolean(val) || isRegExp(val);
1949
+ }
1950
+ /** @internal */
1938
1951
  function isTranslateFallbackWarn(fallback, key) {
1939
1952
  return isRegExp(fallback) ? fallback.test(key) : fallback;
1940
1953
  }
@@ -1960,7 +1973,8 @@ var IntlifyCore = (function(exports) {
1960
1973
  } else {
1961
1974
  if (isTranslateMissingWarn(missingWarn, key)) onWarn(getWarnMessage(CoreWarnCodes.NOT_FOUND_KEY, {
1962
1975
  key,
1963
- locale
1976
+ locale,
1977
+ resource: type === "datetime format" ? "datetime formats" : type === "number format" ? "number formats" : "messages"
1964
1978
  }));
1965
1979
  return key;
1966
1980
  }
@@ -1974,6 +1988,11 @@ var IntlifyCore = (function(exports) {
1974
1988
  function updateFallbackLocale(ctx, locale, fallback) {
1975
1989
  invalidateLocaleChainCache(ctx, fallback);
1976
1990
  if (ctx.fallbackContext) invalidateLocaleChainCache(ctx.fallbackContext, fallback);
1991
+ {
1992
+ const { __datetimeFormatters, __numberFormatters } = ctx;
1993
+ __datetimeFormatters.clear();
1994
+ __numberFormatters.clear();
1995
+ }
1977
1996
  ctx.localeFallbacker(ctx, fallback, locale);
1978
1997
  }
1979
1998
  /** @internal */
@@ -2010,13 +2029,69 @@ var IntlifyCore = (function(exports) {
2010
2029
  groupId: toDevtoolsGroupId(type, key)
2011
2030
  });
2012
2031
  }
2013
- const format = (formats[targetLocale] || {})[key];
2032
+ const format = getOwn(getOwn(formats, targetLocale) || {}, key);
2014
2033
  if (isPlainObject(format) && isString(targetLocale)) return targetLocale;
2015
2034
  handleMissing(context, key, targetLocale, missingWarn, type);
2016
2035
  from = targetLocale;
2017
2036
  }
2018
2037
  return null;
2019
2038
  }
2039
+ function isLanguageTag(locale) {
2040
+ try {
2041
+ Intl.getCanonicalLocales(locale);
2042
+ return true;
2043
+ } catch {
2044
+ return false;
2045
+ }
2046
+ }
2047
+ /**
2048
+ * Create an `Intl.DateTimeFormat` or `Intl.NumberFormat` formatter
2049
+ *
2050
+ * @remarks
2051
+ * `Intl` throws a RangeError for a locale that is not a BCP 47 language tag (e.g. `pt_BR`),
2052
+ * so fall back to the first language tag in the locale chain, or the default locale
2053
+ */
2054
+ function createFormatter(context, IntlFormatter, locale, options, type) {
2055
+ try {
2056
+ return new IntlFormatter(locale, options);
2057
+ } catch (error) {
2058
+ if (isLanguageTag(locale)) throw error;
2059
+ const { fallbackLocale, localeFallbacker, onWarn } = context;
2060
+ const target = localeFallbacker(context, fallbackLocale, locale).find(isLanguageTag) || "en-US";
2061
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_FROM_INVALID_LOCALE, {
2062
+ locale,
2063
+ target,
2064
+ type: type === "datetime format" ? "datetime" : "number"
2065
+ }));
2066
+ return new IntlFormatter(target, options);
2067
+ }
2068
+ }
2069
+ /**
2070
+ * Format a value with the format of a key, or only with the overrides when no key is given
2071
+ *
2072
+ * @remarks
2073
+ * The common part of `datetime()` and `number()`, after they check and parse the arguments
2074
+ */
2075
+ function formatValue(context, [key, value, options, overrides], IntlFormatter, formatters, formats, type) {
2076
+ const missingWarn = isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn;
2077
+ const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
2078
+ const part = !!options.part;
2079
+ const locale = getLocale(context, options);
2080
+ if (!isString(key) || key === "") {
2081
+ const formatter = createFormatter(context, IntlFormatter, locale.replace(/!/g, ""), overrides, type);
2082
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
2083
+ }
2084
+ const targetLocale = resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type);
2085
+ if (!isString(targetLocale)) return context.unresolving ? -1 : key;
2086
+ const format = formats[targetLocale][key];
2087
+ const id = getFormatterCacheKey(targetLocale, key, overrides);
2088
+ let formatter = formatters.get(id);
2089
+ if (!formatter) {
2090
+ formatter = createFormatter(context, IntlFormatter, targetLocale, assign({}, format, overrides), type);
2091
+ formatters.set(id, formatter);
2092
+ }
2093
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
2094
+ }
2020
2095
  function getFormatterCacheKey(locale, key, overrides) {
2021
2096
  let id = `${locale}__${key}`;
2022
2097
  if (isPlainObject(overrides) && !isKeylessObject(overrides)) id = `${id}__${JSON.stringify(overrides)}`;
@@ -2051,7 +2126,7 @@ var IntlifyCore = (function(exports) {
2051
2126
  //#endregion
2052
2127
  //#region packages/core-base/src/datetime.ts
2053
2128
  function datetime(context, ...args) {
2054
- const { datetimeFormats, unresolving, onWarn } = context;
2129
+ const { datetimeFormats, onWarn } = context;
2055
2130
  const { __datetimeFormatters } = context;
2056
2131
  if (!Availabilities.dateTimeFormat) {
2057
2132
  onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
@@ -2061,25 +2136,7 @@ var IntlifyCore = (function(exports) {
2061
2136
  onWarn(getWarnMessage(CoreWarnCodes.INVALID_DATE_ARGUMENT, { value: String(args[0]) }));
2062
2137
  return "";
2063
2138
  }
2064
- const [key, value, options, overrides] = parseDateTimeArgs(...args);
2065
- const missingWarn = isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn;
2066
- const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
2067
- const part = !!options.part;
2068
- const locale = getLocale(context, options);
2069
- if (!isString(key) || key === "") {
2070
- const formatter = new Intl.DateTimeFormat(locale.replace(/!/g, ""), overrides);
2071
- return !part ? formatter.format(value) : formatter.formatToParts(value);
2072
- }
2073
- const targetLocale = resolveFormatLocale(context, key, locale, datetimeFormats, missingWarn, fallbackWarn, "datetime format");
2074
- if (!isString(targetLocale)) return unresolving ? -1 : key;
2075
- const format = datetimeFormats[targetLocale][key];
2076
- const id = getFormatterCacheKey(targetLocale, key, overrides);
2077
- let formatter = __datetimeFormatters.get(id);
2078
- if (!formatter) {
2079
- formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
2080
- __datetimeFormatters.set(id, formatter);
2081
- }
2082
- return !part ? formatter.format(value) : formatter.formatToParts(value);
2139
+ return formatValue(context, parseDateTimeArgs(...args), Intl.DateTimeFormat, __datetimeFormatters, datetimeFormats, "datetime format");
2083
2140
  }
2084
2141
  /** @internal */
2085
2142
  const DATETIME_FORMAT_OPTIONS_KEYS = [
@@ -2140,7 +2197,7 @@ var IntlifyCore = (function(exports) {
2140
2197
  //#endregion
2141
2198
  //#region packages/core-base/src/number.ts
2142
2199
  function number(context, ...args) {
2143
- const { numberFormats, unresolving, onWarn } = context;
2200
+ const { numberFormats, onWarn } = context;
2144
2201
  const { __numberFormatters } = context;
2145
2202
  if (!Availabilities.numberFormat) {
2146
2203
  onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
@@ -2150,25 +2207,7 @@ var IntlifyCore = (function(exports) {
2150
2207
  onWarn(getWarnMessage(CoreWarnCodes.INVALID_NUMBER_ARGUMENT, { value: String(args[0]) }));
2151
2208
  return "";
2152
2209
  }
2153
- const [key, value, options, overrides] = parseNumberArgs(...args);
2154
- const missingWarn = isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn;
2155
- const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
2156
- const part = !!options.part;
2157
- const locale = getLocale(context, options);
2158
- if (!isString(key) || key === "") {
2159
- const formatter = new Intl.NumberFormat(locale.replace(/!/g, ""), overrides);
2160
- return !part ? formatter.format(value) : formatter.formatToParts(value);
2161
- }
2162
- const targetLocale = resolveFormatLocale(context, key, locale, numberFormats, missingWarn, fallbackWarn, "number format");
2163
- if (!isString(targetLocale)) return unresolving ? -1 : key;
2164
- const format = numberFormats[targetLocale][key];
2165
- const id = getFormatterCacheKey(targetLocale, key, overrides);
2166
- let formatter = __numberFormatters.get(id);
2167
- if (!formatter) {
2168
- formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
2169
- __numberFormatters.set(id, formatter);
2170
- }
2171
- return !part ? formatter.format(value) : formatter.formatToParts(value);
2210
+ return formatValue(context, parseNumberArgs(...args), Intl.NumberFormat, __numberFormatters, numberFormats, "number format");
2172
2211
  }
2173
2212
  /** @internal */
2174
2213
  const NUMBER_FORMAT_OPTIONS_KEYS = [
@@ -2233,14 +2272,25 @@ var IntlifyCore = (function(exports) {
2233
2272
  "other"
2234
2273
  ];
2235
2274
  const intlPluralRulesCache = /* @__PURE__ */ new Map();
2236
- function getIntlPluralRules(locale) {
2237
- let cached = intlPluralRulesCache.get(locale);
2238
- if (!cached) {
2275
+ const INTL_PLURAL_RULES_CACHE_SIZE = 1e3;
2276
+ function createIntlPluralRules(locale) {
2277
+ try {
2278
+ if (Intl.PluralRules.supportedLocalesOf(locale).length === 0) return null;
2239
2279
  const rules = new Intl.PluralRules(locale);
2240
- cached = {
2280
+ return {
2241
2281
  rules,
2242
2282
  categories: rules.resolvedOptions().pluralCategories.slice().sort((a, b) => PLURAL_CATEGORY_ORDER.indexOf(a) - PLURAL_CATEGORY_ORDER.indexOf(b))
2243
2283
  };
2284
+ } catch {
2285
+ return null;
2286
+ }
2287
+ }
2288
+ function getIntlPluralRules(locale) {
2289
+ let cached = intlPluralRulesCache.get(locale);
2290
+ if (cached === void 0) {
2291
+ cached = createIntlPluralRules(locale);
2292
+ if (cached === null) warn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DEFAULT_PLURAL_RULE, { locale }));
2293
+ if (intlPluralRulesCache.size >= INTL_PLURAL_RULES_CACHE_SIZE) intlPluralRulesCache.delete(intlPluralRulesCache.keys().next().value);
2244
2294
  intlPluralRulesCache.set(locale, cached);
2245
2295
  }
2246
2296
  return cached;
@@ -2253,10 +2303,11 @@ var IntlifyCore = (function(exports) {
2253
2303
  const locale = options.locale;
2254
2304
  const pluralIndex = getPluralIndex(options);
2255
2305
  let resolvedPluralRule;
2256
- if (isString(locale) && isFunction(options.pluralRules?.[locale])) resolvedPluralRule = options.pluralRules[locale];
2306
+ if (isString(locale) && options.pluralRules && isFunction(getOwn(options.pluralRules, locale))) resolvedPluralRule = options.pluralRules[locale];
2257
2307
  else if (isString(locale) && typeof Intl !== "undefined" && typeof Intl.PluralRules !== "undefined") resolvedPluralRule = (choice, choicesLength) => {
2258
- const { rules, categories } = getIntlPluralRules(locale);
2259
- if (choicesLength > categories.length) return pluralDefault(choice, choicesLength);
2308
+ const intlPluralRules = getIntlPluralRules(locale);
2309
+ if (intlPluralRules === null || choicesLength > intlPluralRules.categories.length) return pluralDefault(choice, choicesLength);
2310
+ const { rules, categories } = intlPluralRules;
2260
2311
  const category = rules.select(Math.abs(choice));
2261
2312
  const index = categories.indexOf(category);
2262
2313
  return Math.min(index === -1 ? choicesLength - 1 : index, choicesLength - 1);
@@ -2267,16 +2318,16 @@ var IntlifyCore = (function(exports) {
2267
2318
  const _list = options.list || [];
2268
2319
  const list = (index) => _list[index];
2269
2320
  const _named = options.named || create();
2270
- if (isNumber(options.pluralIndex)) {
2271
- _named.count ??= options.pluralIndex;
2272
- _named.n ??= options.pluralIndex;
2273
- }
2274
- const named = (key) => _named[key];
2321
+ const hasPluralIndex = isNumber(options.pluralIndex);
2322
+ const named = (key) => {
2323
+ const value = isObjectPrototypeKey(key) ? getOwn(_named, key) : _named[key];
2324
+ return hasPluralIndex && value == null && (key === "count" || key === "n") ? options.pluralIndex : value;
2325
+ };
2275
2326
  function message(key, useLinked) {
2276
2327
  const msg = isFunction(options.messages) ? options.messages(key, !!useLinked) : isObject(options.messages) ? options.messages[key] : false;
2277
2328
  return !msg ? options.parent ? options.parent.message(key) : DEFAULT_MESSAGE : msg;
2278
2329
  }
2279
- const _modifier = (name) => options.modifiers ? options.modifiers[name] : DEFAULT_MODIFIER;
2330
+ const _modifier = (name) => options.modifiers ? getOwn(options.modifiers, name) : DEFAULT_MODIFIER;
2280
2331
  const normalize = isFunction(options.processor?.normalize) ? options.processor.normalize : DEFAULT_NORMALIZE;
2281
2332
  const interpolate = isFunction(options.processor?.interpolate) ? options.processor.interpolate : DEFAULT_INTERPOLATE;
2282
2333
  const type = isString(options.processor?.type) ? options.processor.type : DEFAULT_MESSAGE_DATA_TYPE;
@@ -2296,7 +2347,11 @@ var IntlifyCore = (function(exports) {
2296
2347
  const ret = message(key, true)(ctx);
2297
2348
  const resolved = ret === "" || ret === void 0 ? key : ret;
2298
2349
  const msg = type === "vnode" && isArray(resolved) && modifier ? resolved[0] : resolved;
2299
- return modifier ? _modifier(modifier)(msg, type) : msg;
2350
+ if (!modifier) return msg;
2351
+ const modify = _modifier(modifier);
2352
+ if (isFunction(modify)) return modify(msg, type);
2353
+ 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.`);
2354
+ return msg;
2300
2355
  };
2301
2356
  const ctx = {
2302
2357
  ["list"]: list,
@@ -2307,7 +2362,10 @@ var IntlifyCore = (function(exports) {
2307
2362
  ["type"]: type,
2308
2363
  ["interpolate"]: interpolate,
2309
2364
  ["normalize"]: normalize,
2310
- ["values"]: assign(create(), _list, _named)
2365
+ ["values"]: assign(create(), _list, _named, hasPluralIndex ? {
2366
+ count: named("count"),
2367
+ n: named("n")
2368
+ } : {})
2311
2369
  };
2312
2370
  return ctx;
2313
2371
  }
@@ -2326,7 +2384,7 @@ var IntlifyCore = (function(exports) {
2326
2384
  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) : [
2327
2385
  key,
2328
2386
  locale,
2329
- context.messages[locale] || create()
2387
+ getOwn(context.messages, locale) || create()
2330
2388
  ];
2331
2389
  let cacheBaseKey = key;
2332
2390
  if (!resolvedMessage && !isMessageFormat(format)) {
@@ -2337,10 +2395,7 @@ var IntlifyCore = (function(exports) {
2337
2395
  }
2338
2396
  }
2339
2397
  if (!resolvedMessage && (!isMessageFormat(format) || !isString(targetLocale))) return context.unresolving ? -1 : key;
2340
- if (isString(format) && context.messageCompiler == null) {
2341
- 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)}'.`);
2342
- return key;
2343
- }
2398
+ 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.`);
2344
2399
  let occurred = false;
2345
2400
  const onError = () => {
2346
2401
  occurred = true;
@@ -2348,7 +2403,14 @@ var IntlifyCore = (function(exports) {
2348
2403
  const msg = !isMessageFunction(format) ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError) : format;
2349
2404
  if (occurred) return format;
2350
2405
  const msgContext = createMessageContext(getMessageContextOptions(context, targetLocale, message, options));
2351
- const messaged = inBrowser ? measureEvaluateMessage(context, msg, msgContext) : msg(msgContext);
2406
+ const timeline = startTimelineMeasure(context, "evaluation");
2407
+ const messaged = msg(msgContext);
2408
+ if (timeline) timeline.emitter.emit("message-evaluation", {
2409
+ type: "message-evaluation",
2410
+ value: messaged,
2411
+ time: endTimelineMeasure(timeline),
2412
+ groupId: toDevtoolsGroupId("translate", msg.key)
2413
+ });
2352
2414
  let ret = context.postTranslation ? context.postTranslation(messaged, key) : messaged;
2353
2415
  if (escapeParameter && isString(ret)) ret = sanitizeTranslatedHtml(ret);
2354
2416
  return ret;
@@ -2389,31 +2451,18 @@ var IntlifyCore = (function(exports) {
2389
2451
  groupId: toDevtoolsGroupId(type, key)
2390
2452
  });
2391
2453
  }
2392
- message = messages[targetLocale] || create();
2393
- let start = null;
2394
- let startTag;
2395
- let endTag;
2396
- if (inBrowser) {
2397
- start = window.performance.now();
2398
- startTag = "intlify-message-resolve-start";
2399
- endTag = "intlify-message-resolve-end";
2400
- mark?.(startTag);
2401
- }
2402
- if ((format = resolveValue(message, key)) === null) format = message[key];
2403
- if (inBrowser) {
2404
- const end = window.performance.now();
2405
- const emitter = context.__v_emitter;
2406
- if (emitter && start && format) emitter.emit("message-resolve", {
2454
+ message = getOwn(messages, targetLocale) || create();
2455
+ const timeline = startTimelineMeasure(context, "resolve");
2456
+ if ((format = resolveValue(message, key)) === null) format = getOwn(message, key);
2457
+ if (timeline) {
2458
+ const time = endTimelineMeasure(timeline);
2459
+ if (format) timeline.emitter.emit("message-resolve", {
2407
2460
  type: "message-resolve",
2408
2461
  key,
2409
2462
  message: format,
2410
- time: end - start,
2463
+ time,
2411
2464
  groupId: toDevtoolsGroupId(type, key)
2412
2465
  });
2413
- if (startTag && endTag && mark && measure) {
2414
- mark(endTag);
2415
- measure("intlify message resolve", startTag, endTag);
2416
- }
2417
2466
  }
2418
2467
  if (isMessageFormat(format)) break;
2419
2468
  if (!isImplicitFallback(targetLocale, locales)) {
@@ -2444,55 +2493,40 @@ var IntlifyCore = (function(exports) {
2444
2493
  msg.key = key;
2445
2494
  return msg;
2446
2495
  }
2447
- let start = null;
2448
- let startTag;
2449
- let endTag;
2450
- if (inBrowser && mark) {
2451
- start = window.performance.now();
2452
- startTag = "intlify-message-compilation-start";
2453
- endTag = "intlify-message-compilation-end";
2454
- mark?.(startTag);
2455
- }
2496
+ const timeline = startTimelineMeasure(context, "compilation");
2456
2497
  const msg = context.messageCompiler(format, getCompileContext(context, targetLocale, cacheBaseKey, format, context.warnHtmlMessage, onError));
2457
- if (inBrowser) {
2458
- const end = window.performance.now();
2459
- const emitter = context.__v_emitter;
2460
- if (emitter && start) emitter.emit("message-compilation", {
2461
- type: "message-compilation",
2462
- message: format,
2463
- time: end - start,
2464
- groupId: toDevtoolsGroupId("translate", key)
2465
- });
2466
- if (startTag && endTag && mark && measure) {
2467
- mark(endTag);
2468
- measure("intlify message compilation", startTag, endTag);
2469
- }
2470
- }
2498
+ if (timeline) timeline.emitter.emit("message-compilation", {
2499
+ type: "message-compilation",
2500
+ message: format,
2501
+ time: endTimelineMeasure(timeline),
2502
+ groupId: toDevtoolsGroupId("translate", key)
2503
+ });
2471
2504
  msg.locale = targetLocale;
2472
2505
  msg.key = key;
2473
2506
  msg.source = format;
2474
2507
  return msg;
2475
2508
  }
2476
- let measureEvaluateMessage;
2477
- if (inBrowser) {
2478
- const startTag = "intlify-message-evaluation-start";
2479
- const endTag = "intlify-message-evaluation-end";
2480
- measureEvaluateMessage = (context, msg, msgCtx) => {
2481
- const start = window.performance.now();
2482
- mark(startTag);
2483
- const messaged = msg(msgCtx);
2484
- const end = window.performance.now();
2485
- context.__v_emitter?.emit("message-evaluation", {
2486
- type: "message-evaluation",
2487
- value: messaged,
2488
- time: end - start,
2489
- groupId: toDevtoolsGroupId("translate", msg.key)
2490
- });
2491
- mark(endTag);
2492
- measure("intlify message evaluation", startTag, endTag);
2493
- return messaged;
2509
+ function startTimelineMeasure(context, name) {
2510
+ const emitter = context.__v_emitter;
2511
+ if (!inBrowser || !emitter) return null;
2512
+ const start = window.performance.now();
2513
+ mark?.(`intlify-message-${name}-start`);
2514
+ return {
2515
+ emitter,
2516
+ name,
2517
+ start
2494
2518
  };
2495
2519
  }
2520
+ function endTimelineMeasure({ name, start }) {
2521
+ const time = window.performance.now() - start;
2522
+ if (mark && measure) {
2523
+ const startTag = `intlify-message-${name}-start`;
2524
+ const endTag = `intlify-message-${name}-end`;
2525
+ mark(endTag);
2526
+ measure(`intlify message ${name}`, startTag, endTag);
2527
+ }
2528
+ return time;
2529
+ }
2496
2530
  /** @internal */
2497
2531
  function parseTranslateArgs(...args) {
2498
2532
  const [arg1, arg2, arg3] = args;
@@ -2594,12 +2628,14 @@ var IntlifyCore = (function(exports) {
2594
2628
  exports.getWarnMessage = getWarnMessage;
2595
2629
  exports.handleMissing = handleMissing;
2596
2630
  exports.isAlmostSameLocale = isAlmostSameLocale;
2631
+ exports.isFallbackLocale = isFallbackLocale;
2597
2632
  exports.isImplicitFallback = isImplicitFallback;
2598
2633
  exports.isMessageAST = isMessageAST;
2599
2634
  exports.isMessageFormat = isMessageFormat;
2600
2635
  exports.isMessageFunction = isMessageFunction;
2601
2636
  exports.isTranslateFallbackWarn = isTranslateFallbackWarn;
2602
2637
  exports.isTranslateMissingWarn = isTranslateMissingWarn;
2638
+ exports.isWarnOption = isWarnOption;
2603
2639
  exports.number = number;
2604
2640
  exports.parse = parse;
2605
2641
  exports.parseDateTimeArgs = parseDateTimeArgs;