/
composer.ts
2662 lines (2567 loc) · 79.5 KB
/
composer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ref, computed, getCurrentInstance, watch } from 'vue'
import {
warn,
isArray,
isFunction,
isNumber,
isString,
isRegExp,
isBoolean,
isPlainObject,
isObject,
assign,
inBrowser,
hasOwn
} from '@intlify/shared'
import {
isTranslateFallbackWarn,
isTranslateMissingWarn,
createCoreContext,
MISSING_RESOLVE_VALUE,
updateFallbackLocale,
translate,
parseTranslateArgs,
datetime,
parseDateTimeArgs,
clearDateTimeFormat,
number,
parseNumberArgs,
clearNumberFormat,
fallbackWithLocaleChain,
NOT_REOSLVED,
MessageFunction,
setAdditionalMeta,
getFallbackContext,
setFallbackContext,
DEFAULT_LOCALE,
isMessageAST,
isMessageFunction
} from '@intlify/core-base'
import { VueDevToolsTimelineEvents } from '@intlify/vue-devtools'
import { I18nWarnCodes, getWarnMessage } from './warnings'
import { I18nErrorCodes, createI18nError } from './errors'
import {
TranslateVNodeSymbol,
DatetimePartsSymbol,
NumberPartsSymbol,
EnableEmitter,
DisableEmitter,
SetPluralRulesSymbol,
InejctWithOptionSymbol,
LegacyInstanceSymbol,
__VUE_I18N_BRIDGE__
} from './symbols'
import {
deepCopy,
getLocaleMessages,
getComponentOptions,
createTextNode,
handleFlatJson
} from './utils'
import { VERSION } from './misc'
import type {
ComponentInternalInstance,
VNode,
VNodeArrayChildren,
WritableComputedRef,
ComputedRef
} from 'vue'
import type {
Path,
MessageResolver,
MessageCompiler,
LinkedModifiers,
PluralizationRules,
NamedValue,
MessageFunctions,
MessageProcessor,
MessageType,
Locale,
LocaleMessageValue,
LocaleMessage,
LocaleMessages,
CoreContext,
CoreMissingHandler,
LocaleMessageDictionary,
PostTranslationHandler,
FallbackLocale,
CoreInternalContext,
TranslateOptions,
DateTimeOptions,
NumberOptions,
DateTimeFormats as DateTimeFormatsType,
NumberFormats as NumberFormatsType,
DateTimeFormat,
NumberFormat,
MetaInfo,
PickupLocales,
PickupKeys,
PickupFormatKeys,
FallbackLocales,
SchemaParams,
LocaleParams,
ResourceValue,
ResourcePath,
ResourceNode,
PickupPaths,
PickupFormatPathKeys,
RemoveIndexSignature,
RemovedIndexResources,
IsNever,
IsEmptyObject,
CoreMissingType
} from '@intlify/core-base'
import type { VueDevToolsEmitter } from '@intlify/vue-devtools'
import { isLegacyVueI18n } from './utils'
export { DEFAULT_LOCALE } from '@intlify/core-base'
// extend VNode interface
export const DEVTOOLS_META = '__INTLIFY_META__'
/** @VueI18nComposition */
export type VueMessageType = string | ResourceNode | VNode
/**
* The type definition of Locale Message
*
* @remarks
* The typealias is used to strictly define the type of the Locale message.
*
* The type defined by this can be used in the global scope.
*
* @example
* ```ts
* // type.d.ts (`.d.ts` file at your app)
* import { DefineLocaleMessage } from 'vue-i18n'
*
* declare module 'vue-i18n' {
* export interface DefineLocaleMessage {
* title: string
* menu: {
* login: string
* }
* }
* }
* ```
*
* @VueI18nGeneral
*/
export interface DefineLocaleMessage extends LocaleMessage<VueMessageType> {} // eslint-disable-line @typescript-eslint/no-empty-interface
/**
* The type definition of datetime format
*
* @remarks
* The typealias is used to strictly define the type of the Datetime format.
*
* The type defined by this can be used in the global scope.
*
* @example
* ```ts
* // type.d.ts (`.d.ts` file at your app)
* import { DefineDateTimeFormat } from 'vue-i18n'
*
* declare module 'vue-i18n' {
* export interface DefineDateTimeFormat {
* short: {
* hour: 'numeric'
* timezone: string
* }
* }
* }
* ```
*
* @VueI18nGeneral
*/
export interface DefineDateTimeFormat extends DateTimeFormat {} // eslint-disable-line @typescript-eslint/no-empty-interface
/**
* The type definition of number format
*
* @remarks
* The typealias is used to strictly define the type of the Number format.
*
* The type defined by this can be used in the global scope.
*
* @example
* ```ts
* // type.d.ts (`.d.ts` file at your app)
* import { DefineNumberFormat } from 'vue-i18n'
*
* declare module 'vue-i18n' {
* export interface DefineNumberFormat {
* currency: {
* style: 'currency'
* currencyDisplay: 'symbol'
* currency: string
* }
* }
* }
* ```
*
* @VueI18nGeneral
*/
export interface DefineNumberFormat extends NumberFormat {} // eslint-disable-line @typescript-eslint/no-empty-interface
export type DefaultLocaleMessageSchema<
Schema = RemoveIndexSignature<{
[K in keyof DefineLocaleMessage]: DefineLocaleMessage[K]
}>
> = IsEmptyObject<Schema> extends true ? LocaleMessage<VueMessageType> : Schema
export type DefaultDateTimeFormatSchema<
Schema = RemoveIndexSignature<{
[K in keyof DefineDateTimeFormat]: DefineDateTimeFormat[K]
}>
> = IsEmptyObject<Schema> extends true ? DateTimeFormat : Schema
export type DefaultNumberFormatSchema<
Schema = RemoveIndexSignature<{
[K in keyof DefineNumberFormat]: DefineNumberFormat[K]
}>
> = IsEmptyObject<Schema> extends true ? NumberFormat : Schema
/** @VueI18nComposition */
export type MissingHandler = (
locale: Locale,
key: Path,
instance?: ComponentInternalInstance,
type?: string
) => string | void
export type PreCompileHandler<Message = VueMessageType> = () => {
messages: LocaleMessages<Message>
functions: MessageFunctions<Message>
}
export interface CustomBlock<Message = VueMessageType> {
locale: Locale
resource: LocaleMessages<Message>
}
export type CustomBlocks<Message = VueMessageType> = Array<CustomBlock<Message>>
// prettier-ignore
/**
* Composer Options
*
* @remarks
* This is options to create composer.
*
* @VueI18nComposition
*/
export interface ComposerOptions<
Schema extends {
message?: unknown
datetime?: unknown
number?: unknown
} = {
message: DefaultLocaleMessageSchema
datetime: DefaultDateTimeFormatSchema
number: DefaultNumberFormatSchema
},
Locales extends
| {
messages: unknown
datetimeFormats: unknown
numberFormats: unknown
}
| string = Locale,
MessagesLocales = Locales extends { messages: infer M }
? M
: Locales extends string
? Locales
: Locale,
DateTimeFormatsLocales = Locales extends { datetimeFormats: infer D }
? D
: Locales extends string
? Locales
: Locale,
NumberFormatsLocales = Locales extends { numberFormats: infer N }
? N
: Locales extends string
? Locales
: Locale,
MessageSchema = Schema extends { message: infer M }
? M
: DefaultLocaleMessageSchema,
DateTimeSchema = Schema extends { datetime: infer D }
? D
: DefaultDateTimeFormatSchema,
NumberSchema = Schema extends { number: infer N }
? N
: DefaultNumberFormatSchema,
_Messages extends LocaleMessages<
MessageSchema,
MessagesLocales,
VueMessageType
> = LocaleMessages<MessageSchema, MessagesLocales, VueMessageType>,
_DateTimeFormats extends DateTimeFormatsType<
DateTimeSchema,
DateTimeFormatsLocales
> = DateTimeFormatsType<DateTimeSchema, DateTimeFormatsLocales>,
_NumberFormats extends NumberFormatsType<
NumberSchema,
NumberFormatsLocales
> = NumberFormatsType<NumberSchema, NumberFormatsLocales>
> {
/**
* @remarks
* The locale of localization.
*
* If the locale contains a territory and a dialect, this locale contains an implicit fallback.
*
* @VueI18nSee [Scope and Locale Changing](../guide/essentials/scope)
*
* @defaultValue `'en-US'`
*/
locale?: Locale
/**
* @remarks
* The locale of fallback localization.
*
* For more complex fallback definitions see fallback.
*
* @VueI18nSee [Fallbacking](../guide/essentials/fallback)
*
* @defaultValue The default `'en-US'` for the `locale` if it's not specified, or it's `locale` value
*/
fallbackLocale?: FallbackLocale
/**
* @remarks
* Whether inheritance the root level locale to the component localization locale.
*
* If `false`, regardless of the root level locale, localize for each component locale.
*
* @VueI18nSee [Local Scope](../guide/essentials/scope#local-scope-2)
*
* @defaultValue `true`
*/
inheritLocale?: boolean
/**
* @remarks
* The locale messages of localization.
*
* @VueI18nSee [Getting Started](../guide/)
*
* @defaultValue `{}`
*/
messages?: { [K in keyof _Messages]: MessageSchema }
/**
* @remarks
* Allow use flat json messages or not
*
* @defaultValue `false`
*/
flatJson?: boolean
/**
* @remarks
* The datetime formats of localization.
*
* @VueI18nSee [Datetime Formatting](../guide/essentials/datetime)
*
* @defaultValue `{}`
*/
datetimeFormats?: { [K in keyof _DateTimeFormats]: DateTimeSchema }
/**
* @remarks
* The number formats of localization.
*
* @VueI18nSee [Number Formatting](../guide/essentials/number)
*
* @defaultValue `{}`
*/
numberFormats?: { [K in keyof _NumberFormats]: NumberSchema }
/**
* @remarks
* Custom Modifiers for linked messages.
*
* @VueI18nSee [Custom Modifiers](../guide/essentials/syntax#custom-modifiers)
*/
modifiers?: LinkedModifiers<VueMessageType>
/**
* @remarks
* A set of rules for word pluralization
*
* @VueI18nSee [Custom Pluralization](../guide/essentials/pluralization#custom-pluralization)
*
* @defaultValue `{}`
*/
pluralRules?: PluralizationRules
/**
* @remarks
* A handler for localization missing.
*
* The handler gets called with the localization target locale, localization path key, the Vue instance and values.
*
* If missing handler is assigned, and occurred localization missing, it's not warned.
*
* @defaultValue `null`
*/
missing?: MissingHandler
/**
* @remarks
* Whether suppress warnings outputted when localization fails.
*
* If `false`, suppress localization fail warnings.
*
* If you use regular expression, you can suppress localization fail warnings that it match with translation key (e.g. `t`).
*
* @VueI18nSee [Fallbacking](../guide/essentials/fallback)
*
* @defaultValue `true`
*/
missingWarn?: boolean | RegExp
/**
* @remarks
* Whether suppress warnings when falling back to either `fallbackLocale` or root.
*
* If `false`, suppress fall back warnings.
*
* If you use regular expression, you can suppress fallback warnings that it match with translation key (e.g. `t`).
*
* @VueI18nSee [Fallbacking](../guide/essentials/fallback)
*
* @defaultValue `true`
*/
fallbackWarn?: boolean | RegExp
/**
* @remarks
* In the component localization, whether to fallback to root level (global scope) localization when localization fails.
*
* If `false`, it's not fallback to root.
*
* @VueI18nSee [Fallbacking](../guide/essentials/fallback)
*
* @defaultValue `true`
*/
fallbackRoot?: boolean
/**
* @remarks
* Whether do template interpolation on translation keys when your language lacks a translation for a key.
*
* If `true`, skip writing templates for your "base" language; the keys are your templates.
*
* @VueI18nSee [Fallbacking](../guide/essentials/fallback)
*
* @defaultValue `false`
*/
fallbackFormat?: boolean
/**
* @remarks
* A handler for post processing of translation.
*
* The handler gets after being called with the `t`.
*
* This handler is useful if you want to filter on translated text such as space trimming.
*
* @defaultValue `null`
*/
postTranslation?: PostTranslationHandler<VueMessageType>
/**
* @remarks
* Whether to allow the use locale messages of HTML formatting.
*
* See the warnHtmlMessage property.
*
* @VueI18nSee [HTML Message](../guide/essentials/syntax#html-message)
* @VueI18nSee [Change `warnHtmlInMessage` option default value](../guide/migration/breaking#change-warnhtmlinmessage-option-default-value)
*
* @defaultValue `'off'`
*/
warnHtmlMessage?: boolean
/**
* @remarks
* If `escapeParameter` is configured as true then interpolation parameters are escaped before the message is translated.
*
* This is useful when translation output is used in `v-html` and the translation resource contains html markup (e.g. <b> around a user provided value).
*
* This usage pattern mostly occurs when passing precomputed text strings into UI components.
*
* The escape process involves replacing the following symbols with their respective HTML character entities: `<`, `>`, `"`, `'`.
*
* Setting `escapeParameter` as true should not break existing functionality but provides a safeguard against a subtle type of XSS attack vectors.
*
* @VueI18nSee [HTML Message](../guide/essentials/syntax#html-message)
*
* @defaultValue `false`
*/
escapeParameter?: boolean
/**
* @remarks
* A message resolver to resolve [`messages`](composition#messages).
*
* If not specified, the vue-i18n internal message resolver will be used by default.
*
* You need to implement a message resolver yourself that supports the following requirements:
*
* - Resolve the message using the locale message of [`locale`](composition#locale) passed as the first argument of the message resolver, and the path passed as the second argument.
*
* - If the message could not be resolved, you need to return `null`.
*
* - If you will be returned `null`, the message resolver will also be called on fallback if [`fallbackLocale`](composition#fallbacklocale-2) is enabled, so the message will need to be resolved as well.
*
* The message resolver is called indirectly by the following APIs:
*
* - [`t`](composition#t-key)
*
* - [`te`](composition#te-key-locale)
*
* - [`tm`](composition#tm-key)
*
* - [Translation component](component#translation)
*
* @example
* Here is an example of how to set it up using your `createI18n`:
* ```js
* import { createI18n } from 'vue-i18n'
*
* // your message resolver
* function messageResolver(obj, path) {
* // simple message resolving!
* const msg = obj[path]
* return msg != null ? msg : null
* }
*
* // call with I18n option
* const i18n = createI18n({
* legacy: false,
* locale: 'ja',
* messageResolver, // set your message resolver
* messages: {
* en: { ... },
* ja: { ... }
* }
* })
*
* // the below your something to do ...
* // ...
* ```
*
* @VueI18nTip
* :new: v9.2+
*
* @VueI18nWarning
* If you use the message resolver, the [`flatJson`](composition#flatjson) setting will be ignored. That is, you need to resolve the flat JSON by yourself.
*
* @VueI18nSee [Fallbacking](../guide/essentials/fallback)
*
* @defaultValue `undefined`
*/
messageResolver?: MessageResolver
/**
* @remarks
* A compiler for custom message format.
*
* If not specified, the vue-i18n default message compiler will be used.
*
* You will need to implement your own message compiler that returns Message Functions
*
* @example
* Here is an example of how to custom message compiler with `intl-messageformat`
*
* ```js
* import { createI18n } from 'vue-i18n'
* import IntlMessageFormat from 'intl-messageformat'
*
* function messageCompiler(message, { locale, key, onError }) {
* if (typeof message === 'string') {
* // You can tune your message compiler performance more with your cache strategy or also memoization at here
* const formatter = new IntlMessageFormat(message, locale)
* return ctx => formatter.format(ctx.values)
* } else {
* // If you would like to support it for AST,
* // You need to transform locale mesages such as `json`, `yaml`, etc. with the bundle plugin.
* onError && onError(new Error('not support for AST'))
* return () => key // return default with `key`
* }
* }
*
* // call with I18n option
* const i18n = createI18n({
* legacy: false,
* locale: 'ja',
* messageCompiler, // set your message compiler
* messages: {
* en: {
* hello: 'hello world!',
* greeting: 'hi, {name}!',
* // ICU Message format
* photo: `You have {numPhotos, plural,
* =0 {no photos.}
* =1 {one photo.}
* other {# photos.}
* }`
* },
* }
* })
*
* // the below your something to do ...
* // ...
* ```
*
* @VueI18nTip
* :new: v9.3+
*
* @VueI18nWarning
* The Custom Message Format is an experimental feature. It may receive breaking changes or be removed in the future.
*
* @VueI18nSee [Custom Message Format](../guide/advanced/format)
*
* @defaultValue `undefined`
*/
messageCompiler?: MessageCompiler
}
/**
* @internal
*/
export interface ComposerInternalOptions<
Messages extends Record<string, any> = {},
DateTimeFormats extends Record<string, any> = {},
NumberFormats extends Record<string, any> = {}
> {
__i18n?: CustomBlocks<VueMessageType>
__i18nGlobal?: CustomBlocks<VueMessageType>
__root?: Composer<Messages, DateTimeFormats, NumberFormats>
__injectWithOption?: boolean
}
/**
* Locale message translation functions
*
* @remarks
* This is the interface for {@link Composer}
*
* @VueI18nComposition
*/
export interface ComposerTranslation<
Messages extends Record<string, any> = {},
Locales = 'en-US',
DefinedLocaleMessage extends
RemovedIndexResources<DefineLocaleMessage> = RemovedIndexResources<DefineLocaleMessage>,
C = IsEmptyObject<DefinedLocaleMessage> extends false
? PickupPaths<{
[K in keyof DefinedLocaleMessage]: DefinedLocaleMessage[K]
}>
: never,
M = IsEmptyObject<Messages> extends false ? PickupKeys<Messages> : never,
ResourceKeys extends C | M = IsNever<C> extends false
? IsNever<M> extends false
? C | M
: C
: IsNever<M> extends false
? M
: never
> {
/**
* Locale message translation
*
* @remarks
* If this is used in a reactive context, it will re-evaluate once the locale changes.
*
* If [UseI18nScope](general#usei18nscope) `'local'` or Some [UseI18nOptions](composition#usei18noptions) are specified at `useI18n`, it’s translated in preferentially local scope locale messages than global scope locale messages.
*
* If not, then it’s translated with global scope locale messages.
*
* @param key - A target locale message key
*
* @returns Translated message
*
* @VueI18nSee [Scope and Locale Changing](../guide/essentials/scope)
*/
<Key extends string>(key: Key | ResourceKeys | number): string
/**
* Locale message translation for plurals
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, return a pluralized translation message.
*
* You can also suppress the warning, when the translation missing according to the options.
*
* About details of options, see the {@link TranslateOptions}.
*
* @param key - A target locale message key
* @param plural - Which plural string to get. 1 returns the first one.
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*
* @VueI18nSee [Pluralization](../guide/essentials/pluralization)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
plural: number,
options?: TranslateOptions<Locales>
): string
/**
* Locale message translation for missing default message
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, if no translation was found, return a default message.
*
* You can also suppress the warning, when the translation missing according to the options.
*
* About details of options, see the {@link TranslateOptions}.
*
* @param key - A target locale message key
* @param defaultMsg - A default message to return if no translation was found
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*/
<Key extends string>(
key: Key | ResourceKeys | number,
defaultMsg: string,
options?: TranslateOptions<Locales>
): string
/**
* Locale message translation for list interpolations
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, the locale messages should contain a `{0}`, `{1}`, … for each placeholder in the list.
*
* You can also suppress the warning, when the translation missing according to the options.
*
* About details of options, see the {@link TranslateOptions}.
*
* @param key - A target locale message key
* @param list - A values of list interpolation
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*
* @VueI18nSee [List interpolation](../guide/essentials/syntax#list-interpolation)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
list: unknown[],
options?: TranslateOptions<Locales>
): string
/**
* Locale message translation for list interpolations and plurals
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, the locale messages should contain a `{0}`, `{1}`, … for each placeholder in the list, and return a pluralized translation message.
*
* @param key - A target locale message key
* @param list - A values of list interpolation
* @param plural - Which plural string to get. 1 returns the first one.
*
* @returns Translated message
*
* @VueI18nSee [Pluralization](../guide/essentials/pluralization)
* @VueI18nSee [List interpolation](../guide/essentials/syntax#list-interpolation)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
list: unknown[],
plural: number
): string
/**
* Locale message translation for list interpolations and missing default message
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, the locale messages should contain a `{0}`, `{1}`, … for each placeholder in the list, and if no translation was found, return a default message.
*
* @param key - A target locale message key
* @param list - A values of list interpolation
* @param defaultMsg - A default message to return if no translation was found
*
* @returns Translated message
*
* @VueI18nSee [List interpolation](../guide/essentials/syntax#list-interpolation)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
list: unknown[],
defaultMsg: string
): string
/**
* Locale message translation for named interpolations
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, for each placeholder x, the locale messages should contain a `{x}` token.
*
* You can also suppress the warning, when the translation missing according to the options.
*
* About details of options, see the {@link TranslateOptions}.
*
* @param key - A target locale message key
* @param named - A values of named interpolation
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*
* @VueI18nSee [Named interpolation](../guide/essentials/syntax#named-interpolation)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
named: NamedValue,
options?: TranslateOptions<Locales>
): string
/**
* Locale message translation for named interpolations and plurals
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, for each placeholder x, the locale messages should contain a `{x}` token, and return a pluralized translation message.
*
* @param key - A target locale message key
* @param named - A values of named interpolation
* @param plural - Which plural string to get. 1 returns the first one.
*
* @returns Translated message
*
* @VueI18nSee [Pluralization](../guide/essentials/pluralization)
* @VueI18nSee [Named interpolation](../guide/essentials/syntax#named-interpolation)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
named: NamedValue,
plural: number
): string
/**
* Locale message translation for named interpolations and plurals
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, for each placeholder x, the locale messages should contain a `{x}` token, and if no translation was found, return a default message.
*
* @param key - A target locale message key
* @param named - A values of named interpolation
* @param defaultMsg - A default message to return if no translation was found
*
* @returns Translated message
*
* @VueI18nSee [Named interpolation](../guide/essentials/syntax#named-interpolation)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
named: NamedValue,
defaultMsg: string
): string
}
/**
* Resolve locale message translation functions
*
* @remarks
* This is the interface for {@link Composer}
*
* @VueI18nComposition
*/
export interface ComposerResolveLocaleMessageTranslation<Locales = 'en-US'> {
/**
* Resolve locale message translation
*
* @remarks
* If this is used in a reactive context, it will re-evaluate once the locale changes.
*
* If [UseI18nScope](general#usei18nscope) `'local'` or Some [UseI18nOptions](composition#usei18noptions) are specified at `useI18n`, it’s translated in preferentially local scope locale messages than global scope locale messages.
*
* If not, then it’s translated with global scope locale messages.
*
* @VueI18nTip
* The use-case for `rt` is for programmatic locale messages translation with using `tm`, `v-for`, javascript `for` statement.
*
* @VueI18nWarning
* `rt` differs from `t` in that it processes the locale message directly, not the key of the locale message. There is no internal fallback with `rt`. You need to understand and use the structure of the locale messge returned by `tm`.
*
* @param message - A target locale message to be resolved. You will need to specify the locale message returned by `tm`.
*
* @returns Translated message
*
* @VueI18nSee [Scope and Locale Changing](../guide/essentials/scope)
*/
(message: MessageFunction<VueMessageType> | VueMessageType): string
/**
* Resolve locale message translation for plurals
*
* @remarks
* Overloaded `rt`. About details, see the [call signature](composition#message-messagefunction-message-message-string) details.
*
* In this overloaded `rt`, return a pluralized translation message.
*
* @VueI18nTip
* The use-case for `rt` is for programmatic locale messages translation with using `tm`, `v-for`, javascript `for` statement.
*
* @VueI18nWarning
* `rt` differs from `t` in that it processes the locale message directly, not the key of the locale message. There is no internal fallback with `rt`. You need to understand and use the structure of the locale messge returned by `tm`.
*
* @param message - A target locale message to be resolved. You will need to specify the locale message returned by `tm`.
* @param plural - Which plural string to get. 1 returns the first one.
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*
* @VueI18nSee [Pluralization](../guide/essentials/pluralization)
*/
(
message: MessageFunction<VueMessageType> | VueMessageType,
plural: number,
options?: TranslateOptions<Locales>
): string
/**
* Resolve locale message translation for list interpolations
*
* @remarks
* Overloaded `rt`. About details, see the [call signature](composition#message-messagefunction-message-message-string) details.
*
* In this overloaded `rt`, return a pluralized translation message.
*
* @VueI18nTip
* The use-case for `rt` is for programmatic locale messages translation with using `tm`, `v-for`, javascript `for` statement.
*
* @VueI18nWarning
* `rt` differs from `t` in that it processes the locale message directly, not the key of the locale message. There is no internal fallback with `rt`. You need to understand and use the structure of the locale messge returned by `tm`.
*
* @param message - A target locale message to be resolved. You will need to specify the locale message returned by `tm`.
* @param list - A values of list interpolation.
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*
* @VueI18nSee [List interpolation](../guide/essentials/syntax#list-interpolation)
*/
(
message: MessageFunction<VueMessageType> | VueMessageType,
list: unknown[],
options?: TranslateOptions<Locales>
): string
/**
* Resolve locale message translation for named interpolations
*
* @remarks
* Overloaded `rt`. About details, see the [call signature](composition#message-messagefunction-message-message-string) details.
*
* In this overloaded `rt`, for each placeholder x, the locale messages should contain a `{x}` token.
*
* @VueI18nTip
* The use-case for `rt` is for programmatic locale messages translation with using `tm`, `v-for`, javascript `for` statement.
*
* @VueI18nWarning
* `rt` differs from `t` in that it processes the locale message directly, not the key of the locale message. There is no internal fallback with `rt`. You need to understand and use the structure of the locale messge returned by `tm`.
*
* @param message - A target locale message to be resolved. You will need to specify the locale message returned by `tm`.
* @param named - A values of named interpolation.
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*
* @VueI18nSee [Named interpolation](../guide/essentials/syntax#named-interpolation)
*/
(
message: MessageFunction<VueMessageType> | VueMessageType,
named: NamedValue,
options?: TranslateOptions<Locales>
): string
}
/**
* Datetime formatting functions
*
* @remarks
* This is the interface for {@link Composer}
*
* @VueI18nComposition
*/
export interface ComposerDateTimeFormatting<
DateTimeFormats extends Record<string, any> = {},
Locales = 'en-US',
DefinedDateTimeFormat extends
RemovedIndexResources<DefineDateTimeFormat> = RemovedIndexResources<DefineDateTimeFormat>,
C = IsEmptyObject<DefinedDateTimeFormat> extends false
? PickupFormatPathKeys<{
[K in keyof DefinedDateTimeFormat]: DefinedDateTimeFormat[K]
}>
: never,
M = IsEmptyObject<DateTimeFormats> extends false
? PickupFormatKeys<DateTimeFormats>
: never,
ResourceKeys extends C | M = IsNever<C> extends false
? IsNever<M> extends false