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