@intlify/core-base 9.3.0-beta.26 → 9.3.0-beta.27
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 +43 -59
- package/dist/core-base.d.ts +170 -21
- package/dist/core-base.esm-browser.js +93 -77
- package/dist/core-base.esm-browser.prod.js +2 -2
- package/dist/core-base.global.js +83 -77
- package/dist/core-base.global.prod.js +2 -2
- package/dist/core-base.mjs +57 -39
- package/dist/core-base.prod.cjs +37 -59
- package/package.json +5 -5
package/dist/core-base.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* core-base v9.3.0-beta.
|
|
2
|
+
* core-base v9.3.0-beta.27
|
|
3
3
|
* (c) 2023 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -398,7 +398,8 @@ function createMessageContext(options = {}) {
|
|
|
398
398
|
["message" /* HelperNameMap.MESSAGE */]: message,
|
|
399
399
|
["type" /* HelperNameMap.TYPE */]: type,
|
|
400
400
|
["interpolate" /* HelperNameMap.INTERPOLATE */]: interpolate,
|
|
401
|
-
["normalize" /* HelperNameMap.NORMALIZE */]: normalize
|
|
401
|
+
["normalize" /* HelperNameMap.NORMALIZE */]: normalize,
|
|
402
|
+
["values" /* HelperNameMap.VALUES */]: shared.assign({}, _list, _named)
|
|
402
403
|
};
|
|
403
404
|
return ctx;
|
|
404
405
|
}
|
|
@@ -432,7 +433,8 @@ const CoreWarnCodes = {
|
|
|
432
433
|
FALLBACK_TO_NUMBER_FORMAT: 4,
|
|
433
434
|
CANNOT_FORMAT_DATE: 5,
|
|
434
435
|
FALLBACK_TO_DATE_FORMAT: 6,
|
|
435
|
-
|
|
436
|
+
EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER: 7,
|
|
437
|
+
__EXTEND_POINT__: 8
|
|
436
438
|
};
|
|
437
439
|
/** @internal */
|
|
438
440
|
const warnMessages = {
|
|
@@ -441,7 +443,8 @@ const warnMessages = {
|
|
|
441
443
|
[CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
|
|
442
444
|
[CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
|
|
443
445
|
[CoreWarnCodes.CANNOT_FORMAT_DATE]: `Cannot format a date value due to not supported Intl.DateTimeFormat.`,
|
|
444
|
-
[CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale
|
|
446
|
+
[CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`,
|
|
447
|
+
[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.`
|
|
445
448
|
};
|
|
446
449
|
function getWarnMessage(code, ...args) {
|
|
447
450
|
return shared.format(warnMessages[code], ...args);
|
|
@@ -568,7 +571,7 @@ function appendItemToChain(chain, target, blocks) {
|
|
|
568
571
|
* Intlify core-base version
|
|
569
572
|
* @internal
|
|
570
573
|
*/
|
|
571
|
-
const VERSION = '9.3.0-beta.
|
|
574
|
+
const VERSION = '9.3.0-beta.27';
|
|
572
575
|
const NOT_REOSLVED = -1;
|
|
573
576
|
const DEFAULT_LOCALE = 'en-US';
|
|
574
577
|
const MISSING_RESOLVE_VALUE = '';
|
|
@@ -629,10 +632,10 @@ function registerLocaleFallbacker(fallbacker) {
|
|
|
629
632
|
}
|
|
630
633
|
// Additional Meta for Intlify DevTools
|
|
631
634
|
let _additionalMeta = null;
|
|
632
|
-
const setAdditionalMeta =
|
|
635
|
+
const setAdditionalMeta = /* #__PURE__*/ (meta) => {
|
|
633
636
|
_additionalMeta = meta;
|
|
634
637
|
};
|
|
635
|
-
const getAdditionalMeta =
|
|
638
|
+
const getAdditionalMeta = /* #__PURE__*/ () => _additionalMeta;
|
|
636
639
|
let _fallbackContext = null;
|
|
637
640
|
const setFallbackContext = (context) => {
|
|
638
641
|
_fallbackContext = context;
|
|
@@ -642,6 +645,7 @@ const getFallbackContext = () => _fallbackContext;
|
|
|
642
645
|
let _cid = 0;
|
|
643
646
|
function createCoreContext(options = {}) {
|
|
644
647
|
// setup options
|
|
648
|
+
const onWarn = shared.isFunction(options.onWarn) ? options.onWarn : shared.warn;
|
|
645
649
|
const version = shared.isString(options.version) ? options.version : VERSION;
|
|
646
650
|
const locale = shared.isString(options.locale) ? options.locale : DEFAULT_LOCALE;
|
|
647
651
|
const fallbackLocale = shared.isArray(options.fallbackLocale) ||
|
|
@@ -683,6 +687,9 @@ function createCoreContext(options = {}) {
|
|
|
683
687
|
const messageCompiler = shared.isFunction(options.messageCompiler)
|
|
684
688
|
? options.messageCompiler
|
|
685
689
|
: _compiler;
|
|
690
|
+
if (shared.isFunction(options.messageCompiler)) {
|
|
691
|
+
shared.warnOnce(getWarnMessage(CoreWarnCodes.EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER));
|
|
692
|
+
}
|
|
686
693
|
const messageResolver = shared.isFunction(options.messageResolver)
|
|
687
694
|
? options.messageResolver
|
|
688
695
|
: _resolver || resolveWithKeyValue;
|
|
@@ -692,7 +699,6 @@ function createCoreContext(options = {}) {
|
|
|
692
699
|
const fallbackContext = shared.isObject(options.fallbackContext)
|
|
693
700
|
? options.fallbackContext
|
|
694
701
|
: undefined;
|
|
695
|
-
const onWarn = shared.isFunction(options.onWarn) ? options.onWarn : shared.warn;
|
|
696
702
|
// setup internal options
|
|
697
703
|
const internalOptions = options;
|
|
698
704
|
const __datetimeFormatters = shared.isObject(internalOptions.__datetimeFormatters)
|
|
@@ -850,14 +856,14 @@ function formatMessagePart(ctx, node) {
|
|
|
850
856
|
}
|
|
851
857
|
}
|
|
852
858
|
|
|
853
|
-
|
|
854
|
-
const inc = ()
|
|
859
|
+
const code = messageCompiler.CompileErrorCodes.__EXTEND_POINT__;
|
|
860
|
+
const inc = shared.incrementer(code);
|
|
855
861
|
const CoreErrorCodes = {
|
|
856
862
|
INVALID_ARGUMENT: code,
|
|
857
863
|
INVALID_DATE_ARGUMENT: inc(),
|
|
858
864
|
INVALID_ISO_DATE_ARGUMENT: inc(),
|
|
859
|
-
|
|
860
|
-
__EXTEND_POINT__: inc() //
|
|
865
|
+
NOT_SUPPORT_NON_STRING_MESSAGE: inc(),
|
|
866
|
+
__EXTEND_POINT__: inc() // 22
|
|
861
867
|
};
|
|
862
868
|
function createCoreError(code) {
|
|
863
869
|
return messageCompiler.createCompileError(code, null, { messages: errorMessages } );
|
|
@@ -868,7 +874,7 @@ const errorMessages = {
|
|
|
868
874
|
[CoreErrorCodes.INVALID_DATE_ARGUMENT]: 'The date provided is an invalid Date object.' +
|
|
869
875
|
'Make sure your Date represents a valid date.',
|
|
870
876
|
[CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: 'The argument provided is not a valid ISO date string',
|
|
871
|
-
[CoreErrorCodes.
|
|
877
|
+
[CoreErrorCodes.NOT_SUPPORT_NON_STRING_MESSAGE]: 'Not support non-string message'
|
|
872
878
|
};
|
|
873
879
|
|
|
874
880
|
const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
|
|
@@ -882,6 +888,9 @@ let compileCache = Object.create(null);
|
|
|
882
888
|
function clearCompileCache() {
|
|
883
889
|
compileCache = Object.create(null);
|
|
884
890
|
}
|
|
891
|
+
const isMessageAST = (val) => shared.isObject(val) &&
|
|
892
|
+
(val.t === 0 || val.type === 0) &&
|
|
893
|
+
('b' in val || 'body' in val);
|
|
885
894
|
function baseCompile(message, options = {}) {
|
|
886
895
|
// error detecting on compile
|
|
887
896
|
let detectError = false;
|
|
@@ -893,27 +902,25 @@ function baseCompile(message, options = {}) {
|
|
|
893
902
|
// compile with mesasge-compiler
|
|
894
903
|
return { ...messageCompiler.baseCompile(message, options), detectError };
|
|
895
904
|
}
|
|
896
|
-
function compileToFunction(message,
|
|
905
|
+
function compileToFunction(message, context) {
|
|
897
906
|
if (!shared.isString(message)) {
|
|
898
|
-
throw createCoreError(CoreErrorCodes.
|
|
907
|
+
throw createCoreError(CoreErrorCodes.NOT_SUPPORT_NON_STRING_MESSAGE);
|
|
899
908
|
}
|
|
900
909
|
{
|
|
901
910
|
// check HTML message
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
905
|
-
options.warnHtmlMessage
|
|
911
|
+
const warnHtmlMessage = shared.isBoolean(context.warnHtmlMessage)
|
|
912
|
+
? context.warnHtmlMessage
|
|
906
913
|
: true;
|
|
907
914
|
checkHtmlMessage(message, warnHtmlMessage);
|
|
908
915
|
// check caches
|
|
909
|
-
const onCacheKey =
|
|
916
|
+
const onCacheKey = context.onCacheKey || defaultOnCacheKey;
|
|
910
917
|
const cacheKey = onCacheKey(message);
|
|
911
918
|
const cached = compileCache[cacheKey];
|
|
912
919
|
if (cached) {
|
|
913
920
|
return cached;
|
|
914
921
|
}
|
|
915
922
|
// compile
|
|
916
|
-
const { code, detectError } = baseCompile(message,
|
|
923
|
+
const { code, detectError } = baseCompile(message, context);
|
|
917
924
|
// evaluate function
|
|
918
925
|
const msg = new Function(`return ${code}`)();
|
|
919
926
|
// if occurred compile error, don't cache
|
|
@@ -922,36 +929,12 @@ function compileToFunction(message, options = {}) {
|
|
|
922
929
|
: msg;
|
|
923
930
|
}
|
|
924
931
|
}
|
|
925
|
-
function compile(message,
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
931
|
-
options.warnHtmlMessage
|
|
932
|
-
: true;
|
|
933
|
-
checkHtmlMessage(message, warnHtmlMessage);
|
|
934
|
-
// check caches
|
|
935
|
-
const onCacheKey = options.onCacheKey || defaultOnCacheKey;
|
|
936
|
-
const cacheKey = onCacheKey(message);
|
|
937
|
-
const cached = compileCache[cacheKey];
|
|
938
|
-
if (cached) {
|
|
939
|
-
return cached;
|
|
932
|
+
function compile(message, context) {
|
|
933
|
+
{
|
|
934
|
+
if (!isMessageAST(message)) {
|
|
935
|
+
shared.warn(`the message that is resolve with key '${context.key}') is not supported for jit compilation`);
|
|
936
|
+
return (() => message);
|
|
940
937
|
}
|
|
941
|
-
// compile with JIT mode
|
|
942
|
-
const { ast, detectError } = baseCompile(message, {
|
|
943
|
-
...options,
|
|
944
|
-
location: true,
|
|
945
|
-
jit: true
|
|
946
|
-
});
|
|
947
|
-
// compose message function from AST
|
|
948
|
-
const msg = format(ast);
|
|
949
|
-
// if occurred compile error, don't cache
|
|
950
|
-
return !detectError
|
|
951
|
-
? (compileCache[cacheKey] = msg)
|
|
952
|
-
: msg;
|
|
953
|
-
}
|
|
954
|
-
else {
|
|
955
938
|
// AST case (passed from bundler)
|
|
956
939
|
const cacheKey = message.cacheKey;
|
|
957
940
|
if (cacheKey) {
|
|
@@ -971,7 +954,6 @@ function compile(message, options = {}) {
|
|
|
971
954
|
|
|
972
955
|
const NOOP_MESSAGE_FUNCTION = () => '';
|
|
973
956
|
const isMessageFunction = (val) => shared.isFunction(val);
|
|
974
|
-
const isMessageAST = (val) => shared.isObject(val) && val.type === 0 && 'body' in val;
|
|
975
957
|
// implementation of `translate` function
|
|
976
958
|
function translate(context, ...args) {
|
|
977
959
|
const { fallbackFormat, postTranslation, unresolving, messageCompiler, fallbackLocale, messages } = context;
|
|
@@ -1042,12 +1024,12 @@ function translate(context, ...args) {
|
|
|
1042
1024
|
}
|
|
1043
1025
|
// setup compile error detecting
|
|
1044
1026
|
let occurred = false;
|
|
1045
|
-
const
|
|
1027
|
+
const onError = () => {
|
|
1046
1028
|
occurred = true;
|
|
1047
1029
|
};
|
|
1048
1030
|
// compile message format
|
|
1049
1031
|
const msg = !isMessageFunction(format)
|
|
1050
|
-
? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey,
|
|
1032
|
+
? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError)
|
|
1051
1033
|
: format;
|
|
1052
1034
|
// if occurred compile error, return the message format
|
|
1053
1035
|
if (occurred) {
|
|
@@ -1175,7 +1157,7 @@ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn
|
|
|
1175
1157
|
}
|
|
1176
1158
|
return [format, targetLocale, message];
|
|
1177
1159
|
}
|
|
1178
|
-
function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey,
|
|
1160
|
+
function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError) {
|
|
1179
1161
|
const { messageCompiler, warnHtmlMessage } = context;
|
|
1180
1162
|
if (isMessageFunction(format)) {
|
|
1181
1163
|
const msg = format;
|
|
@@ -1199,7 +1181,7 @@ function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey,
|
|
|
1199
1181
|
endTag = 'intlify-message-compilation-end';
|
|
1200
1182
|
shared.mark && shared.mark(startTag);
|
|
1201
1183
|
}
|
|
1202
|
-
const msg = messageCompiler(format,
|
|
1184
|
+
const msg = messageCompiler(format, getCompileContext(context, targetLocale, cacheBaseKey, format, warnHtmlMessage, onError));
|
|
1203
1185
|
// for vue-devtools timeline event
|
|
1204
1186
|
if (shared.inBrowser) {
|
|
1205
1187
|
const end = window.performance.now();
|
|
@@ -1292,11 +1274,13 @@ function parseTranslateArgs(...args) {
|
|
|
1292
1274
|
}
|
|
1293
1275
|
return [key, options];
|
|
1294
1276
|
}
|
|
1295
|
-
function
|
|
1277
|
+
function getCompileContext(context, locale, key, source, warnHtmlMessage, onError) {
|
|
1296
1278
|
return {
|
|
1279
|
+
locale,
|
|
1280
|
+
key,
|
|
1297
1281
|
warnHtmlMessage,
|
|
1298
1282
|
onError: (err) => {
|
|
1299
|
-
|
|
1283
|
+
onError && onError(err);
|
|
1300
1284
|
{
|
|
1301
1285
|
const _source = getSourceForCodeFrame(source);
|
|
1302
1286
|
const message = `Message compilation error: ${err.message}`;
|
|
@@ -1338,10 +1322,10 @@ function getMessageContextOptions(context, locale, message, options) {
|
|
|
1338
1322
|
}
|
|
1339
1323
|
if (shared.isString(val) || isMessageAST(val)) {
|
|
1340
1324
|
let occurred = false;
|
|
1341
|
-
const
|
|
1325
|
+
const onError = () => {
|
|
1342
1326
|
occurred = true;
|
|
1343
1327
|
};
|
|
1344
|
-
const msg = compileMessageFormat(context, key, locale, val, key,
|
|
1328
|
+
const msg = compileMessageFormat(context, key, locale, val, key, onError);
|
|
1345
1329
|
return !occurred
|
|
1346
1330
|
? msg
|
|
1347
1331
|
: NOOP_MESSAGE_FUNCTION;
|
package/dist/core-base.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BaseError } from '@intlify/shared';
|
|
1
2
|
import { CompileError } from '@intlify/message-compiler';
|
|
2
3
|
import { CompileErrorCodes } from '@intlify/message-compiler';
|
|
3
4
|
import type { CompileOptions } from '@intlify/message-compiler';
|
|
@@ -18,15 +19,11 @@ export declare function clearCompileCache(): void;
|
|
|
18
19
|
|
|
19
20
|
/* Excluded from this release type: clearNumberFormat */
|
|
20
21
|
|
|
21
|
-
export declare function compile<Message = string, MessageSource
|
|
22
|
+
export declare function compile<Message = string, MessageSource = string | ResourceNode>(message: MessageSource, context: MessageCompilerContext): MessageFunction<Message>;
|
|
22
23
|
export { CompileError }
|
|
23
24
|
export { CompileErrorCodes }
|
|
24
25
|
|
|
25
|
-
export declare function compileToFunction<Message = string, MessageSource
|
|
26
|
-
|
|
27
|
-
declare type CoreBaseCompileOptions = CompileOptions & {
|
|
28
|
-
warnHtmlMessage?: boolean;
|
|
29
|
-
};
|
|
26
|
+
export declare function compileToFunction<Message = string, MessageSource = string | ResourceNode>(message: MessageSource, context: MessageCompilerContext): MessageFunction<Message>;
|
|
30
27
|
|
|
31
28
|
export declare interface CoreCommonContext<Message = string, Locales = 'en-US'> {
|
|
32
29
|
cid: number;
|
|
@@ -52,15 +49,14 @@ export declare interface CoreDateTimeContext<DateTimeFormats = {}> {
|
|
|
52
49
|
};
|
|
53
50
|
}
|
|
54
51
|
|
|
55
|
-
export declare interface CoreError extends
|
|
56
|
-
code: CoreErrorCodes;
|
|
52
|
+
export declare interface CoreError extends BaseError {
|
|
57
53
|
}
|
|
58
54
|
|
|
59
55
|
export declare const CoreErrorCodes: {
|
|
60
|
-
readonly INVALID_ARGUMENT:
|
|
56
|
+
readonly INVALID_ARGUMENT: 17;
|
|
61
57
|
readonly INVALID_DATE_ARGUMENT: number;
|
|
62
58
|
readonly INVALID_ISO_DATE_ARGUMENT: number;
|
|
63
|
-
readonly
|
|
59
|
+
readonly NOT_SUPPORT_NON_STRING_MESSAGE: number;
|
|
64
60
|
readonly __EXTEND_POINT__: number;
|
|
65
61
|
};
|
|
66
62
|
|
|
@@ -167,7 +163,8 @@ export declare const CoreWarnCodes: {
|
|
|
167
163
|
readonly FALLBACK_TO_NUMBER_FORMAT: 4;
|
|
168
164
|
readonly CANNOT_FORMAT_DATE: 5;
|
|
169
165
|
readonly FALLBACK_TO_DATE_FORMAT: 6;
|
|
170
|
-
readonly
|
|
166
|
+
readonly EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER: 7;
|
|
167
|
+
readonly __EXTEND_POINT__: 8;
|
|
171
168
|
};
|
|
172
169
|
|
|
173
170
|
export declare type CoreWarnCodes = (typeof CoreWarnCodes)[keyof typeof CoreWarnCodes];
|
|
@@ -399,7 +396,13 @@ export declare type LinkedModifiers<T = string> = {
|
|
|
399
396
|
export declare type LinkedModify<T = string> = (value: T, type: string) => MessageType<T>;
|
|
400
397
|
|
|
401
398
|
export declare interface LinkedOptions {
|
|
399
|
+
/**
|
|
400
|
+
* The message type of linked message
|
|
401
|
+
*/
|
|
402
402
|
type?: string;
|
|
403
|
+
/**
|
|
404
|
+
* The modifier of linked message
|
|
405
|
+
*/
|
|
403
406
|
modifier?: string;
|
|
404
407
|
}
|
|
405
408
|
|
|
@@ -462,19 +465,160 @@ export declare type LocaleRecord<T extends any[], R> = {
|
|
|
462
465
|
[K in T[number]]: R;
|
|
463
466
|
};
|
|
464
467
|
|
|
465
|
-
|
|
468
|
+
/**
|
|
469
|
+
* The message compiler
|
|
470
|
+
*
|
|
471
|
+
* @param message - A resolved message that ususally will be passed the string. if you can transform to it with bundler, will be passed the AST.
|
|
472
|
+
* @param context - A message context {@link MessageCompilerContext}
|
|
473
|
+
*
|
|
474
|
+
* @returns A {@link MessageFunction}
|
|
475
|
+
*
|
|
476
|
+
* @VueI18nGeneral
|
|
477
|
+
*/
|
|
478
|
+
export declare type MessageCompiler<Message = string, MessageSource = string | ResourceNode> = (message: MessageSource, context: MessageCompilerContext) => MessageFunction<Message>;
|
|
466
479
|
|
|
480
|
+
/**
|
|
481
|
+
* The context that will pass the message compiler.
|
|
482
|
+
*
|
|
483
|
+
* @VueI18nGeneral
|
|
484
|
+
*/
|
|
485
|
+
export declare type MessageCompilerContext = Pick<CompileOptions, 'onError' | 'onCacheKey'> & {
|
|
486
|
+
/**
|
|
487
|
+
* Whether to allow the use locale messages of HTML formatting.
|
|
488
|
+
*/
|
|
489
|
+
warnHtmlMessage?: boolean;
|
|
490
|
+
/**
|
|
491
|
+
* The resolved locale message key
|
|
492
|
+
*/
|
|
493
|
+
key: string;
|
|
494
|
+
/**
|
|
495
|
+
* The locale
|
|
496
|
+
*/
|
|
497
|
+
locale: Locale;
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* The message context.
|
|
502
|
+
*
|
|
503
|
+
* @VueI18nGeneral
|
|
504
|
+
*/
|
|
467
505
|
export declare interface MessageContext<T = string> {
|
|
506
|
+
/**
|
|
507
|
+
* Resolve message value from list.
|
|
508
|
+
*
|
|
509
|
+
* @param index - An index of message values.
|
|
510
|
+
*
|
|
511
|
+
* @returns A resolved message value.
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* ```js
|
|
515
|
+
* const messages = {
|
|
516
|
+
* en: {
|
|
517
|
+
* greeting: ({ list }) => `hello, ${list(0)}!`
|
|
518
|
+
* }
|
|
519
|
+
* }
|
|
520
|
+
* ```
|
|
521
|
+
*/
|
|
468
522
|
list(index: number): unknown;
|
|
523
|
+
/**
|
|
524
|
+
* Resolve message value from named.
|
|
525
|
+
*
|
|
526
|
+
* @param key - A key of message value.
|
|
527
|
+
*
|
|
528
|
+
* @returns A resolved message value.
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```js
|
|
532
|
+
* const messages = {
|
|
533
|
+
* en: {
|
|
534
|
+
* greeting: ({ named }) => `hello, ${named('name')}!`
|
|
535
|
+
* }
|
|
536
|
+
* }
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
469
539
|
named(key: string): unknown;
|
|
540
|
+
/**
|
|
541
|
+
* Resolve message with plural index.
|
|
542
|
+
*
|
|
543
|
+
* @remarks
|
|
544
|
+
* That's resolved with plural index with translation function.
|
|
545
|
+
*
|
|
546
|
+
* @param messages - the messages, that is resolved with plural index with translation function.
|
|
547
|
+
*
|
|
548
|
+
* @returns A resolved message.
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
551
|
+
* ```js
|
|
552
|
+
* const messages = {
|
|
553
|
+
* en: {
|
|
554
|
+
* car: ({ plural }) => plural(['car', 'cars']),
|
|
555
|
+
* apple: ({ plural, named }) =>
|
|
556
|
+
* plural([
|
|
557
|
+
* 'no apples',
|
|
558
|
+
* 'one apple',
|
|
559
|
+
* `${named('count')} apples`
|
|
560
|
+
* ])
|
|
561
|
+
* }
|
|
562
|
+
* }
|
|
563
|
+
* ```
|
|
564
|
+
*/
|
|
470
565
|
plural(messages: T[]): T;
|
|
566
|
+
/**
|
|
567
|
+
* Resolve linked message.
|
|
568
|
+
*
|
|
569
|
+
* @param key - A message key
|
|
570
|
+
* @param modifier - A modifier
|
|
571
|
+
*
|
|
572
|
+
* @returns A resolve message.
|
|
573
|
+
*/
|
|
471
574
|
linked(key: Path, modifier?: string): MessageType<T>;
|
|
575
|
+
/**
|
|
576
|
+
* Overloaded `linked`
|
|
577
|
+
*
|
|
578
|
+
* @param key - A message key
|
|
579
|
+
* @param modifier - A modifier
|
|
580
|
+
* @param type - A message type
|
|
581
|
+
*
|
|
582
|
+
* @returns A resolve message.
|
|
583
|
+
*/
|
|
472
584
|
linked(key: Path, modifier?: string, type?: string): MessageType<T>;
|
|
585
|
+
/**
|
|
586
|
+
* Overloaded `linked`
|
|
587
|
+
*
|
|
588
|
+
* @param key - A message key
|
|
589
|
+
* @param optoins - An {@link LinkedOptions | linked options}
|
|
590
|
+
*
|
|
591
|
+
* @returns A resolve message.
|
|
592
|
+
*/
|
|
473
593
|
linked(key: Path, optoins?: LinkedOptions): MessageType<T>;
|
|
474
|
-
|
|
594
|
+
/* Excluded from this release type: message */
|
|
595
|
+
/**
|
|
596
|
+
* The message type to be handled by the message function.
|
|
597
|
+
*
|
|
598
|
+
* @remarks
|
|
599
|
+
* Usually `text`, you need to return **string** in message function.
|
|
600
|
+
*/
|
|
475
601
|
type: string;
|
|
476
|
-
|
|
477
|
-
|
|
602
|
+
/* Excluded from this release type: interpolate */
|
|
603
|
+
/* Excluded from this release type: normalize */
|
|
604
|
+
/**
|
|
605
|
+
* The message values.
|
|
606
|
+
*
|
|
607
|
+
* @remarks
|
|
608
|
+
* The message values are the argument values passed from translation fucntion, such as `$t`, `t`, or `translate`.
|
|
609
|
+
*
|
|
610
|
+
* @example
|
|
611
|
+
* vue-i18n `$t` (or `t`) case:
|
|
612
|
+
* ```html
|
|
613
|
+
* <p>{{ $t('greeting', { name: 'DIO' }) }}</p> <!-- `{ name: 'DIO' }` is message vlaues -->
|
|
614
|
+
* ```
|
|
615
|
+
*
|
|
616
|
+
* `@intlify/core` (`@intlify/core-base`) `translate` case:
|
|
617
|
+
* ```js
|
|
618
|
+
* translate(context, 'foo.bar', ['dio']) // `['dio']` is message values
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
values: Record<string, unknown>;
|
|
478
622
|
}
|
|
479
623
|
|
|
480
624
|
export declare interface MessageContextOptions<T = string, N = {}> {
|
|
@@ -489,17 +633,22 @@ export declare interface MessageContextOptions<T = string, N = {}> {
|
|
|
489
633
|
processor?: MessageProcessor<T>;
|
|
490
634
|
}
|
|
491
635
|
|
|
636
|
+
/**
|
|
637
|
+
* The Message Function.
|
|
638
|
+
*
|
|
639
|
+
* @param ctx - A {@link MessageContext}
|
|
640
|
+
*
|
|
641
|
+
* @return A resolved format message, that is string type basically.
|
|
642
|
+
*
|
|
643
|
+
* @VueI18nGeneral
|
|
644
|
+
*/
|
|
492
645
|
export declare type MessageFunction<T = string> = MessageFunctionCallable | MessageFunctionInternal<T>;
|
|
493
646
|
|
|
494
647
|
export declare type MessageFunctionCallable = <T = string>(ctx: MessageContext<T>) => MessageFunctionReturn<T>;
|
|
495
648
|
|
|
496
|
-
|
|
497
|
-
(ctx: MessageContext<T>): MessageFunctionReturn<T>;
|
|
498
|
-
key?: string;
|
|
499
|
-
locale?: string;
|
|
500
|
-
source?: string;
|
|
501
|
-
};
|
|
649
|
+
/* Excluded from this release type: MessageFunctionInternal */
|
|
502
650
|
|
|
651
|
+
/** @VueI18nGeneral */
|
|
503
652
|
export declare type MessageFunctionReturn<T = string> = T extends string ? MessageType<T> : MessageType<T>[];
|
|
504
653
|
|
|
505
654
|
export declare type MessageFunctions<T = string> = Record<string, MessageFunction<T>>;
|