@intlify/core 9.2.0-beta.4 → 9.2.0-beta.40
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.cjs.js +4 -4
- package/dist/core.cjs.prod.js +4 -4
- package/dist/core.esm-browser.js +201 -48
- package/dist/core.esm-browser.prod.js +3 -3
- package/dist/core.esm-bundler.js +2 -2
- package/dist/core.global.js +205 -48
- package/dist/core.global.prod.js +3 -3
- package/dist/core.runtime.esm-browser.js +163 -31
- package/dist/core.runtime.esm-browser.prod.js +3 -3
- package/dist/core.runtime.esm-bundler.js +2 -2
- package/dist/core.runtime.global.js +167 -31
- package/dist/core.runtime.global.prod.js +3 -3
- package/index.mjs +1 -0
- package/package.json +16 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* core v9.2.0-beta.
|
|
3
|
-
* (c)
|
|
2
|
+
* core v9.2.0-beta.40
|
|
3
|
+
* (c) 2022 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
@@ -494,14 +494,15 @@ function createMessageContext(options = {}) {
|
|
|
494
494
|
isFunction(options.pluralRules[locale])
|
|
495
495
|
? pluralDefault
|
|
496
496
|
: undefined;
|
|
497
|
-
const plural = (messages) =>
|
|
497
|
+
const plural = (messages) => {
|
|
498
|
+
return messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
|
|
499
|
+
};
|
|
498
500
|
const _list = options.list || [];
|
|
499
501
|
const list = (index) => _list[index];
|
|
500
502
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
501
503
|
const _named = options.named || {};
|
|
502
504
|
isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
|
|
503
505
|
const named = (key) => _named[key];
|
|
504
|
-
// TODO: need to design resolve message function?
|
|
505
506
|
function message(key) {
|
|
506
507
|
// prettier-ignore
|
|
507
508
|
const msg = isFunction(options.messages)
|
|
@@ -528,15 +529,39 @@ function createMessageContext(options = {}) {
|
|
|
528
529
|
const type = isPlainObject(options.processor) && isString(options.processor.type)
|
|
529
530
|
? options.processor.type
|
|
530
531
|
: DEFAULT_MESSAGE_DATA_TYPE;
|
|
532
|
+
const linked = (key, ...args) => {
|
|
533
|
+
const [arg1, arg2] = args;
|
|
534
|
+
let type = 'text';
|
|
535
|
+
let modifier = '';
|
|
536
|
+
if (args.length === 1) {
|
|
537
|
+
if (isObject(arg1)) {
|
|
538
|
+
modifier = arg1.modifier || modifier;
|
|
539
|
+
type = arg1.type || type;
|
|
540
|
+
}
|
|
541
|
+
else if (isString(arg1)) {
|
|
542
|
+
modifier = arg1 || modifier;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
else if (args.length === 2) {
|
|
546
|
+
if (isString(arg1)) {
|
|
547
|
+
modifier = arg1 || modifier;
|
|
548
|
+
}
|
|
549
|
+
if (isString(arg2)) {
|
|
550
|
+
type = arg2 || type;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
let msg = message(key)(ctx);
|
|
554
|
+
// The message in vnode resolved with linked are returned as an array by processor.nomalize
|
|
555
|
+
if (type === 'vnode' && isArray(msg) && modifier) {
|
|
556
|
+
msg = msg[0];
|
|
557
|
+
}
|
|
558
|
+
return modifier ? _modifier(modifier)(msg, type) : msg;
|
|
559
|
+
};
|
|
531
560
|
const ctx = {
|
|
532
561
|
["list" /* LIST */]: list,
|
|
533
562
|
["named" /* NAMED */]: named,
|
|
534
563
|
["plural" /* PLURAL */]: plural,
|
|
535
|
-
["linked" /* LINKED */]:
|
|
536
|
-
// TODO: should check `key`
|
|
537
|
-
const msg = message(key)(ctx);
|
|
538
|
-
return isString(modifier) ? _modifier(modifier)(msg) : msg;
|
|
539
|
-
},
|
|
564
|
+
["linked" /* LINKED */]: linked,
|
|
540
565
|
["message" /* MESSAGE */]: message,
|
|
541
566
|
["type" /* TYPE */]: type,
|
|
542
567
|
["interpolate" /* INTERPOLATE */]: interpolate,
|
|
@@ -715,18 +740,37 @@ function appendItemToChain(chain, target, blocks) {
|
|
|
715
740
|
* Intlify core-base version
|
|
716
741
|
* @internal
|
|
717
742
|
*/
|
|
718
|
-
const VERSION = '9.2.0-beta.
|
|
743
|
+
const VERSION = '9.2.0-beta.40';
|
|
719
744
|
const NOT_REOSLVED = -1;
|
|
720
745
|
const DEFAULT_LOCALE = 'en-US';
|
|
721
746
|
const MISSING_RESOLVE_VALUE = '';
|
|
747
|
+
const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
|
|
722
748
|
function getDefaultLinkedModifiers() {
|
|
723
749
|
return {
|
|
724
|
-
upper: (val) =>
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
750
|
+
upper: (val, type) => {
|
|
751
|
+
// prettier-ignore
|
|
752
|
+
return type === 'text' && isString(val)
|
|
753
|
+
? val.toUpperCase()
|
|
754
|
+
: type === 'vnode' && isObject(val) && '__v_isVNode' in val
|
|
755
|
+
? val.children.toUpperCase()
|
|
756
|
+
: val;
|
|
757
|
+
},
|
|
758
|
+
lower: (val, type) => {
|
|
759
|
+
// prettier-ignore
|
|
760
|
+
return type === 'text' && isString(val)
|
|
761
|
+
? val.toLowerCase()
|
|
762
|
+
: type === 'vnode' && isObject(val) && '__v_isVNode' in val
|
|
763
|
+
? val.children.toLowerCase()
|
|
764
|
+
: val;
|
|
765
|
+
},
|
|
766
|
+
capitalize: (val, type) => {
|
|
767
|
+
// prettier-ignore
|
|
768
|
+
return (type === 'text' && isString(val)
|
|
769
|
+
? capitalize(val)
|
|
770
|
+
: type === 'vnode' && isObject(val) && '__v_isVNode' in val
|
|
771
|
+
? capitalize(val.children)
|
|
772
|
+
: val);
|
|
773
|
+
}
|
|
730
774
|
};
|
|
731
775
|
}
|
|
732
776
|
let _compiler;
|
|
@@ -761,6 +805,11 @@ const setAdditionalMeta = (meta) => {
|
|
|
761
805
|
_additionalMeta = meta;
|
|
762
806
|
};
|
|
763
807
|
const getAdditionalMeta = () => _additionalMeta;
|
|
808
|
+
let _fallbackContext = null;
|
|
809
|
+
const setFallbackContext = (context) => {
|
|
810
|
+
_fallbackContext = context;
|
|
811
|
+
};
|
|
812
|
+
const getFallbackContext = () => _fallbackContext;
|
|
764
813
|
// ID for CoreContext
|
|
765
814
|
let _cid = 0;
|
|
766
815
|
function createCoreContext(options = {}) {
|
|
@@ -812,6 +861,9 @@ function createCoreContext(options = {}) {
|
|
|
812
861
|
const localeFallbacker = isFunction(options.localeFallbacker)
|
|
813
862
|
? options.localeFallbacker
|
|
814
863
|
: _fallbacker || fallbackWithSimple;
|
|
864
|
+
const fallbackContext = isObject(options.fallbackContext)
|
|
865
|
+
? options.fallbackContext
|
|
866
|
+
: undefined;
|
|
815
867
|
const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
|
|
816
868
|
// setup internal options
|
|
817
869
|
const internalOptions = options;
|
|
@@ -845,6 +897,7 @@ function createCoreContext(options = {}) {
|
|
|
845
897
|
messageCompiler,
|
|
846
898
|
messageResolver,
|
|
847
899
|
localeFallbacker,
|
|
900
|
+
fallbackContext,
|
|
848
901
|
onWarn,
|
|
849
902
|
__meta
|
|
850
903
|
};
|
|
@@ -919,7 +972,7 @@ function compileToFunction(source, options = {}) {
|
|
|
919
972
|
}
|
|
920
973
|
|
|
921
974
|
let code = CompileErrorCodes.__EXTEND_POINT__;
|
|
922
|
-
const inc = () => code
|
|
975
|
+
const inc = () => ++code;
|
|
923
976
|
const CoreErrorCodes = {
|
|
924
977
|
INVALID_ARGUMENT: code,
|
|
925
978
|
INVALID_DATE_ARGUMENT: inc(),
|
|
@@ -941,7 +994,7 @@ const NOOP_MESSAGE_FUNCTION = () => '';
|
|
|
941
994
|
const isMessageFunction = (val) => isFunction(val);
|
|
942
995
|
// implementation of `translate` function
|
|
943
996
|
function translate(context, ...args) {
|
|
944
|
-
const { fallbackFormat, postTranslation, unresolving, fallbackLocale, messages } = context;
|
|
997
|
+
const { fallbackFormat, postTranslation, unresolving, messageCompiler, fallbackLocale, messages } = context;
|
|
945
998
|
const [key, options] = parseTranslateArgs(...args);
|
|
946
999
|
const missingWarn = isBoolean(options.missingWarn)
|
|
947
1000
|
? options.missingWarn
|
|
@@ -957,9 +1010,9 @@ function translate(context, ...args) {
|
|
|
957
1010
|
const defaultMsgOrKey = isString(options.default) || isBoolean(options.default) // default by function option
|
|
958
1011
|
? !isBoolean(options.default)
|
|
959
1012
|
? options.default
|
|
960
|
-
: key
|
|
1013
|
+
: (!messageCompiler ? () => key : key)
|
|
961
1014
|
: fallbackFormat // default by `fallbackFormat` option
|
|
962
|
-
? key
|
|
1015
|
+
? (!messageCompiler ? () => key : key)
|
|
963
1016
|
: '';
|
|
964
1017
|
const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== '';
|
|
965
1018
|
const locale = isString(options.locale) ? options.locale : context.locale;
|
|
@@ -967,13 +1020,19 @@ function translate(context, ...args) {
|
|
|
967
1020
|
escapeParameter && escapeParams(options);
|
|
968
1021
|
// resolve message format
|
|
969
1022
|
// eslint-disable-next-line prefer-const
|
|
970
|
-
let [
|
|
1023
|
+
let [formatScope, targetLocale, message] = !resolvedMessage
|
|
971
1024
|
? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn)
|
|
972
1025
|
: [
|
|
973
1026
|
key,
|
|
974
1027
|
locale,
|
|
975
1028
|
messages[locale] || {}
|
|
976
1029
|
];
|
|
1030
|
+
// NOTE:
|
|
1031
|
+
// Fix to work around `ssrTransfrom` bug in Vite.
|
|
1032
|
+
// https://github.com/vitejs/vite/issues/4306
|
|
1033
|
+
// To get around this, use temporary variables.
|
|
1034
|
+
// https://github.com/nuxt/framework/issues/1461#issuecomment-954606243
|
|
1035
|
+
let format = formatScope;
|
|
977
1036
|
// if you use default message, set it as message format!
|
|
978
1037
|
let cacheBaseKey = key;
|
|
979
1038
|
if (!resolvedMessage &&
|
|
@@ -1014,7 +1073,9 @@ function translate(context, ...args) {
|
|
|
1014
1073
|
const msgContext = createMessageContext(ctxOptions);
|
|
1015
1074
|
const messaged = evaluateMessage(context, msg, msgContext);
|
|
1016
1075
|
// if use post translation option, proceed it with handler
|
|
1017
|
-
const ret = postTranslation
|
|
1076
|
+
const ret = postTranslation
|
|
1077
|
+
? postTranslation(messaged, key)
|
|
1078
|
+
: messaged;
|
|
1018
1079
|
// NOTE: experimental !!
|
|
1019
1080
|
{
|
|
1020
1081
|
// prettier-ignore
|
|
@@ -1136,6 +1197,12 @@ function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey,
|
|
|
1136
1197
|
msg.key = msg.key || key;
|
|
1137
1198
|
return msg;
|
|
1138
1199
|
}
|
|
1200
|
+
if (messageCompiler == null) {
|
|
1201
|
+
const msg = (() => format);
|
|
1202
|
+
msg.locale = targetLocale;
|
|
1203
|
+
msg.key = key;
|
|
1204
|
+
return msg;
|
|
1205
|
+
}
|
|
1139
1206
|
// for vue-devtools timeline event
|
|
1140
1207
|
let start = null;
|
|
1141
1208
|
let startTag;
|
|
@@ -1262,9 +1329,14 @@ function getCompileOptions(context, locale, key, source, warnHtmlMessage, errorD
|
|
|
1262
1329
|
};
|
|
1263
1330
|
}
|
|
1264
1331
|
function getMessageContextOptions(context, locale, message, options) {
|
|
1265
|
-
const { modifiers, pluralRules, messageResolver: resolveValue } = context;
|
|
1332
|
+
const { modifiers, pluralRules, messageResolver: resolveValue, fallbackLocale, fallbackWarn, missingWarn, fallbackContext } = context;
|
|
1266
1333
|
const resolveMessage = (key) => {
|
|
1267
|
-
|
|
1334
|
+
let val = resolveValue(message, key);
|
|
1335
|
+
// fallback to root context
|
|
1336
|
+
if (val == null && fallbackContext) {
|
|
1337
|
+
const [, , message] = resolveMessageFormat(fallbackContext, key, locale, fallbackLocale, fallbackWarn, missingWarn);
|
|
1338
|
+
val = resolveValue(message, key);
|
|
1339
|
+
}
|
|
1268
1340
|
if (isString(val)) {
|
|
1269
1341
|
let occurred = false;
|
|
1270
1342
|
const errorDetector = () => {
|
|
@@ -1330,7 +1402,7 @@ function datetime(context, ...args) {
|
|
|
1330
1402
|
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1331
1403
|
fallbackLocale, locale);
|
|
1332
1404
|
if (!isString(key) || key === '') {
|
|
1333
|
-
return new Intl.DateTimeFormat(locale).format(value);
|
|
1405
|
+
return new Intl.DateTimeFormat(locale, overrides).format(value);
|
|
1334
1406
|
}
|
|
1335
1407
|
// resolve format
|
|
1336
1408
|
let datetimeFormat = {};
|
|
@@ -1385,9 +1457,32 @@ function datetime(context, ...args) {
|
|
|
1385
1457
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1386
1458
|
}
|
|
1387
1459
|
/** @internal */
|
|
1460
|
+
const DATETIME_FORMAT_OPTIONS_KEYS = [
|
|
1461
|
+
'localeMatcher',
|
|
1462
|
+
'weekday',
|
|
1463
|
+
'era',
|
|
1464
|
+
'year',
|
|
1465
|
+
'month',
|
|
1466
|
+
'day',
|
|
1467
|
+
'hour',
|
|
1468
|
+
'minute',
|
|
1469
|
+
'second',
|
|
1470
|
+
'timeZoneName',
|
|
1471
|
+
'formatMatcher',
|
|
1472
|
+
'hour12',
|
|
1473
|
+
'timeZone',
|
|
1474
|
+
'dateStyle',
|
|
1475
|
+
'timeStyle',
|
|
1476
|
+
'calendar',
|
|
1477
|
+
'dayPeriod',
|
|
1478
|
+
'numberingSystem',
|
|
1479
|
+
'hourCycle',
|
|
1480
|
+
'fractionalSecondDigits'
|
|
1481
|
+
];
|
|
1482
|
+
/** @internal */
|
|
1388
1483
|
function parseDateTimeArgs(...args) {
|
|
1389
1484
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1390
|
-
|
|
1485
|
+
const options = {};
|
|
1391
1486
|
let overrides = {};
|
|
1392
1487
|
let value;
|
|
1393
1488
|
if (isString(arg1)) {
|
|
@@ -1429,7 +1524,14 @@ function parseDateTimeArgs(...args) {
|
|
|
1429
1524
|
options.key = arg2;
|
|
1430
1525
|
}
|
|
1431
1526
|
else if (isPlainObject(arg2)) {
|
|
1432
|
-
|
|
1527
|
+
Object.keys(arg2).forEach(key => {
|
|
1528
|
+
if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1529
|
+
overrides[key] = arg2[key];
|
|
1530
|
+
}
|
|
1531
|
+
else {
|
|
1532
|
+
options[key] = arg2[key];
|
|
1533
|
+
}
|
|
1534
|
+
});
|
|
1433
1535
|
}
|
|
1434
1536
|
if (isString(arg3)) {
|
|
1435
1537
|
options.locale = arg3;
|
|
@@ -1474,7 +1576,7 @@ function number(context, ...args) {
|
|
|
1474
1576
|
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1475
1577
|
fallbackLocale, locale);
|
|
1476
1578
|
if (!isString(key) || key === '') {
|
|
1477
|
-
return new Intl.NumberFormat(locale).format(value);
|
|
1579
|
+
return new Intl.NumberFormat(locale, overrides).format(value);
|
|
1478
1580
|
}
|
|
1479
1581
|
// resolve format
|
|
1480
1582
|
let numberFormat = {};
|
|
@@ -1529,9 +1631,32 @@ function number(context, ...args) {
|
|
|
1529
1631
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1530
1632
|
}
|
|
1531
1633
|
/** @internal */
|
|
1634
|
+
const NUMBER_FORMAT_OPTIONS_KEYS = [
|
|
1635
|
+
'localeMatcher',
|
|
1636
|
+
'style',
|
|
1637
|
+
'currency',
|
|
1638
|
+
'currencyDisplay',
|
|
1639
|
+
'currencySign',
|
|
1640
|
+
'useGrouping',
|
|
1641
|
+
'minimumIntegerDigits',
|
|
1642
|
+
'minimumFractionDigits',
|
|
1643
|
+
'maximumFractionDigits',
|
|
1644
|
+
'minimumSignificantDigits',
|
|
1645
|
+
'maximumSignificantDigits',
|
|
1646
|
+
'compactDisplay',
|
|
1647
|
+
'notation',
|
|
1648
|
+
'signDisplay',
|
|
1649
|
+
'unit',
|
|
1650
|
+
'unitDisplay',
|
|
1651
|
+
'roundingMode',
|
|
1652
|
+
'roundingPriority',
|
|
1653
|
+
'roundingIncrement',
|
|
1654
|
+
'trailingZeroDisplay'
|
|
1655
|
+
];
|
|
1656
|
+
/** @internal */
|
|
1532
1657
|
function parseNumberArgs(...args) {
|
|
1533
1658
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1534
|
-
|
|
1659
|
+
const options = {};
|
|
1535
1660
|
let overrides = {};
|
|
1536
1661
|
if (!isNumber(arg1)) {
|
|
1537
1662
|
throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
@@ -1541,7 +1666,14 @@ function parseNumberArgs(...args) {
|
|
|
1541
1666
|
options.key = arg2;
|
|
1542
1667
|
}
|
|
1543
1668
|
else if (isPlainObject(arg2)) {
|
|
1544
|
-
|
|
1669
|
+
Object.keys(arg2).forEach(key => {
|
|
1670
|
+
if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1671
|
+
overrides[key] = arg2[key];
|
|
1672
|
+
}
|
|
1673
|
+
else {
|
|
1674
|
+
options[key] = arg2[key];
|
|
1675
|
+
}
|
|
1676
|
+
});
|
|
1545
1677
|
}
|
|
1546
1678
|
if (isString(arg3)) {
|
|
1547
1679
|
options.locale = arg3;
|
|
@@ -1571,4 +1703,4 @@ registerMessageResolver(resolveValue);
|
|
|
1571
1703
|
// register fallback locale at @intlify/core
|
|
1572
1704
|
registerLocaleFallbacker(fallbackWithLocaleChain);
|
|
1573
1705
|
|
|
1574
|
-
export { CompileErrorCodes, CoreErrorCodes, CoreWarnCodes, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_REOSLVED, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compileToFunction, createCompileError, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getAdditionalMeta, getDevToolsHook, getWarnMessage, handleMissing, initI18nDevTools, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveValue, resolveWithKeyValue, setAdditionalMeta, setDevToolsHook, translate, translateDevTools, updateFallbackLocale };
|
|
1706
|
+
export { CompileErrorCodes, CoreErrorCodes, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_REOSLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compileToFunction, createCompileError, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getAdditionalMeta, getDevToolsHook, getFallbackContext, getWarnMessage, handleMissing, initI18nDevTools, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveValue, resolveWithKeyValue, setAdditionalMeta, setDevToolsHook, setFallbackContext, translate, translateDevTools, updateFallbackLocale };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* core v9.2.0-beta.
|
|
3
|
-
* (c)
|
|
2
|
+
* core v9.2.0-beta.40
|
|
3
|
+
* (c) 2022 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
const e=/\{([0-9a-zA-Z]+)\}/g;const t=e=>JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029").replace(/\u0027/g,"\\u0027"),n=e=>"number"==typeof e&&isFinite(e),r=e=>"[object RegExp]"===p(e),a=e=>E(e)&&0===Object.keys(e).length;function o(e,t){"undefined"!=typeof console&&(console.warn("[intlify] "+e),t&&console.warn(t.stack))}const l=Object.assign;function s(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const c=Array.isArray,i=e=>"function"==typeof e,u=e=>"string"==typeof e,m=e=>"boolean"==typeof e,f=e=>null!==e&&"object"==typeof e,_=Object.prototype.toString,p=e=>_.call(e),E=e=>"[object Object]"===p(e),g={EXPECTED_TOKEN:1,INVALID_TOKEN_IN_PLACEHOLDER:2,UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER:3,UNKNOWN_ESCAPE_SEQUENCE:4,INVALID_UNICODE_ESCAPE_SEQUENCE:5,UNBALANCED_CLOSING_BRACE:6,UNTERMINATED_CLOSING_BRACE:7,EMPTY_PLACEHOLDER:8,NOT_ALLOW_NEST_PLACEHOLDER:9,INVALID_LINKED_FORMAT:10,MUST_HAVE_MESSAGES_IN_PLURAL:11,UNEXPECTED_EMPTY_LINKED_MODIFIER:12,UNEXPECTED_EMPTY_LINKED_KEY:13,UNEXPECTED_LEXICAL_ANALYSIS:14,__EXTEND_POINT__:15};function N(e,t,n={}){const{domain:r}=n,a=new SyntaxError(String(e));return a.code=e,t&&(a.location=t),a.domain=r,a}const A=[];A[0]={w:[0],i:[3,0],"[":[4],o:[7]},A[1]={w:[1],".":[2],"[":[4],o:[7]},A[2]={w:[2],i:[3,0],0:[3,0]},A[3]={i:[3,0],0:[3,0],w:[1,1],".":[2,1],"[":[4,1],o:[7,1]},A[4]={"'":[5,0],'"':[6,0],"[":[4,2],"]":[1,3],o:8,l:[4,0]},A[5]={"'":[4,0],o:8,l:[5,0]},A[6]={'"':[4,0],o:8,l:[6,0]};const d=/^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;function T(e){if(null==e)return"o";switch(e.charCodeAt(0)){case 91:case 93:case 46:case 34:case 39:return e;case 95:case 36:case 45:return"i";case 9:case 10:case 13:case 160:case 65279:case 8232:case 8233:return"w"}return"i"}function b(e){const t=e.trim();return("0"!==e.charAt(0)||!isNaN(parseInt(e)))&&(d.test(t)?function(e){const t=e.charCodeAt(0);return t!==e.charCodeAt(e.length-1)||34!==t&&39!==t?e:e.slice(1,-1)}(t):"*"+t)}function I(e){const t=[];let n,r,a,o,l,s,c,i=-1,u=0,m=0;const f=[];function _(){const t=e[i+1];if(5===u&&"'"===t||6===u&&'"'===t)return i++,a="\\"+t,f[0](),!0}for(f[0]=()=>{void 0===r?r=a:r+=a},f[1]=()=>{void 0!==r&&(t.push(r),r=void 0)},f[2]=()=>{f[0](),m++},f[3]=()=>{if(m>0)m--,u=4,f[0]();else{if(m=0,void 0===r)return!1;if(r=b(r),!1===r)return!1;f[1]()}};null!==u;)if(i++,n=e[i],"\\"!==n||!_()){if(o=T(n),c=A[u],l=c[o]||c.l||8,8===l)return;if(u=l[0],void 0!==l[1]&&(s=f[l[1]],s&&(a=n,!1===s())))return;if(7===u)return t}}const L=new Map;function F(e,t){return f(e)?e[t]:null}function O(e,t){if(!f(e))return null;let n=L.get(t);if(n||(n=I(t),n&&L.set(t,n)),!n)return null;const r=n.length;let a=e,o=0;for(;o<r;){const e=a[n[o]];if(void 0===e)return null;a=e,o++}return a}const h=e=>e,C=e=>"",R="text",k=e=>0===e.length?"":e.join(""),D=e=>null==e?"":c(e)||E(e)&&e.toString===_?JSON.stringify(e,null,2):String(e);function M(e,t){return e=Math.abs(e),2===t?e?e>1?1:0:1:e?Math.min(e,2):0}function w(e={}){const t=e.locale,r=function(e){const t=n(e.pluralIndex)?e.pluralIndex:-1;return e.named&&(n(e.named.count)||n(e.named.n))?n(e.named.count)?e.named.count:n(e.named.n)?e.named.n:t:t}(e),a=f(e.pluralRules)&&u(t)&&i(e.pluralRules[t])?e.pluralRules[t]:M,o=f(e.pluralRules)&&u(t)&&i(e.pluralRules[t])?M:void 0,l=e.list||[],s=e.named||{};n(e.pluralIndex)&&function(e,t){t.count||(t.count=e),t.n||(t.n=e)}(r,s);function c(t){const n=i(e.messages)?e.messages(t):!!f(e.messages)&&e.messages[t];return n||(e.parent?e.parent.message(t):C)}const m=E(e.processor)&&i(e.processor.normalize)?e.processor.normalize:k,_=E(e.processor)&&i(e.processor.interpolate)?e.processor.interpolate:D,p={list:e=>l[e],named:e=>s[e],plural:e=>e[a(r,e.length,o)],linked:(t,n)=>{const r=c(t)(p);return u(n)?(a=n,e.modifiers?e.modifiers[a]:h)(r):r;var a},message:c,type:E(e.processor)&&u(e.processor.type)?e.processor.type:"text",interpolate:_,normalize:m};return p}const y="i18n:init";let S=null;function U(e){S=e}function P(){return S}function v(e,t,n){S&&S.emit(y,{timestamp:Date.now(),i18n:e,version:t,meta:n})}const W=$("function:translate");function $(e){return t=>S&&S.emit(e,t)}const K={NOT_FOUND_KEY:1,FALLBACK_TO_TRANSLATE:2,CANNOT_FORMAT_NUMBER:3,FALLBACK_TO_NUMBER_FORMAT:4,CANNOT_FORMAT_DATE:5,FALLBACK_TO_DATE_FORMAT:6,__EXTEND_POINT__:7},B={[K.NOT_FOUND_KEY]:"Not found '{key}' key in '{locale}' locale messages.",[K.FALLBACK_TO_TRANSLATE]:"Fall back to translate '{key}' key with '{target}' locale.",[K.CANNOT_FORMAT_NUMBER]:"Cannot format a number value due to not supported Intl.NumberFormat.",[K.FALLBACK_TO_NUMBER_FORMAT]:"Fall back to number format '{key}' key with '{target}' locale.",[K.CANNOT_FORMAT_DATE]:"Cannot format a date value due to not supported Intl.DateTimeFormat.",[K.FALLBACK_TO_DATE_FORMAT]:"Fall back to datetime format '{key}' key with '{target}' locale."};function G(t,...n){return function(t,...n){return 1===n.length&&f(n[0])&&(n=n[0]),n&&n.hasOwnProperty||(n={}),t.replace(e,((e,t)=>n.hasOwnProperty(t)?n[t]:""))}(B[t],...n)}function V(e,t,n){return[...new Set([n,...c(t)?t:f(t)?Object.keys(t):u(t)?[t]:[n]])]}function j(e,t,n){const r=u(n)?n:J,a=e;a.__localeChainCache||(a.__localeChainCache=new Map);let o=a.__localeChainCache.get(r);if(!o){o=[];let e=[n];for(;c(e);)e=x(o,e,t);const l=c(t)||!E(t)?t:t.default?t.default:null;e=u(l)?[l]:l,c(e)&&x(o,e,!1),a.__localeChainCache.set(r,o)}return o}function x(e,t,n){let r=!0;for(let a=0;a<t.length&&m(r);a++){u(t[a])&&(r=H(e,t[a],n))}return r}function H(e,t,n){let r;const a=t.split("-");do{r=X(e,a.join("-"),n),a.splice(-1,1)}while(a.length&&!0===r);return r}function X(e,t,n){let r=!1;if(!e.includes(t)&&(r=!0,t)){r="!"!==t[t.length-1];const a=t.replace(/!/g,"");e.push(a),(c(n)||E(n))&&n[a]&&(r=n[a])}return r}const Y="9.2.0-beta.4",z=-1,J="en-US",Q="";let q,Z,ee;function te(e){q=e}function ne(e){Z=e}function re(e){ee=e}let ae=null;const oe=e=>{ae=e},le=()=>ae;let se=0;function ce(e={}){const t=u(e.version)?e.version:"9.2.0-beta.4",n=u(e.locale)?e.locale:J,a=c(e.fallbackLocale)||E(e.fallbackLocale)||u(e.fallbackLocale)||!1===e.fallbackLocale?e.fallbackLocale:n,s=E(e.messages)?e.messages:{[n]:{}},_=E(e.datetimeFormats)?e.datetimeFormats:{[n]:{}},p=E(e.numberFormats)?e.numberFormats:{[n]:{}},g=l({},e.modifiers||{},{upper:e=>u(e)?e.toUpperCase():e,lower:e=>u(e)?e.toLowerCase():e,capitalize:e=>u(e)?`${e.charAt(0).toLocaleUpperCase()}${e.substr(1)}`:e}),N=e.pluralRules||{},A=i(e.missing)?e.missing:null,d=!m(e.missingWarn)&&!r(e.missingWarn)||e.missingWarn,T=!m(e.fallbackWarn)&&!r(e.fallbackWarn)||e.fallbackWarn,b=!!e.fallbackFormat,I=!!e.unresolving,L=i(e.postTranslation)?e.postTranslation:null,O=E(e.processor)?e.processor:null,h=!m(e.warnHtmlMessage)||e.warnHtmlMessage,C=!!e.escapeParameter,R=i(e.messageCompiler)?e.messageCompiler:q,k=i(e.messageResolver)?e.messageResolver:Z||F,D=i(e.localeFallbacker)?e.localeFallbacker:ee||V,M=i(e.onWarn)?e.onWarn:o,w=e,y=f(w.__datetimeFormatters)?w.__datetimeFormatters:new Map,S=f(w.__numberFormatters)?w.__numberFormatters:new Map,U=f(w.__meta)?w.__meta:{};se++;const P={version:t,cid:se,locale:n,fallbackLocale:a,messages:s,modifiers:g,pluralRules:N,missing:A,missingWarn:d,fallbackWarn:T,fallbackFormat:b,unresolving:I,postTranslation:L,processor:O,warnHtmlMessage:h,escapeParameter:C,messageCompiler:R,messageResolver:k,localeFallbacker:D,onWarn:M,__meta:U};return P.datetimeFormats=_,P.numberFormats=p,P.__datetimeFormatters=y,P.__numberFormatters=S,P}function ie(e,t){return e instanceof RegExp?e.test(t):e}function ue(e,t){return e instanceof RegExp?e.test(t):e}function me(e,t,n,r,a){const{missing:o}=e;if(null!==o){const r=o(e,n,t,a);return u(r)?r:t}return t}function fe(e,t,n){e.__localeChainCache=new Map,e.localeFallbacker(e,n,t)}function _e(){}function pe(e,t={}){return()=>e}let Ee=g.__EXTEND_POINT__;const ge=()=>Ee++,Ne={INVALID_ARGUMENT:Ee,INVALID_DATE_ARGUMENT:ge(),INVALID_ISO_DATE_ARGUMENT:ge(),__EXTEND_POINT__:ge()};function Ae(e){return N(e,null,void 0)}const de=()=>"",Te=e=>i(e);function be(e,...t){const{fallbackFormat:r,postTranslation:a,unresolving:o,fallbackLocale:l,messages:_}=e,[p,E]=Le(...t),g=(m(E.missingWarn),m(E.fallbackWarn),m(E.escapeParameter)?E.escapeParameter:e.escapeParameter),N=!!E.resolvedMessage,A=u(E.default)||m(E.default)?m(E.default)?p:E.default:r?p:"",d=r||""!==A,T=u(E.locale)?E.locale:e.locale;g&&function(e){c(e.list)?e.list=e.list.map((e=>u(e)?s(e):e)):f(e.named)&&Object.keys(e.named).forEach((t=>{u(e.named[t])&&(e.named[t]=s(e.named[t]))}))}(E);let[b,I,L]=N?[p,T,_[T]||{}]:function(e,t,n,r,a,o){const{messages:l,messageResolver:s,localeFallbacker:c}=e,m=c(e,r,n);let f,_={},p=null;const E="translate";for(let n=0;n<m.length&&(f=m[n],_=l[f]||{},null===(p=s(_,t))&&(p=_[t]),!u(p)&&!i(p));n++){const n=me(e,t,f,0,E);n!==t&&(p=n)}return[p,f,_]}(e,p,T,l),F=p;if(N||u(b)||Te(b)||d&&(b=A,F=b),!(N||(u(b)||Te(b))&&u(I)))return o?-1:p;let O=!1;const h=Te(b)?b:Ie(e,p,I,b,F,(()=>{O=!0}));if(O)return b;const C=function(e,t,n){return t(n)}(0,h,w(function(e,t,r,a){const{modifiers:o,pluralRules:l,messageResolver:s}=e,c={locale:t,modifiers:o,pluralRules:l,messages:n=>{const a=s(r,n);if(u(a)){let r=!1;const o=Ie(e,n,t,a,n,(()=>{r=!0}));return r?de:o}return Te(a)?a:de}};e.processor&&(c.processor=e.processor);a.list&&(c.list=a.list);a.named&&(c.named=a.named);n(a.plural)&&(c.pluralIndex=a.plural);return c}(e,I,L,E)));return a?a(C):C}function Ie(e,n,r,a,o,l){const{messageCompiler:s,warnHtmlMessage:c}=e;if(Te(a)){const e=a;return e.locale=e.locale||r,e.key=e.key||n,e}const i=s(a,function(e,n,r,a,o,l){return{warnHtmlMessage:o,onError:e=>{throw l&&l(e),e},onCacheKey:e=>((e,n,r)=>t({l:e,k:n,s:r}))(n,r,e)}}(0,r,o,0,c,l));return i.locale=r,i.key=n,i.source=a,i}function Le(...e){const[t,r,o]=e,s={};if(!u(t)&&!n(t)&&!Te(t))throw Error(Ne.INVALID_ARGUMENT);const i=n(t)?String(t):(Te(t),t);return n(r)?s.plural=r:u(r)?s.default=r:E(r)&&!a(r)?s.named=r:c(r)&&(s.list=r),n(o)?s.plural=o:u(o)?s.default=o:E(o)&&l(s,o),[i,s]}function Fe(e,...t){const{datetimeFormats:n,unresolving:r,fallbackLocale:o,localeFallbacker:s}=e,{__datetimeFormatters:c}=e,[i,f,_,p]=Oe(...t);m(_.missingWarn);m(_.fallbackWarn);const g=!!_.part,N=u(_.locale)?_.locale:e.locale,A=s(e,o,N);if(!u(i)||""===i)return new Intl.DateTimeFormat(N).format(f);let d,T={},b=null;for(let t=0;t<A.length&&(d=A[t],T=n[d]||{},b=T[i],!E(b));t++)me(e,i,d,0,"datetime format");if(!E(b)||!u(d))return r?-1:i;let I=`${d}__${i}`;a(p)||(I=`${I}__${JSON.stringify(p)}`);let L=c.get(I);return L||(L=new Intl.DateTimeFormat(d,l({},b,p)),c.set(I,L)),g?L.formatToParts(f):L.format(f)}function Oe(...e){const[t,r,a,o]=e;let l,s={},c={};if(u(t)){const e=t.match(/(\d{4}-\d{2}-\d{2})(T|\s)?(.*)/);if(!e)throw Error(Ne.INVALID_ISO_DATE_ARGUMENT);const n=e[3]?e[3].trim().startsWith("T")?`${e[1].trim()}${e[3].trim()}`:`${e[1].trim()}T${e[3].trim()}`:e[1].trim();l=new Date(n);try{l.toISOString()}catch(e){throw Error(Ne.INVALID_ISO_DATE_ARGUMENT)}}else if("[object Date]"===p(t)){if(isNaN(t.getTime()))throw Error(Ne.INVALID_DATE_ARGUMENT);l=t}else{if(!n(t))throw Error(Ne.INVALID_ARGUMENT);l=t}return u(r)?s.key=r:E(r)&&(s=r),u(a)?s.locale=a:E(a)&&(c=a),E(o)&&(c=o),[s.key||"",l,s,c]}function he(e,t,n){const r=e;for(const e in n){const n=`${t}__${e}`;r.__datetimeFormatters.has(n)&&r.__datetimeFormatters.delete(n)}}function Ce(e,...t){const{numberFormats:n,unresolving:r,fallbackLocale:o,localeFallbacker:s}=e,{__numberFormatters:c}=e,[i,f,_,p]=Re(...t);m(_.missingWarn);m(_.fallbackWarn);const g=!!_.part,N=u(_.locale)?_.locale:e.locale,A=s(e,o,N);if(!u(i)||""===i)return new Intl.NumberFormat(N).format(f);let d,T={},b=null;for(let t=0;t<A.length&&(d=A[t],T=n[d]||{},b=T[i],!E(b));t++)me(e,i,d,0,"number format");if(!E(b)||!u(d))return r?-1:i;let I=`${d}__${i}`;a(p)||(I=`${I}__${JSON.stringify(p)}`);let L=c.get(I);return L||(L=new Intl.NumberFormat(d,l({},b,p)),c.set(I,L)),g?L.formatToParts(f):L.format(f)}function Re(...e){const[t,r,a,o]=e;let l={},s={};if(!n(t))throw Error(Ne.INVALID_ARGUMENT);const c=t;return u(r)?l.key=r:E(r)&&(l=r),u(a)?l.locale=a:E(a)&&(s=a),E(o)&&(s=o),[l.key||"",c,l,s]}function ke(e,t,n){const r=e;for(const e in n){const n=`${t}__${e}`;r.__numberFormatters.has(n)&&r.__numberFormatters.delete(n)}}ne(O),re(j);export{g as CompileErrorCodes,Ne as CoreErrorCodes,K as CoreWarnCodes,J as DEFAULT_LOCALE,R as DEFAULT_MESSAGE_DATA_TYPE,Q as MISSING_RESOLVE_VALUE,z as NOT_REOSLVED,Y as VERSION,_e as clearCompileCache,he as clearDateTimeFormat,ke as clearNumberFormat,pe as compileToFunction,N as createCompileError,ce as createCoreContext,Ae as createCoreError,w as createMessageContext,Fe as datetime,j as fallbackWithLocaleChain,V as fallbackWithSimple,le as getAdditionalMeta,P as getDevToolsHook,G as getWarnMessage,me as handleMissing,v as initI18nDevTools,Te as isMessageFunction,ie as isTranslateFallbackWarn,ue as isTranslateMissingWarn,Ce as number,I as parse,Oe as parseDateTimeArgs,Re as parseNumberArgs,Le as parseTranslateArgs,re as registerLocaleFallbacker,te as registerMessageCompiler,ne as registerMessageResolver,O as resolveValue,F as resolveWithKeyValue,oe as setAdditionalMeta,U as setDevToolsHook,be as translate,W as translateDevTools,fe as updateFallbackLocale};
|
|
6
|
+
const e=/\{([0-9a-zA-Z]+)\}/g;const t=e=>JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029").replace(/\u0027/g,"\\u0027"),n=e=>"number"==typeof e&&isFinite(e),r=e=>"[object RegExp]"===g(e),a=e=>p(e)&&0===Object.keys(e).length;function o(e,t){"undefined"!=typeof console&&(console.warn("[intlify] "+e),t&&console.warn(t.stack))}const l=Object.assign;function s(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const c=Array.isArray,i=e=>"function"==typeof e,u=e=>"string"==typeof e,m=e=>"boolean"==typeof e,f=e=>null!==e&&"object"==typeof e,_=Object.prototype.toString,g=e=>_.call(e),p=e=>"[object Object]"===g(e),d={EXPECTED_TOKEN:1,INVALID_TOKEN_IN_PLACEHOLDER:2,UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER:3,UNKNOWN_ESCAPE_SEQUENCE:4,INVALID_UNICODE_ESCAPE_SEQUENCE:5,UNBALANCED_CLOSING_BRACE:6,UNTERMINATED_CLOSING_BRACE:7,EMPTY_PLACEHOLDER:8,NOT_ALLOW_NEST_PLACEHOLDER:9,INVALID_LINKED_FORMAT:10,MUST_HAVE_MESSAGES_IN_PLURAL:11,UNEXPECTED_EMPTY_LINKED_MODIFIER:12,UNEXPECTED_EMPTY_LINKED_KEY:13,UNEXPECTED_LEXICAL_ANALYSIS:14,__EXTEND_POINT__:15};function E(e,t,n={}){const{domain:r,messages:a,args:o}=n,l=new SyntaxError(String(e));return l.code=e,t&&(l.location=t),l.domain=r,l}const N=[];N[0]={w:[0],i:[3,0],"[":[4],o:[7]},N[1]={w:[1],".":[2],"[":[4],o:[7]},N[2]={w:[2],i:[3,0],0:[3,0]},N[3]={i:[3,0],0:[3,0],w:[1,1],".":[2,1],"[":[4,1],o:[7,1]},N[4]={"'":[5,0],'"':[6,0],"[":[4,2],"]":[1,3],o:8,l:[4,0]},N[5]={"'":[4,0],o:8,l:[5,0]},N[6]={'"':[4,0],o:8,l:[6,0]};const A=/^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;function T(e){if(null==e)return"o";switch(e.charCodeAt(0)){case 91:case 93:case 46:case 34:case 39:return e;case 95:case 36:case 45:return"i";case 9:case 10:case 13:case 160:case 65279:case 8232:case 8233:return"w"}return"i"}function b(e){const t=e.trim();return("0"!==e.charAt(0)||!isNaN(parseInt(e)))&&(n=t,A.test(n)?function(e){const t=e.charCodeAt(0);return t!==e.charCodeAt(e.length-1)||34!==t&&39!==t?e:e.slice(1,-1)}(t):"*"+t);var n}function h(e){const t=[];let n,r,a,o,l,s,c,i=-1,u=0,m=0;const f=[];function _(){const t=e[i+1];if(5===u&&"'"===t||6===u&&'"'===t)return i++,a="\\"+t,f[0](),!0}for(f[0]=()=>{void 0===r?r=a:r+=a},f[1]=()=>{void 0!==r&&(t.push(r),r=void 0)},f[2]=()=>{f[0](),m++},f[3]=()=>{if(m>0)m--,u=4,f[0]();else{if(m=0,void 0===r)return!1;if(r=b(r),!1===r)return!1;f[1]()}};null!==u;)if(i++,n=e[i],"\\"!==n||!_()){if(o=T(n),c=N[u],l=c[o]||c.l||8,8===l)return;if(u=l[0],void 0!==l[1]&&(s=f[l[1]],s&&(a=n,!1===s())))return;if(7===u)return t}}const k=new Map;function y(e,t){return f(e)?e[t]:null}function I(e,t){if(!f(e))return null;let n=k.get(t);if(n||(n=h(t),n&&k.set(t,n)),!n)return null;const r=n.length;let a=e,o=0;for(;o<r;){const e=a[n[o]];if(void 0===e)return null;a=e,o++}return a}const L=e=>e,C=e=>"",D="text",F=e=>0===e.length?"":e.join(""),O=e=>null==e?"":c(e)||p(e)&&e.toString===_?JSON.stringify(e,null,2):String(e);function R(e,t){return e=Math.abs(e),2===t?e?e>1?1:0:1:e?Math.min(e,2):0}function M(e={}){const t=e.locale,r=function(e){const t=n(e.pluralIndex)?e.pluralIndex:-1;return e.named&&(n(e.named.count)||n(e.named.n))?n(e.named.count)?e.named.count:n(e.named.n)?e.named.n:t:t}(e),a=f(e.pluralRules)&&u(t)&&i(e.pluralRules[t])?e.pluralRules[t]:R,o=f(e.pluralRules)&&u(t)&&i(e.pluralRules[t])?R:void 0,l=e.list||[],s=e.named||{};n(e.pluralIndex)&&function(e,t){t.count||(t.count=e),t.n||(t.n=e)}(r,s);function m(t){const n=i(e.messages)?e.messages(t):!!f(e.messages)&&e.messages[t];return n||(e.parent?e.parent.message(t):C)}const _=p(e.processor)&&i(e.processor.normalize)?e.processor.normalize:F,g=p(e.processor)&&i(e.processor.interpolate)?e.processor.interpolate:O,d={list:e=>l[e],named:e=>s[e],plural:e=>e[a(r,e.length,o)],linked:(t,...n)=>{const[r,a]=n;let o="text",l="";1===n.length?f(r)?(l=r.modifier||l,o=r.type||o):u(r)&&(l=r||l):2===n.length&&(u(r)&&(l=r||l),u(a)&&(o=a||o));let s=m(t)(d);return"vnode"===o&&c(s)&&l&&(s=s[0]),l?(i=l,e.modifiers?e.modifiers[i]:L)(s,o):s;var i},message:m,type:p(e.processor)&&u(e.processor.type)?e.processor.type:"text",interpolate:g,normalize:_};return d}const w="i18n:init";let S=null;function W(e){S=e}function v(){return S}function U(e,t,n){S&&S.emit(w,{timestamp:Date.now(),i18n:e,version:t,meta:n})}const P=x("function:translate");function x(e){return t=>S&&S.emit(e,t)}const $={NOT_FOUND_KEY:1,FALLBACK_TO_TRANSLATE:2,CANNOT_FORMAT_NUMBER:3,FALLBACK_TO_NUMBER_FORMAT:4,CANNOT_FORMAT_DATE:5,FALLBACK_TO_DATE_FORMAT:6,__EXTEND_POINT__:7},K={[$.NOT_FOUND_KEY]:"Not found '{key}' key in '{locale}' locale messages.",[$.FALLBACK_TO_TRANSLATE]:"Fall back to translate '{key}' key with '{target}' locale.",[$.CANNOT_FORMAT_NUMBER]:"Cannot format a number value due to not supported Intl.NumberFormat.",[$.FALLBACK_TO_NUMBER_FORMAT]:"Fall back to number format '{key}' key with '{target}' locale.",[$.CANNOT_FORMAT_DATE]:"Cannot format a date value due to not supported Intl.DateTimeFormat.",[$.FALLBACK_TO_DATE_FORMAT]:"Fall back to datetime format '{key}' key with '{target}' locale."};function V(t,...n){return function(t,...n){return 1===n.length&&f(n[0])&&(n=n[0]),n&&n.hasOwnProperty||(n={}),t.replace(e,((e,t)=>n.hasOwnProperty(t)?n[t]:""))}(K[t],...n)}function j(e,t,n){return[...new Set([n,...c(t)?t:f(t)?Object.keys(t):u(t)?[t]:[n]])]}function G(e,t,n){const r=u(n)?n:J,a=e;a.__localeChainCache||(a.__localeChainCache=new Map);let o=a.__localeChainCache.get(r);if(!o){o=[];let e=[n];for(;c(e);)e=B(o,e,t);const l=c(t)||!p(t)?t:t.default?t.default:null;e=u(l)?[l]:l,c(e)&&B(o,e,!1),a.__localeChainCache.set(r,o)}return o}function B(e,t,n){let r=!0;for(let a=0;a<t.length&&m(r);a++){const o=t[a];u(o)&&(r=H(e,t[a],n))}return r}function H(e,t,n){let r;const a=t.split("-");do{r=X(e,a.join("-"),n),a.splice(-1,1)}while(a.length&&!0===r);return r}function X(e,t,n){let r=!1;if(!e.includes(t)&&(r=!0,t)){r="!"!==t[t.length-1];const a=t.replace(/!/g,"");e.push(a),(c(n)||p(n))&&n[a]&&(r=n[a])}return r}const Y="9.2.0-beta.40",z=-1,J="en-US",Z="",Q=e=>`${e.charAt(0).toLocaleUpperCase()}${e.substr(1)}`;let q,ee,te;function ne(e){q=e}function re(e){ee=e}function ae(e){te=e}let oe=null;const le=e=>{oe=e},se=()=>oe;let ce=null;const ie=e=>{ce=e},ue=()=>ce;let me=0;function fe(e={}){const t=u(e.version)?e.version:"9.2.0-beta.40",n=u(e.locale)?e.locale:J,a=c(e.fallbackLocale)||p(e.fallbackLocale)||u(e.fallbackLocale)||!1===e.fallbackLocale?e.fallbackLocale:n,s=p(e.messages)?e.messages:{[n]:{}},_=p(e.datetimeFormats)?e.datetimeFormats:{[n]:{}},g=p(e.numberFormats)?e.numberFormats:{[n]:{}},d=l({},e.modifiers||{},{upper:(e,t)=>"text"===t&&u(e)?e.toUpperCase():"vnode"===t&&f(e)&&"__v_isVNode"in e?e.children.toUpperCase():e,lower:(e,t)=>"text"===t&&u(e)?e.toLowerCase():"vnode"===t&&f(e)&&"__v_isVNode"in e?e.children.toLowerCase():e,capitalize:(e,t)=>"text"===t&&u(e)?Q(e):"vnode"===t&&f(e)&&"__v_isVNode"in e?Q(e.children):e}),E=e.pluralRules||{},N=i(e.missing)?e.missing:null,A=!m(e.missingWarn)&&!r(e.missingWarn)||e.missingWarn,T=!m(e.fallbackWarn)&&!r(e.fallbackWarn)||e.fallbackWarn,b=!!e.fallbackFormat,h=!!e.unresolving,k=i(e.postTranslation)?e.postTranslation:null,I=p(e.processor)?e.processor:null,L=!m(e.warnHtmlMessage)||e.warnHtmlMessage,C=!!e.escapeParameter,D=i(e.messageCompiler)?e.messageCompiler:q,F=i(e.messageResolver)?e.messageResolver:ee||y,O=i(e.localeFallbacker)?e.localeFallbacker:te||j,R=f(e.fallbackContext)?e.fallbackContext:void 0,M=i(e.onWarn)?e.onWarn:o,w=e,S=f(w.__datetimeFormatters)?w.__datetimeFormatters:new Map,W=f(w.__numberFormatters)?w.__numberFormatters:new Map,v=f(w.__meta)?w.__meta:{};me++;const U={version:t,cid:me,locale:n,fallbackLocale:a,messages:s,modifiers:d,pluralRules:E,missing:N,missingWarn:A,fallbackWarn:T,fallbackFormat:b,unresolving:h,postTranslation:k,processor:I,warnHtmlMessage:L,escapeParameter:C,messageCompiler:D,messageResolver:F,localeFallbacker:O,fallbackContext:R,onWarn:M,__meta:v};return U.datetimeFormats=_,U.numberFormats=g,U.__datetimeFormatters=S,U.__numberFormatters=W,U}function _e(e,t){return e instanceof RegExp?e.test(t):e}function ge(e,t){return e instanceof RegExp?e.test(t):e}function pe(e,t,n,r,a){const{missing:o,onWarn:l}=e;if(null!==o){const r=o(e,n,t,a);return u(r)?r:t}return t}function de(e,t,n){e.__localeChainCache=new Map,e.localeFallbacker(e,n,t)}function Ee(){}function Ne(e,t={}){return()=>e}let Ae=d.__EXTEND_POINT__;const Te=()=>++Ae,be={INVALID_ARGUMENT:Ae,INVALID_DATE_ARGUMENT:Te(),INVALID_ISO_DATE_ARGUMENT:Te(),__EXTEND_POINT__:Te()};function he(e){return E(e,null,void 0)}const ke=()=>"",ye=e=>i(e);function Ie(e,...t){const{fallbackFormat:r,postTranslation:a,unresolving:o,messageCompiler:l,fallbackLocale:i,messages:_}=e,[g,p]=De(...t),d=m(p.missingWarn)?p.missingWarn:e.missingWarn,E=m(p.fallbackWarn)?p.fallbackWarn:e.fallbackWarn,N=m(p.escapeParameter)?p.escapeParameter:e.escapeParameter,A=!!p.resolvedMessage,T=u(p.default)||m(p.default)?m(p.default)?l?g:()=>g:p.default:r?l?g:()=>g:"",b=r||""!==T,h=u(p.locale)?p.locale:e.locale;N&&function(e){c(e.list)?e.list=e.list.map((e=>u(e)?s(e):e)):f(e.named)&&Object.keys(e.named).forEach((t=>{u(e.named[t])&&(e.named[t]=s(e.named[t]))}))}(p);let[k,y,I]=A?[g,h,_[h]||{}]:Le(e,g,h,i,E,d),L=k,C=g;if(A||u(L)||ye(L)||b&&(L=T,C=L),!(A||(u(L)||ye(L))&&u(y)))return o?-1:g;let D=!1;const F=ye(L)?L:Ce(e,g,y,L,C,(()=>{D=!0}));if(D)return L;const O=function(e,t,r,a){const{modifiers:o,pluralRules:l,messageResolver:s,fallbackLocale:c,fallbackWarn:i,missingWarn:m,fallbackContext:f}=e,_=n=>{let a=s(r,n);if(null==a&&f){const[,,e]=Le(f,n,t,c,i,m);a=s(e,n)}if(u(a)){let r=!1;const o=Ce(e,n,t,a,n,(()=>{r=!0}));return r?ke:o}return ye(a)?a:ke},g={locale:t,modifiers:o,pluralRules:l,messages:_};e.processor&&(g.processor=e.processor);a.list&&(g.list=a.list);a.named&&(g.named=a.named);n(a.plural)&&(g.pluralIndex=a.plural);return g}(e,y,I,p),R=function(e,t,n){return t(n)}(0,F,M(O));return a?a(R,g):R}function Le(e,t,n,r,a,o){const{messages:l,onWarn:s,messageResolver:c,localeFallbacker:m}=e,f=m(e,r,n);let _,g={},p=null;for(let n=0;n<f.length&&(_=f[n],g=l[_]||{},null===(p=c(g,t))&&(p=g[t]),!u(p)&&!i(p));n++){const n=pe(e,t,_,0,"translate");n!==t&&(p=n)}return[p,_,g]}function Ce(e,n,r,a,o,l){const{messageCompiler:s,warnHtmlMessage:c}=e;if(ye(a)){const e=a;return e.locale=e.locale||r,e.key=e.key||n,e}if(null==s){const e=()=>a;return e.locale=r,e.key=n,e}const i=s(a,function(e,n,r,a,o,l){return{warnHtmlMessage:o,onError:e=>{throw l&&l(e),e},onCacheKey:e=>((e,n,r)=>t({l:e,k:n,s:r}))(n,r,e)}}(0,r,o,0,c,l));return i.locale=r,i.key=n,i.source=a,i}function De(...e){const[t,r,o]=e,s={};if(!u(t)&&!n(t)&&!ye(t))throw Error(be.INVALID_ARGUMENT);const i=n(t)?String(t):(ye(t),t);return n(r)?s.plural=r:u(r)?s.default=r:p(r)&&!a(r)?s.named=r:c(r)&&(s.list=r),n(o)?s.plural=o:u(o)?s.default=o:p(o)&&l(s,o),[i,s]}function Fe(e,...t){const{datetimeFormats:n,unresolving:r,fallbackLocale:o,onWarn:s,localeFallbacker:c}=e,{__datetimeFormatters:i}=e,[f,_,g,d]=Re(...t);m(g.missingWarn)?g.missingWarn:e.missingWarn;m(g.fallbackWarn)?g.fallbackWarn:e.fallbackWarn;const E=!!g.part,N=u(g.locale)?g.locale:e.locale,A=c(e,o,N);if(!u(f)||""===f)return new Intl.DateTimeFormat(N,d).format(_);let T,b={},h=null;for(let t=0;t<A.length&&(T=A[t],b=n[T]||{},h=b[f],!p(h));t++)pe(e,f,T,0,"datetime format");if(!p(h)||!u(T))return r?-1:f;let k=`${T}__${f}`;a(d)||(k=`${k}__${JSON.stringify(d)}`);let y=i.get(k);return y||(y=new Intl.DateTimeFormat(T,l({},h,d)),i.set(k,y)),E?y.formatToParts(_):y.format(_)}const Oe=["localeMatcher","weekday","era","year","month","day","hour","minute","second","timeZoneName","formatMatcher","hour12","timeZone","dateStyle","timeStyle","calendar","dayPeriod","numberingSystem","hourCycle","fractionalSecondDigits"];function Re(...e){const[t,r,a,o]=e,l={};let s,c={};if(u(t)){const e=t.match(/(\d{4}-\d{2}-\d{2})(T|\s)?(.*)/);if(!e)throw Error(be.INVALID_ISO_DATE_ARGUMENT);const n=e[3]?e[3].trim().startsWith("T")?`${e[1].trim()}${e[3].trim()}`:`${e[1].trim()}T${e[3].trim()}`:e[1].trim();s=new Date(n);try{s.toISOString()}catch(e){throw Error(be.INVALID_ISO_DATE_ARGUMENT)}}else if("[object Date]"===g(t)){if(isNaN(t.getTime()))throw Error(be.INVALID_DATE_ARGUMENT);s=t}else{if(!n(t))throw Error(be.INVALID_ARGUMENT);s=t}return u(r)?l.key=r:p(r)&&Object.keys(r).forEach((e=>{Oe.includes(e)?c[e]=r[e]:l[e]=r[e]})),u(a)?l.locale=a:p(a)&&(c=a),p(o)&&(c=o),[l.key||"",s,l,c]}function Me(e,t,n){const r=e;for(const e in n){const n=`${t}__${e}`;r.__datetimeFormatters.has(n)&&r.__datetimeFormatters.delete(n)}}function we(e,...t){const{numberFormats:n,unresolving:r,fallbackLocale:o,onWarn:s,localeFallbacker:c}=e,{__numberFormatters:i}=e,[f,_,g,d]=We(...t);m(g.missingWarn)?g.missingWarn:e.missingWarn;m(g.fallbackWarn)?g.fallbackWarn:e.fallbackWarn;const E=!!g.part,N=u(g.locale)?g.locale:e.locale,A=c(e,o,N);if(!u(f)||""===f)return new Intl.NumberFormat(N,d).format(_);let T,b={},h=null;for(let t=0;t<A.length&&(T=A[t],b=n[T]||{},h=b[f],!p(h));t++)pe(e,f,T,0,"number format");if(!p(h)||!u(T))return r?-1:f;let k=`${T}__${f}`;a(d)||(k=`${k}__${JSON.stringify(d)}`);let y=i.get(k);return y||(y=new Intl.NumberFormat(T,l({},h,d)),i.set(k,y)),E?y.formatToParts(_):y.format(_)}const Se=["localeMatcher","style","currency","currencyDisplay","currencySign","useGrouping","minimumIntegerDigits","minimumFractionDigits","maximumFractionDigits","minimumSignificantDigits","maximumSignificantDigits","compactDisplay","notation","signDisplay","unit","unitDisplay","roundingMode","roundingPriority","roundingIncrement","trailingZeroDisplay"];function We(...e){const[t,r,a,o]=e,l={};let s={};if(!n(t))throw Error(be.INVALID_ARGUMENT);const c=t;return u(r)?l.key=r:p(r)&&Object.keys(r).forEach((e=>{Se.includes(e)?s[e]=r[e]:l[e]=r[e]})),u(a)?l.locale=a:p(a)&&(s=a),p(o)&&(s=o),[l.key||"",c,l,s]}function ve(e,t,n){const r=e;for(const e in n){const n=`${t}__${e}`;r.__numberFormatters.has(n)&&r.__numberFormatters.delete(n)}}re(I),ae(G);export{d as CompileErrorCodes,be as CoreErrorCodes,$ as CoreWarnCodes,Oe as DATETIME_FORMAT_OPTIONS_KEYS,J as DEFAULT_LOCALE,D as DEFAULT_MESSAGE_DATA_TYPE,Z as MISSING_RESOLVE_VALUE,z as NOT_REOSLVED,Se as NUMBER_FORMAT_OPTIONS_KEYS,Y as VERSION,Ee as clearCompileCache,Me as clearDateTimeFormat,ve as clearNumberFormat,Ne as compileToFunction,E as createCompileError,fe as createCoreContext,he as createCoreError,M as createMessageContext,Fe as datetime,G as fallbackWithLocaleChain,j as fallbackWithSimple,se as getAdditionalMeta,v as getDevToolsHook,ue as getFallbackContext,V as getWarnMessage,pe as handleMissing,U as initI18nDevTools,ye as isMessageFunction,_e as isTranslateFallbackWarn,ge as isTranslateMissingWarn,we as number,h as parse,Re as parseDateTimeArgs,We as parseNumberArgs,De as parseTranslateArgs,ae as registerLocaleFallbacker,ne as registerMessageCompiler,re as registerMessageResolver,I as resolveValue,y as resolveWithKeyValue,le as setAdditionalMeta,W as setDevToolsHook,ie as setFallbackContext,Ie as translate,P as translateDevTools,de as updateFallbackLocale};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* core v9.2.0-beta.
|
|
3
|
-
* (c)
|
|
2
|
+
* core v9.2.0-beta.40
|
|
3
|
+
* (c) 2022 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
import { registerMessageResolver, resolveValue, registerLocaleFallbacker, fallbackWithLocaleChain } from '@intlify/core-base';
|