@intlify/core-base 9.2.0-beta.9 → 9.2.0
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-base.cjs.js +166 -30
- package/dist/core-base.cjs.prod.js +166 -30
- package/dist/core-base.d.ts +27 -9
- package/dist/core-base.esm-browser.js +201 -48
- package/dist/core-base.esm-browser.prod.js +3 -3
- package/dist/core-base.esm-bundler.js +165 -32
- package/dist/core-base.global.js +205 -48
- package/dist/core-base.global.prod.js +3 -3
- package/index.mjs +1 -0
- package/package.json +19 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* core-base v9.2.0
|
|
3
|
-
* (c)
|
|
2
|
+
* core-base v9.2.0
|
|
3
|
+
* (c) 2022 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
@@ -328,14 +328,15 @@ function createMessageContext(options = {}) {
|
|
|
328
328
|
shared.isFunction(options.pluralRules[locale])
|
|
329
329
|
? pluralDefault
|
|
330
330
|
: undefined;
|
|
331
|
-
const plural = (messages) =>
|
|
331
|
+
const plural = (messages) => {
|
|
332
|
+
return messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
|
|
333
|
+
};
|
|
332
334
|
const _list = options.list || [];
|
|
333
335
|
const list = (index) => _list[index];
|
|
334
336
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
335
337
|
const _named = options.named || {};
|
|
336
338
|
shared.isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
|
|
337
339
|
const named = (key) => _named[key];
|
|
338
|
-
// TODO: need to design resolve message function?
|
|
339
340
|
function message(key) {
|
|
340
341
|
// prettier-ignore
|
|
341
342
|
const msg = shared.isFunction(options.messages)
|
|
@@ -362,15 +363,39 @@ function createMessageContext(options = {}) {
|
|
|
362
363
|
const type = shared.isPlainObject(options.processor) && shared.isString(options.processor.type)
|
|
363
364
|
? options.processor.type
|
|
364
365
|
: DEFAULT_MESSAGE_DATA_TYPE;
|
|
366
|
+
const linked = (key, ...args) => {
|
|
367
|
+
const [arg1, arg2] = args;
|
|
368
|
+
let type = 'text';
|
|
369
|
+
let modifier = '';
|
|
370
|
+
if (args.length === 1) {
|
|
371
|
+
if (shared.isObject(arg1)) {
|
|
372
|
+
modifier = arg1.modifier || modifier;
|
|
373
|
+
type = arg1.type || type;
|
|
374
|
+
}
|
|
375
|
+
else if (shared.isString(arg1)) {
|
|
376
|
+
modifier = arg1 || modifier;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
else if (args.length === 2) {
|
|
380
|
+
if (shared.isString(arg1)) {
|
|
381
|
+
modifier = arg1 || modifier;
|
|
382
|
+
}
|
|
383
|
+
if (shared.isString(arg2)) {
|
|
384
|
+
type = arg2 || type;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
let msg = message(key)(ctx);
|
|
388
|
+
// The message in vnode resolved with linked are returned as an array by processor.nomalize
|
|
389
|
+
if (type === 'vnode' && shared.isArray(msg) && modifier) {
|
|
390
|
+
msg = msg[0];
|
|
391
|
+
}
|
|
392
|
+
return modifier ? _modifier(modifier)(msg, type) : msg;
|
|
393
|
+
};
|
|
365
394
|
const ctx = {
|
|
366
395
|
["list" /* LIST */]: list,
|
|
367
396
|
["named" /* NAMED */]: named,
|
|
368
397
|
["plural" /* PLURAL */]: plural,
|
|
369
|
-
["linked" /* LINKED */]:
|
|
370
|
-
// TODO: should check `key`
|
|
371
|
-
const msg = message(key)(ctx);
|
|
372
|
-
return shared.isString(modifier) ? _modifier(modifier)(msg) : msg;
|
|
373
|
-
},
|
|
398
|
+
["linked" /* LINKED */]: linked,
|
|
374
399
|
["message" /* MESSAGE */]: message,
|
|
375
400
|
["type" /* TYPE */]: type,
|
|
376
401
|
["interpolate" /* INTERPOLATE */]: interpolate,
|
|
@@ -544,18 +569,37 @@ function appendItemToChain(chain, target, blocks) {
|
|
|
544
569
|
* Intlify core-base version
|
|
545
570
|
* @internal
|
|
546
571
|
*/
|
|
547
|
-
const VERSION = '9.2.0
|
|
572
|
+
const VERSION = '9.2.0';
|
|
548
573
|
const NOT_REOSLVED = -1;
|
|
549
574
|
const DEFAULT_LOCALE = 'en-US';
|
|
550
575
|
const MISSING_RESOLVE_VALUE = '';
|
|
576
|
+
const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
|
|
551
577
|
function getDefaultLinkedModifiers() {
|
|
552
578
|
return {
|
|
553
|
-
upper: (val) =>
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
579
|
+
upper: (val, type) => {
|
|
580
|
+
// prettier-ignore
|
|
581
|
+
return type === 'text' && shared.isString(val)
|
|
582
|
+
? val.toUpperCase()
|
|
583
|
+
: type === 'vnode' && shared.isObject(val) && '__v_isVNode' in val
|
|
584
|
+
? val.children.toUpperCase()
|
|
585
|
+
: val;
|
|
586
|
+
},
|
|
587
|
+
lower: (val, type) => {
|
|
588
|
+
// prettier-ignore
|
|
589
|
+
return type === 'text' && shared.isString(val)
|
|
590
|
+
? val.toLowerCase()
|
|
591
|
+
: type === 'vnode' && shared.isObject(val) && '__v_isVNode' in val
|
|
592
|
+
? val.children.toLowerCase()
|
|
593
|
+
: val;
|
|
594
|
+
},
|
|
595
|
+
capitalize: (val, type) => {
|
|
596
|
+
// prettier-ignore
|
|
597
|
+
return (type === 'text' && shared.isString(val)
|
|
598
|
+
? capitalize(val)
|
|
599
|
+
: type === 'vnode' && shared.isObject(val) && '__v_isVNode' in val
|
|
600
|
+
? capitalize(val.children)
|
|
601
|
+
: val);
|
|
602
|
+
}
|
|
559
603
|
};
|
|
560
604
|
}
|
|
561
605
|
let _compiler;
|
|
@@ -590,6 +634,11 @@ const setAdditionalMeta = (meta) => {
|
|
|
590
634
|
_additionalMeta = meta;
|
|
591
635
|
};
|
|
592
636
|
const getAdditionalMeta = () => _additionalMeta;
|
|
637
|
+
let _fallbackContext = null;
|
|
638
|
+
const setFallbackContext = (context) => {
|
|
639
|
+
_fallbackContext = context;
|
|
640
|
+
};
|
|
641
|
+
const getFallbackContext = () => _fallbackContext;
|
|
593
642
|
// ID for CoreContext
|
|
594
643
|
let _cid = 0;
|
|
595
644
|
function createCoreContext(options = {}) {
|
|
@@ -641,6 +690,9 @@ function createCoreContext(options = {}) {
|
|
|
641
690
|
const localeFallbacker = shared.isFunction(options.localeFallbacker)
|
|
642
691
|
? options.localeFallbacker
|
|
643
692
|
: _fallbacker || fallbackWithSimple;
|
|
693
|
+
const fallbackContext = shared.isObject(options.fallbackContext)
|
|
694
|
+
? options.fallbackContext
|
|
695
|
+
: undefined;
|
|
644
696
|
const onWarn = shared.isFunction(options.onWarn) ? options.onWarn : shared.warn;
|
|
645
697
|
// setup internal options
|
|
646
698
|
const internalOptions = options;
|
|
@@ -674,6 +726,7 @@ function createCoreContext(options = {}) {
|
|
|
674
726
|
messageCompiler,
|
|
675
727
|
messageResolver,
|
|
676
728
|
localeFallbacker,
|
|
729
|
+
fallbackContext,
|
|
677
730
|
onWarn,
|
|
678
731
|
__meta
|
|
679
732
|
};
|
|
@@ -743,7 +796,7 @@ function compileToFunction(source, options = {}) {
|
|
|
743
796
|
}
|
|
744
797
|
|
|
745
798
|
let code = messageCompiler.CompileErrorCodes.__EXTEND_POINT__;
|
|
746
|
-
const inc = () => code
|
|
799
|
+
const inc = () => ++code;
|
|
747
800
|
const CoreErrorCodes = {
|
|
748
801
|
INVALID_ARGUMENT: code,
|
|
749
802
|
INVALID_DATE_ARGUMENT: inc(),
|
|
@@ -765,7 +818,7 @@ const NOOP_MESSAGE_FUNCTION = () => '';
|
|
|
765
818
|
const isMessageFunction = (val) => shared.isFunction(val);
|
|
766
819
|
// implementation of `translate` function
|
|
767
820
|
function translate(context, ...args) {
|
|
768
|
-
const { fallbackFormat, postTranslation, unresolving, fallbackLocale, messages } = context;
|
|
821
|
+
const { fallbackFormat, postTranslation, unresolving, messageCompiler, fallbackLocale, messages } = context;
|
|
769
822
|
const [key, options] = parseTranslateArgs(...args);
|
|
770
823
|
const missingWarn = shared.isBoolean(options.missingWarn)
|
|
771
824
|
? options.missingWarn
|
|
@@ -781,9 +834,9 @@ function translate(context, ...args) {
|
|
|
781
834
|
const defaultMsgOrKey = shared.isString(options.default) || shared.isBoolean(options.default) // default by function option
|
|
782
835
|
? !shared.isBoolean(options.default)
|
|
783
836
|
? options.default
|
|
784
|
-
: key
|
|
837
|
+
: (!messageCompiler ? () => key : key)
|
|
785
838
|
: fallbackFormat // default by `fallbackFormat` option
|
|
786
|
-
? key
|
|
839
|
+
? (!messageCompiler ? () => key : key)
|
|
787
840
|
: '';
|
|
788
841
|
const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== '';
|
|
789
842
|
const locale = shared.isString(options.locale) ? options.locale : context.locale;
|
|
@@ -791,13 +844,19 @@ function translate(context, ...args) {
|
|
|
791
844
|
escapeParameter && escapeParams(options);
|
|
792
845
|
// resolve message format
|
|
793
846
|
// eslint-disable-next-line prefer-const
|
|
794
|
-
let [
|
|
847
|
+
let [formatScope, targetLocale, message] = !resolvedMessage
|
|
795
848
|
? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn)
|
|
796
849
|
: [
|
|
797
850
|
key,
|
|
798
851
|
locale,
|
|
799
852
|
messages[locale] || {}
|
|
800
853
|
];
|
|
854
|
+
// NOTE:
|
|
855
|
+
// Fix to work around `ssrTransfrom` bug in Vite.
|
|
856
|
+
// https://github.com/vitejs/vite/issues/4306
|
|
857
|
+
// To get around this, use temporary variables.
|
|
858
|
+
// https://github.com/nuxt/framework/issues/1461#issuecomment-954606243
|
|
859
|
+
let format = formatScope;
|
|
801
860
|
// if you use default message, set it as message format!
|
|
802
861
|
let cacheBaseKey = key;
|
|
803
862
|
if (!resolvedMessage &&
|
|
@@ -831,7 +890,9 @@ function translate(context, ...args) {
|
|
|
831
890
|
const msgContext = createMessageContext(ctxOptions);
|
|
832
891
|
const messaged = evaluateMessage(context, msg, msgContext);
|
|
833
892
|
// if use post translation option, proceed it with handler
|
|
834
|
-
const ret = postTranslation
|
|
893
|
+
const ret = postTranslation
|
|
894
|
+
? postTranslation(messaged, key)
|
|
895
|
+
: messaged;
|
|
835
896
|
return ret;
|
|
836
897
|
}
|
|
837
898
|
function escapeParams(options) {
|
|
@@ -879,6 +940,12 @@ function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey,
|
|
|
879
940
|
msg.key = msg.key || key;
|
|
880
941
|
return msg;
|
|
881
942
|
}
|
|
943
|
+
if (messageCompiler == null) {
|
|
944
|
+
const msg = (() => format);
|
|
945
|
+
msg.locale = targetLocale;
|
|
946
|
+
msg.key = key;
|
|
947
|
+
return msg;
|
|
948
|
+
}
|
|
882
949
|
const msg = messageCompiler(format, getCompileOptions(context, targetLocale, cacheBaseKey, format, warnHtmlMessage, errorDetector));
|
|
883
950
|
msg.locale = targetLocale;
|
|
884
951
|
msg.key = key;
|
|
@@ -938,9 +1005,14 @@ function getCompileOptions(context, locale, key, source, warnHtmlMessage, errorD
|
|
|
938
1005
|
};
|
|
939
1006
|
}
|
|
940
1007
|
function getMessageContextOptions(context, locale, message, options) {
|
|
941
|
-
const { modifiers, pluralRules, messageResolver: resolveValue } = context;
|
|
1008
|
+
const { modifiers, pluralRules, messageResolver: resolveValue, fallbackLocale, fallbackWarn, missingWarn, fallbackContext } = context;
|
|
942
1009
|
const resolveMessage = (key) => {
|
|
943
|
-
|
|
1010
|
+
let val = resolveValue(message, key);
|
|
1011
|
+
// fallback to root context
|
|
1012
|
+
if (val == null && fallbackContext) {
|
|
1013
|
+
const [, , message] = resolveMessageFormat(fallbackContext, key, locale, fallbackLocale, fallbackWarn, missingWarn);
|
|
1014
|
+
val = resolveValue(message, key);
|
|
1015
|
+
}
|
|
944
1016
|
if (shared.isString(val)) {
|
|
945
1017
|
let occurred = false;
|
|
946
1018
|
const errorDetector = () => {
|
|
@@ -996,7 +1068,7 @@ function datetime(context, ...args) {
|
|
|
996
1068
|
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
997
1069
|
fallbackLocale, locale);
|
|
998
1070
|
if (!shared.isString(key) || key === '') {
|
|
999
|
-
return new Intl.DateTimeFormat(locale).format(value);
|
|
1071
|
+
return new Intl.DateTimeFormat(locale, overrides).format(value);
|
|
1000
1072
|
}
|
|
1001
1073
|
// resolve format
|
|
1002
1074
|
let datetimeFormat = {};
|
|
@@ -1028,9 +1100,32 @@ function datetime(context, ...args) {
|
|
|
1028
1100
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1029
1101
|
}
|
|
1030
1102
|
/** @internal */
|
|
1103
|
+
const DATETIME_FORMAT_OPTIONS_KEYS = [
|
|
1104
|
+
'localeMatcher',
|
|
1105
|
+
'weekday',
|
|
1106
|
+
'era',
|
|
1107
|
+
'year',
|
|
1108
|
+
'month',
|
|
1109
|
+
'day',
|
|
1110
|
+
'hour',
|
|
1111
|
+
'minute',
|
|
1112
|
+
'second',
|
|
1113
|
+
'timeZoneName',
|
|
1114
|
+
'formatMatcher',
|
|
1115
|
+
'hour12',
|
|
1116
|
+
'timeZone',
|
|
1117
|
+
'dateStyle',
|
|
1118
|
+
'timeStyle',
|
|
1119
|
+
'calendar',
|
|
1120
|
+
'dayPeriod',
|
|
1121
|
+
'numberingSystem',
|
|
1122
|
+
'hourCycle',
|
|
1123
|
+
'fractionalSecondDigits'
|
|
1124
|
+
];
|
|
1125
|
+
/** @internal */
|
|
1031
1126
|
function parseDateTimeArgs(...args) {
|
|
1032
1127
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1033
|
-
|
|
1128
|
+
const options = {};
|
|
1034
1129
|
let overrides = {};
|
|
1035
1130
|
let value;
|
|
1036
1131
|
if (shared.isString(arg1)) {
|
|
@@ -1072,7 +1167,14 @@ function parseDateTimeArgs(...args) {
|
|
|
1072
1167
|
options.key = arg2;
|
|
1073
1168
|
}
|
|
1074
1169
|
else if (shared.isPlainObject(arg2)) {
|
|
1075
|
-
|
|
1170
|
+
Object.keys(arg2).forEach(key => {
|
|
1171
|
+
if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1172
|
+
overrides[key] = arg2[key];
|
|
1173
|
+
}
|
|
1174
|
+
else {
|
|
1175
|
+
options[key] = arg2[key];
|
|
1176
|
+
}
|
|
1177
|
+
});
|
|
1076
1178
|
}
|
|
1077
1179
|
if (shared.isString(arg3)) {
|
|
1078
1180
|
options.locale = arg3;
|
|
@@ -1113,7 +1215,7 @@ function number(context, ...args) {
|
|
|
1113
1215
|
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1114
1216
|
fallbackLocale, locale);
|
|
1115
1217
|
if (!shared.isString(key) || key === '') {
|
|
1116
|
-
return new Intl.NumberFormat(locale).format(value);
|
|
1218
|
+
return new Intl.NumberFormat(locale, overrides).format(value);
|
|
1117
1219
|
}
|
|
1118
1220
|
// resolve format
|
|
1119
1221
|
let numberFormat = {};
|
|
@@ -1145,9 +1247,32 @@ function number(context, ...args) {
|
|
|
1145
1247
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1146
1248
|
}
|
|
1147
1249
|
/** @internal */
|
|
1250
|
+
const NUMBER_FORMAT_OPTIONS_KEYS = [
|
|
1251
|
+
'localeMatcher',
|
|
1252
|
+
'style',
|
|
1253
|
+
'currency',
|
|
1254
|
+
'currencyDisplay',
|
|
1255
|
+
'currencySign',
|
|
1256
|
+
'useGrouping',
|
|
1257
|
+
'minimumIntegerDigits',
|
|
1258
|
+
'minimumFractionDigits',
|
|
1259
|
+
'maximumFractionDigits',
|
|
1260
|
+
'minimumSignificantDigits',
|
|
1261
|
+
'maximumSignificantDigits',
|
|
1262
|
+
'compactDisplay',
|
|
1263
|
+
'notation',
|
|
1264
|
+
'signDisplay',
|
|
1265
|
+
'unit',
|
|
1266
|
+
'unitDisplay',
|
|
1267
|
+
'roundingMode',
|
|
1268
|
+
'roundingPriority',
|
|
1269
|
+
'roundingIncrement',
|
|
1270
|
+
'trailingZeroDisplay'
|
|
1271
|
+
];
|
|
1272
|
+
/** @internal */
|
|
1148
1273
|
function parseNumberArgs(...args) {
|
|
1149
1274
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1150
|
-
|
|
1275
|
+
const options = {};
|
|
1151
1276
|
let overrides = {};
|
|
1152
1277
|
if (!shared.isNumber(arg1)) {
|
|
1153
1278
|
throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
@@ -1157,7 +1282,14 @@ function parseNumberArgs(...args) {
|
|
|
1157
1282
|
options.key = arg2;
|
|
1158
1283
|
}
|
|
1159
1284
|
else if (shared.isPlainObject(arg2)) {
|
|
1160
|
-
|
|
1285
|
+
Object.keys(arg2).forEach(key => {
|
|
1286
|
+
if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1287
|
+
overrides[key] = arg2[key];
|
|
1288
|
+
}
|
|
1289
|
+
else {
|
|
1290
|
+
options[key] = arg2[key];
|
|
1291
|
+
}
|
|
1292
|
+
});
|
|
1161
1293
|
}
|
|
1162
1294
|
if (shared.isString(arg3)) {
|
|
1163
1295
|
options.locale = arg3;
|
|
@@ -1186,10 +1318,12 @@ exports.CompileErrorCodes = messageCompiler.CompileErrorCodes;
|
|
|
1186
1318
|
exports.createCompileError = messageCompiler.createCompileError;
|
|
1187
1319
|
exports.CoreErrorCodes = CoreErrorCodes;
|
|
1188
1320
|
exports.CoreWarnCodes = CoreWarnCodes;
|
|
1321
|
+
exports.DATETIME_FORMAT_OPTIONS_KEYS = DATETIME_FORMAT_OPTIONS_KEYS;
|
|
1189
1322
|
exports.DEFAULT_LOCALE = DEFAULT_LOCALE;
|
|
1190
1323
|
exports.DEFAULT_MESSAGE_DATA_TYPE = DEFAULT_MESSAGE_DATA_TYPE;
|
|
1191
1324
|
exports.MISSING_RESOLVE_VALUE = MISSING_RESOLVE_VALUE;
|
|
1192
1325
|
exports.NOT_REOSLVED = NOT_REOSLVED;
|
|
1326
|
+
exports.NUMBER_FORMAT_OPTIONS_KEYS = NUMBER_FORMAT_OPTIONS_KEYS;
|
|
1193
1327
|
exports.VERSION = VERSION;
|
|
1194
1328
|
exports.clearCompileCache = clearCompileCache;
|
|
1195
1329
|
exports.clearDateTimeFormat = clearDateTimeFormat;
|
|
@@ -1203,6 +1337,7 @@ exports.fallbackWithLocaleChain = fallbackWithLocaleChain;
|
|
|
1203
1337
|
exports.fallbackWithSimple = fallbackWithSimple;
|
|
1204
1338
|
exports.getAdditionalMeta = getAdditionalMeta;
|
|
1205
1339
|
exports.getDevToolsHook = getDevToolsHook;
|
|
1340
|
+
exports.getFallbackContext = getFallbackContext;
|
|
1206
1341
|
exports.getWarnMessage = getWarnMessage;
|
|
1207
1342
|
exports.handleMissing = handleMissing;
|
|
1208
1343
|
exports.initI18nDevTools = initI18nDevTools;
|
|
@@ -1221,6 +1356,7 @@ exports.resolveValue = resolveValue;
|
|
|
1221
1356
|
exports.resolveWithKeyValue = resolveWithKeyValue;
|
|
1222
1357
|
exports.setAdditionalMeta = setAdditionalMeta;
|
|
1223
1358
|
exports.setDevToolsHook = setDevToolsHook;
|
|
1359
|
+
exports.setFallbackContext = setFallbackContext;
|
|
1224
1360
|
exports.translate = translate;
|
|
1225
1361
|
exports.translateDevTools = translateDevTools;
|
|
1226
1362
|
exports.updateFallbackLocale = updateFallbackLocale;
|
package/dist/core-base.d.ts
CHANGED
|
@@ -35,7 +35,9 @@ export declare interface CoreCommonContext<Message = string, Locales = 'en-US'>
|
|
|
35
35
|
onWarn(msg: string, err?: Error): void;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export declare type CoreContext<Message = string, Messages = {}, DateTimeFormats = {}, NumberFormats = {}, ResourceLocales = PickupLocales<NonNullable<Messages>> | PickupLocales<NonNullable<DateTimeFormats>> | PickupLocales<NonNullable<NumberFormats>>, Locales = [ResourceLocales] extends [never] ? Locale : ResourceLocales> = CoreCommonContext<Message, Locales> & CoreTranslationContext<NonNullable<Messages>, Message> & CoreDateTimeContext<NonNullable<DateTimeFormats>> & CoreNumberContext<NonNullable<NumberFormats
|
|
38
|
+
export declare type CoreContext<Message = string, Messages = {}, DateTimeFormats = {}, NumberFormats = {}, ResourceLocales = PickupLocales<NonNullable<Messages>> | PickupLocales<NonNullable<DateTimeFormats>> | PickupLocales<NonNullable<NumberFormats>>, Locales = [ResourceLocales] extends [never] ? Locale : ResourceLocales> = CoreCommonContext<Message, Locales> & CoreTranslationContext<NonNullable<Messages>, Message> & CoreDateTimeContext<NonNullable<DateTimeFormats>> & CoreNumberContext<NonNullable<NumberFormats>> & {
|
|
39
|
+
fallbackContext?: CoreContext<Message, Messages, DateTimeFormats, NumberFormats, ResourceLocales, Locales>;
|
|
40
|
+
};
|
|
39
41
|
|
|
40
42
|
export declare interface CoreDateTimeContext<DateTimeFormats = {}> {
|
|
41
43
|
datetimeFormats: {
|
|
@@ -132,6 +134,7 @@ export declare interface CoreOptions<Message = string, Schema extends {
|
|
|
132
134
|
messageCompiler?: MessageCompiler<Message>;
|
|
133
135
|
messageResolver?: MessageResolver;
|
|
134
136
|
localeFallbacker?: LocaleFallbacker;
|
|
137
|
+
fallbackContext?: CoreContext<Message, MessagesLocales, DateTimeFormatsLocales, NumberFormatsLocales>;
|
|
135
138
|
onWarn?: (msg: string, err?: Error) => void;
|
|
136
139
|
}
|
|
137
140
|
|
|
@@ -196,6 +199,8 @@ export declare function datetime<Context extends CoreContext<Message, {}, Contex
|
|
|
196
199
|
|
|
197
200
|
export declare function datetime<Context extends CoreContext<Message, {}, Context['datetimeFormats'], {}>, Value extends number | string | Date = number, Key extends string = string, ResourceKeys extends PickupFormatKeys<Context['datetimeFormats']> = PickupFormatKeys<Context['datetimeFormats']>, Message = string>(context: Context, value: Value, keyOrOptions: Key | ResourceKeys | DateTimeOptions<Key | ResourceKeys, Context['locale']>, locale: Context['locale'], override: Intl.DateTimeFormatOptions): string | number | Intl.DateTimeFormatPart[];
|
|
198
201
|
|
|
202
|
+
/* Excluded from this release type: DATETIME_FORMAT_OPTIONS_KEYS */
|
|
203
|
+
|
|
199
204
|
export declare type DateTimeDigital = 'numeric' | '2-digit';
|
|
200
205
|
|
|
201
206
|
export declare type DateTimeFormat = {
|
|
@@ -246,9 +251,9 @@ export declare type DateTimeHumanReadable = 'long' | 'short' | 'narrow';
|
|
|
246
251
|
* datetime(context, value, { key: 'short', part: true })
|
|
247
252
|
*
|
|
248
253
|
* // orverride context.datetimeFormats[locale] options with functino options
|
|
249
|
-
* datetime(cnotext, value, 'short', {
|
|
250
|
-
* datetime(cnotext, value, 'short', 'ja-JP', {
|
|
251
|
-
* datetime(context, value, { key: 'short', part: true
|
|
254
|
+
* datetime(cnotext, value, 'short', { year: '2-digit' })
|
|
255
|
+
* datetime(cnotext, value, 'short', 'ja-JP', { year: '2-digit' })
|
|
256
|
+
* datetime(context, value, { key: 'short', part: true, year: '2-digit' })
|
|
252
257
|
*/
|
|
253
258
|
/**
|
|
254
259
|
* DateTime options
|
|
@@ -258,7 +263,7 @@ export declare type DateTimeHumanReadable = 'long' | 'short' | 'narrow';
|
|
|
258
263
|
*
|
|
259
264
|
* @VueI18nGeneral
|
|
260
265
|
*/
|
|
261
|
-
export declare interface DateTimeOptions<Key = string, Locales = Locale> {
|
|
266
|
+
export declare interface DateTimeOptions<Key = string, Locales = Locale> extends Intl.DateTimeFormatOptions {
|
|
262
267
|
/**
|
|
263
268
|
* @remarks
|
|
264
269
|
* The target format key
|
|
@@ -354,6 +359,8 @@ export declare const getAdditionalMeta: () => MetaInfo | null;
|
|
|
354
359
|
|
|
355
360
|
export declare function getDevToolsHook(): IntlifyDevToolsEmitter | null;
|
|
356
361
|
|
|
362
|
+
export declare const getFallbackContext: () => CoreContext | null;
|
|
363
|
+
|
|
357
364
|
export declare function getWarnMessage(code: CoreWarnCodes, ...args: unknown[]): string;
|
|
358
365
|
|
|
359
366
|
/* Excluded from this release type: handleMissing */
|
|
@@ -379,7 +386,12 @@ export declare type LinkedModifiers<T = string> = {
|
|
|
379
386
|
[key: string]: LinkedModify<T>;
|
|
380
387
|
};
|
|
381
388
|
|
|
382
|
-
export declare type LinkedModify<T = string> = (value: T) => MessageType<T>;
|
|
389
|
+
export declare type LinkedModify<T = string> = (value: T, type: string) => MessageType<T>;
|
|
390
|
+
|
|
391
|
+
export declare interface LinkedOptions {
|
|
392
|
+
type?: string;
|
|
393
|
+
modifier?: string;
|
|
394
|
+
}
|
|
383
395
|
|
|
384
396
|
/** @VueI18nGeneral */
|
|
385
397
|
export declare type Locale = string;
|
|
@@ -447,6 +459,8 @@ export declare interface MessageContext<T = string> {
|
|
|
447
459
|
named(key: string): unknown;
|
|
448
460
|
plural(messages: T[]): T;
|
|
449
461
|
linked(key: Path, modifier?: string): MessageType<T>;
|
|
462
|
+
linked(key: Path, modifier?: string, type?: string): MessageType<T>;
|
|
463
|
+
linked(key: Path, optoins?: LinkedOptions): MessageType<T>;
|
|
450
464
|
message(key: Path): MessageFunction<T>;
|
|
451
465
|
type: string;
|
|
452
466
|
interpolate: MessageInterpolate<T>;
|
|
@@ -519,6 +533,8 @@ export declare function number<Context extends CoreContext<Message, {}, {}, Cont
|
|
|
519
533
|
|
|
520
534
|
export declare function number<Context extends CoreContext<Message, {}, {}, Context['numberFormats']>, Value extends number = number, Key extends string = string, ResourceKeys extends PickupFormatKeys<Context['numberFormats']> = PickupFormatKeys<Context['numberFormats']>, Message = string>(context: Context, value: Value, keyOrOptions: Key | ResourceKeys | NumberOptions<Key | ResourceKeys, Context['locale']>, locale: Context['locale'], override: Intl.NumberFormatOptions): string | number | Intl.NumberFormatPart[];
|
|
521
535
|
|
|
536
|
+
/* Excluded from this release type: NUMBER_FORMAT_OPTIONS_KEYS */
|
|
537
|
+
|
|
522
538
|
export declare type NumberFormat = {
|
|
523
539
|
[key: string]: NumberFormatOptions;
|
|
524
540
|
};
|
|
@@ -567,7 +583,7 @@ export declare type NumberFormatToPartsResult = {
|
|
|
567
583
|
* // orverride context.numberFormats[locale] options with functino options
|
|
568
584
|
* number(cnotext, value, 'currency', { year: '2-digit' })
|
|
569
585
|
* number(cnotext, value, 'currency', 'ja-JP', { year: '2-digit' })
|
|
570
|
-
* number(context, value, { key: 'currenty', part: true
|
|
586
|
+
* number(context, value, { key: 'currenty', locale: 'ja-JP', part: true, year: '2-digit'})
|
|
571
587
|
*/
|
|
572
588
|
/**
|
|
573
589
|
* Number Options
|
|
@@ -577,7 +593,7 @@ export declare type NumberFormatToPartsResult = {
|
|
|
577
593
|
*
|
|
578
594
|
* @VueI18nGeneral
|
|
579
595
|
*/
|
|
580
|
-
export declare interface NumberOptions<Key = string, Locales = Locale> {
|
|
596
|
+
export declare interface NumberOptions<Key = string, Locales = Locale> extends Intl.NumberFormatOptions {
|
|
581
597
|
/**
|
|
582
598
|
* @remarks
|
|
583
599
|
* The target format key
|
|
@@ -649,7 +665,7 @@ export declare type PluralizationRules = {
|
|
|
649
665
|
};
|
|
650
666
|
|
|
651
667
|
/** @VueI18nGeneral */
|
|
652
|
-
export declare type PostTranslationHandler<Message = string> = (translated: MessageType<Message
|
|
668
|
+
export declare type PostTranslationHandler<Message = string> = (translated: MessageType<Message>, key: string) => MessageType<Message>;
|
|
653
669
|
|
|
654
670
|
/**
|
|
655
671
|
* Register the locale fallbacker
|
|
@@ -737,6 +753,8 @@ export declare const setAdditionalMeta: (meta: MetaInfo | null) => void;
|
|
|
737
753
|
|
|
738
754
|
export declare function setDevToolsHook(hook: IntlifyDevToolsEmitter | null): void;
|
|
739
755
|
|
|
756
|
+
export declare const setFallbackContext: (context: CoreContext | null) => void;
|
|
757
|
+
|
|
740
758
|
export declare interface SpecificDateTimeFormatOptions extends Intl.DateTimeFormatOptions {
|
|
741
759
|
year?: DateTimeDigital;
|
|
742
760
|
month?: DateTimeDigital | DateTimeHumanReadable;
|