UNPKG

vue-i18n-bridge

Version:
1,146 lines (1,137 loc) 149 kB
import type { App } from 'vue'; import type { ComponentInternalInstance } from 'vue'; import type { ComputedRef } from '@vue/reactivity'; import { DateTimeOptions } from '@intlify/core-base'; import { FallbackLocale } from '@intlify/core-base'; import type { FallbackLocales } from '@intlify/core-base'; import { InjectionKey } from 'vue'; import { DateTimeFormat as IntlDateTimeFormat } from '@intlify/core-base'; import { DateTimeFormats as IntlDateTimeFormats } from '@intlify/core-base'; import { FormatMatcher as IntlFormatMatcher } from '@intlify/core-base'; import { LocaleMatcher as IntlLocaleMatcher } from '@intlify/core-base'; import { NumberFormat as IntlNumberFormat } from '@intlify/core-base'; import { NumberFormats as IntlNumberFormats } from '@intlify/core-base'; import { IsEmptyObject } from '@intlify/core-base'; import { IsNever } from '@intlify/core-base'; import { LinkedModifiers } from '@intlify/core-base'; import { Locale } from '@intlify/core-base'; import type { LocaleMessage } from '@intlify/core-base'; import { LocaleMessageDictionary } from '@intlify/core-base'; import { LocaleMessages } from '@intlify/core-base'; import { LocaleMessageType } from '@intlify/core-base'; import { LocaleMessageValue } from '@intlify/core-base'; import type { LocaleParams } from '@intlify/core-base'; import { MessageFunction } from '@intlify/core-base'; import { MessageFunctions } from '@intlify/core-base'; import type { MessageResolver } from '@intlify/core-base'; import { NamedValue } from '@intlify/core-base'; import { NumberOptions } from '@intlify/core-base'; import { Path } from '@intlify/core-base'; import { PathValue } from '@intlify/core-base'; import type { PickupFormatKeys } from '@intlify/core-base'; import { PickupFormatPathKeys } from '@intlify/core-base'; import { PickupKeys } from '@intlify/core-base'; import type { PickupLocales } from '@intlify/core-base'; import { PickupPaths } from '@intlify/core-base'; import { PluralizationRule } from '@intlify/core-base'; import type { PluralizationRules } from '@intlify/core-base'; import { PostTranslationHandler } from '@intlify/core-base'; import type { RemoveIndexSignature } from '@intlify/core-base'; import type { ResourcePath } from '@intlify/core-base'; import type { ResourceValue } from '@intlify/core-base'; import type { SchemaParams } from '@intlify/core-base'; import { TranslateOptions } from '@intlify/core-base'; import type { VNode } from 'vue'; import type { WritableComputedRef } from '@vue/reactivity'; export declare type Choice = number; export declare type ComponentInstanceCreatedListener = <Messages>(target: VueI18n<Messages>, global: VueI18n<Messages>) => void; /** * Composer interfaces * * @remarks * This is the interface for being used for Vue 3 Composition API. * * @VueI18nComposition */ export declare interface Composer<Messages = {}, DateTimeFormats = {}, NumberFormats = {}, OptionLocale = Locale, ResourceLocales = PickupLocales<NonNullable<Messages>> | PickupLocales<NonNullable<DateTimeFormats>> | PickupLocales<NonNullable<NumberFormats>>, Locales = OptionLocale extends Locale ? [ResourceLocales] extends [never] ? Locale : ResourceLocales : OptionLocale | ResourceLocales> { /** * @remarks * Instance ID. */ id: number; /** * @remarks * The current locale this Composer instance is using. * * If the locale contains a territory and a dialect, this locale contains an implicit fallback. * * @VueI18nSee [Scope and Locale Changing](../guide/essentials/scope) */ locale: WritableComputedRef<Locales>; /** * @remarks * The current fallback locales this Composer instance is using. * * @VueI18nSee [Fallbacking](../guide/essentials/fallback) */ fallbackLocale: WritableComputedRef<FallbackLocales<Locales>>; /** * @remarks * Whether inherit the root level locale to the component localization locale. * * @VueI18nSee [Local Scope](../guide/essentials/scope#local-scope-2) */ inheritLocale: boolean; /** * @remarks * The list of available locales in `messages` in lexical order. */ readonly availableLocales: Locales[]; /** * @remarks * The locale messages of localization. * * @VueI18nSee [Getting Started](../guide/) */ readonly messages: ComputedRef<{ [K in keyof Messages]: Messages[K]; }>; /** * @remarks * The datetime formats of localization. * * @VueI18nSee [Datetime Formatting](../guide/essentials/datetime) */ readonly datetimeFormats: ComputedRef<{ [K in keyof DateTimeFormats]: DateTimeFormats[K]; }>; /** * @remarks * The number formats of localization. * * @VueI18nSee [Number Formatting](../guide/essentials/number) */ readonly numberFormats: ComputedRef<{ [K in keyof NumberFormats]: NumberFormats[K]; }>; /** * @remarks * Custom Modifiers for linked messages. * * @VueI18nSee [Custom Modifiers](../guide/essentials/syntax#custom-modifiers) */ readonly modifiers: LinkedModifiers<VueMessageType>; /** * @remarks * A set of rules for word pluralization * * @VueI18nSee [Custom Pluralization](../guide/essentials/pluralization#custom-pluralization) */ readonly pluralRules: PluralizationRules; /** * @remarks * Whether this composer instance is global or not */ readonly isGlobal: boolean; /** * @remarks * Whether suppress warnings outputted when localization fails. * * @VueI18nSee [Fallbacking](../guide/essentials/fallback) */ missingWarn: boolean | RegExp; /** * @remarks * Whether suppress fall back warnings when localization fails. * * @VueI18nSee [Fallbacking](../guide/essentials/fallback) */ fallbackWarn: boolean | RegExp; /** * @remarks * Whether to fall back to root level (global scope) localization when localization fails. * * @VueI18nSee [Fallbacking](../guide/essentials/fallback) */ fallbackRoot: boolean; /** * @remarks * Whether suppress warnings when falling back to either `fallbackLocale` or root. * * @VueI18nSee [Fallbacking](../guide/essentials/fallback) */ fallbackFormat: boolean; /** * @remarks * Whether to allow the use locale messages of HTML formatting. * * If you set `false`, will check the locale messages on the Composer instance. * * If you are specified `true`, a warning will be output at console. * * @VueI18nSee [HTML Message](../guide/essentials/syntax#html-message) * @VueI18nSee [Change `warnHtmlInMessage` option default value](../guide/migration/breaking#change-warnhtmlinmessage-option-default-value) */ warnHtmlMessage: boolean; /** * @remarks * Whether interpolation parameters are escaped before the message is translated. * * @VueI18nSee [HTML Message](../guide/essentials/syntax#html-message) */ escapeParameter: boolean; /** * Locale message translation * * @remarks * About details functions, See the {@link ComposerTranslation} */ t: ComposerTranslation<Messages, Locales, RemoveIndexSignature<{ [K in keyof DefineLocaleMessage]: DefineLocaleMessage[K]; }>>; /** * Resolve locale message translation * * @remarks * About details functions, See the {@link ComposerResolveLocaleMessageTranslation} */ rt: ComposerResolveLocaleMessageTranslation<Locales>; /** * Datetime formatting * * @remarks * About details functions, See the {@link ComposerDateTimeFormatting} */ d: ComposerDateTimeFormatting<DateTimeFormats, Locales, RemoveIndexSignature<{ [K in keyof DefineDateTimeFormat]: DefineDateTimeFormat[K]; }>>; /** * Number Formatting * * @remarks * About details functions, See the {@link ComposerNumberFormatting} */ n: ComposerNumberFormatting<NumberFormats, Locales, RemoveIndexSignature<{ [K in keyof DefineNumberFormat]: DefineNumberFormat[K]; }>>; /** * Translation locale message exist * * @remarks * whether do exist locale message on Composer instance [messages](composition#messages). * * If you specified `locale`, check the locale messages of `locale`. * * @param key - A target locale message key * @param locale - A locale, it will be used over than global scope or local scope * * @returns If found locale message, `true`, else `false` */ te<Str extends string, Key extends PickupKeys<Messages> = PickupKeys<Messages>>(key: Str | Key, locale?: Locales): boolean; /** * Locale messages getter * * @remarks * 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. * * Based on the current `locale`, locale messages will be returned from Composer instance messages. * * If you change the `locale`, the locale messages returned will also correspond to the locale. * * If there are no locale messages for the given `key` in the composer instance messages, they will be returned with [fallbacking](../guide/essentials/fallback). * * @VueI18nWarning * You need to use `rt` for the locale message returned by `tm`. see the [rt](composition#rt-message) details. * * @example * template block: * ```html * <div class="container"> * <template v-for="content in tm('contents')"> * <h2>{{ rt(content.title) }}</h2> * <p v-for="paragraph in content.paragraphs"> * {{ rt(paragraph) }} * </p> * </template> * </div> * ``` * script block: * ```js * import { defineComponent } from 'vue * import { useI18n } from 'vue-i18n' * * export default defineComponent({ * setup() { * const { rt, tm } = useI18n({ * messages: { * en: { * contents: [ * { * title: 'Title1', * // ... * paragraphs: [ * // ... * ] * } * ] * } * } * // ... * }) * // ... * return { ... , rt, tm } * } * }) * ``` * * @param key - A target locale message key * * @return Locale messages */ tm<Key extends string, ResourceKeys extends PickupKeys<Messages> = PickupKeys<Messages>, Locale extends PickupLocales<NonNullable<Messages>> = PickupLocales<NonNullable<Messages>>, Target = IsEmptyObject<Messages> extends false ? NonNullable<Messages>[Locale] : RemoveIndexSignature<{ [K in keyof DefineLocaleMessage]: DefineLocaleMessage[K]; }>, Return = ResourceKeys extends ResourcePath<Target> ? ResourceValue<Target, ResourceKeys> : Record<string, any>>(key: Key | ResourceKeys): Return; /** * Get locale message * * @remarks * get locale message from Composer instance [messages](composition#messages). * * @param locale - A target locale * * @typeParam MessageSchema - The locale message schema, default `never` * * @returns Locale messages */ getLocaleMessage<MessageSchema extends LocaleMessage<VueMessageType> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<Messages>> = PickupLocales<NonNullable<Messages>>, Return = IsNever<MessageSchema> extends true ? IsEmptyObject<Messages> extends true ? RemoveIndexSignature<{ [K in keyof DefineLocaleMessage]: DefineLocaleMessage[K]; }> : NonNullable<Messages>[Locale] : MessageSchema>(locale: LocaleSchema | Locale): Return; /** * Set locale message * * @remarks * Set locale message to Composer instance [messages](composition#messages). * * @param locale - A target locale * @param message - A message * * @typeParam MessageSchema - The locale message schema, default `never` */ setLocaleMessage<MessageSchema extends LocaleMessage<VueMessageType> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<Messages>> = PickupLocales<NonNullable<Messages>>, MessageType = IsNever<MessageSchema> extends true ? IsEmptyObject<Messages> extends true ? RemoveIndexSignature<{ [K in keyof DefineLocaleMessage]: DefineLocaleMessage[K]; }> : NonNullable<Messages>[Locale] : MessageSchema, Message extends MessageType = MessageType>(locale: LocaleSchema | Locale, message: Message): void; /** * Merge locale message * * @remarks * Merge locale message to Composer instance [messages](composition#messages). * * @param locale - A target locale * @param message - A message * * @typeParam MessageSchema - The locale message schema, default `never` */ mergeLocaleMessage<MessageSchema extends LocaleMessage<VueMessageType> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<Messages>> = PickupLocales<NonNullable<Messages>>, Message = IsNever<MessageSchema> extends true ? Record<string, any> : MessageSchema>(locale: LocaleSchema | Locale, message: Message): void; /** * Get datetime format * * @remarks * get datetime format from Composer instance [datetimeFormats](composition#datetimeformats). * * @param locale - A target locale * * @typeParam DateTimeSchema - The datetime format schema, default `never` * * @returns Datetime format */ getDateTimeFormat<DateTimeSchema extends Record<string, any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<DateTimeFormats>> = PickupLocales<NonNullable<DateTimeFormats>>, Return = IsNever<DateTimeSchema> extends true ? IsEmptyObject<DateTimeFormats> extends true ? RemoveIndexSignature<{ [K in keyof DefineDateTimeFormat]: DefineDateTimeFormat[K]; }> : NonNullable<DateTimeFormats>[Locale] : DateTimeSchema>(locale: LocaleSchema | Locale): Return; /** * Set datetime format * * @remarks * Set datetime format to Composer instance [datetimeFormats](composition#datetimeformats). * * @param locale - A target locale * @param format - A target datetime format * * @typeParam DateTimeSchema - The datetime format schema, default `never` */ setDateTimeFormat<DateTimeSchema extends Record<string, any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<DateTimeFormats>> = PickupLocales<NonNullable<DateTimeFormats>>, FormatsType = IsNever<DateTimeSchema> extends true ? IsEmptyObject<DateTimeFormats> extends true ? RemoveIndexSignature<{ [K in keyof DefineDateTimeFormat]: DefineDateTimeFormat[K]; }> : NonNullable<DateTimeFormats>[Locale] : DateTimeSchema, Formats extends FormatsType = FormatsType>(locale: LocaleSchema | Locale, format: Formats): void; /** * Merge datetime format * * @remarks * Merge datetime format to Composer instance [datetimeFormats](composition#datetimeformats). * * @param locale - A target locale * @param format - A target datetime format * * @typeParam DateTimeSchema - The datetime format schema, default `never` */ mergeDateTimeFormat<DateTimeSchema extends Record<string, any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<DateTimeFormats>> = PickupLocales<NonNullable<DateTimeFormats>>, Formats = IsNever<DateTimeSchema> extends true ? Record<string, any> : DateTimeSchema>(locale: LocaleSchema | Locale, format: Formats): void; /** * Get number format * * @remarks * get number format from Composer instance [numberFormats](composition#numberFormats). * * @param locale - A target locale * * @typeParam NumberSchema - The number format schema, default `never` * * @returns Number format */ getNumberFormat<NumberSchema extends Record<string, any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<NumberFormats>> = PickupLocales<NonNullable<NumberFormats>>, Return = IsNever<NumberSchema> extends true ? IsEmptyObject<NumberFormats> extends true ? RemoveIndexSignature<{ [K in keyof DefineNumberFormat]: DefineNumberFormat[K]; }> : NonNullable<NumberFormats>[Locale] : NumberSchema>(locale: LocaleSchema | Locale): Return; /** * Set number format * * @remarks * Set number format to Composer instance [numberFormats](composition#numberFormats). * * @param locale - A target locale * @param format - A target number format * * @typeParam NumberSchema - The number format schema, default `never` */ setNumberFormat<NumberSchema extends Record<string, any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<NumberFormats>> = PickupLocales<NonNullable<NumberFormats>>, FormatsType = IsNever<NumberSchema> extends true ? IsEmptyObject<NumberFormats> extends true ? RemoveIndexSignature<{ [K in keyof DefineNumberFormat]: DefineNumberFormat[K]; }> : NonNullable<NumberFormats>[Locale] : NumberSchema, Formats extends FormatsType = FormatsType>(locale: LocaleSchema | Locale, format: Formats): void; /** * Merge number format * * @remarks * Merge number format to Composer instance [numberFormats](composition#numberFormats). * * @param locale - A target locale * @param format - A target number format * * @typeParam NumberSchema - The number format schema, default `never` */ mergeNumberFormat<NumberSchema extends Record<string, any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<NumberFormats>> = PickupLocales<NonNullable<NumberFormats>>, Formats = IsNever<NumberSchema> extends true ? Record<string, any> : NumberSchema>(locale: LocaleSchema | Locale, format: Formats): void; /** * Get post translation handler * * @returns {@link PostTranslationHandler} * * @VueI18nSee [missing](composition#posttranslation) */ getPostTranslationHandler(): PostTranslationHandler<VueMessageType> | null; /** * Set post translation handler * * @param handler - A {@link PostTranslationHandler} * * @VueI18nSee [missing](composition#posttranslation) */ setPostTranslationHandler(handler: PostTranslationHandler<VueMessageType> | null): void; /** * Get missing handler * * @returns {@link MissingHandler} * * @VueI18nSee [missing](composition#missing) */ getMissingHandler(): MissingHandler | null; /** * Set missing handler * * @param handler - A {@link MissingHandler} * * @VueI18nSee [missing](composition#missing) */ setMissingHandler(handler: MissingHandler | null): void; } /** * Composer additional options for `useI18n` * * @remarks * `ComposerAdditionalOptions` is extend for {@link ComposerOptions}, so you can specify these options. * * @VueI18nSee [useI18n](composition#usei18n) * * @VueI18nComposition */ export declare interface ComposerAdditionalOptions { useScope?: I18nScope; } /** * Datetime formatting functions * * @remarks * This is the interface for {@link Composer} * * @VueI18nComposition */ export declare interface ComposerDateTimeFormatting<DateTimeFormats = {}, 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 ? C | M : C : IsNever<M> extends false ? M : never> { /** * Datetime formatting * * @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 datetime formats than global scope datetime formats. * * If not, then it’s formatted with global scope datetime formats. * * @param value - A value, timestamp number or `Date` instance or ISO 8601 string * * @returns Formatted value * * @VueI18nSee [Datetime formatting](../guide/essentials/datetime) */ (value: number | Date | string): string; /** * Datetime formatting * * @remarks * Overloaded `d`. About details, see the [call signature](composition#value-number-date-string-string) details. * * In this overloaded `d`, format in datetime format for a key registered in datetime formats. * * @param value - A value, timestamp number or `Date` instance or ISO 8601 string * @param keyOrOptions - A key of datetime formats, or additional {@link DateTimeOptions | options} for datetime formatting * * @returns Formatted value */ <Value extends number | Date | string = number, Key extends string = string>(value: Value, keyOrOptions: Key | ResourceKeys | DateTimeOptions<Key | ResourceKeys, Locales>): string; /** * Datetime formatting * * @remarks * Overloaded `d`. About details, see the [call signature](composition#value-number-date-string-string) details. * * In this overloaded `d`, format in datetime format for a key registered in datetime formats at target locale * * @param value - A value, timestamp number or `Date` instance or ISO 8601 string * @param keyOrOptions - A key of datetime formats, or additional {@link DateTimeOptions | options} for datetime formatting * @param locale - A locale, it will be used over than global scope or local scope. * * @returns Formatted value */ <Value extends number | Date | string = number, Key extends string = string>(value: Value, keyOrOptions: Key | ResourceKeys | DateTimeOptions<Key | ResourceKeys, Locales>, locale: Locales): string; } /** * Number formatting functions * * @remarks * This is the interface for {@link Composer} * * @VueI18nComposition */ export declare interface ComposerNumberFormatting<NumberFormats = {}, Locales = 'en-US', DefinedNumberFormat extends RemovedIndexResources<DefineNumberFormat> = RemovedIndexResources<DefineNumberFormat>, C = IsEmptyObject<DefinedNumberFormat> extends false ? PickupFormatPathKeys<{ [K in keyof DefinedNumberFormat]: DefinedNumberFormat[K]; }> : never, M = IsEmptyObject<NumberFormats> extends false ? PickupFormatKeys<NumberFormats> : never, ResourceKeys extends C | M = IsNever<C> extends false ? IsNever<M> extends false ? C | M : C : IsNever<M> extends false ? M : never> { /** * Number Formatting * * @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 datetime formats than global scope datetime formats. * * If not, then it’s formatted with global scope number formats. * * @param value - A number value * * @returns Formatted value * * @VueI18nSee [Number formatting](../guide/essentials/number) */ (value: number): string; /** * Number Formatting * * @remarks * Overloaded `n`. About details, see the [call signature](composition#value-number-string) details. * * In this overloaded `n`, format in number format for a key registered in number formats. * * @param value - A number value * @param keyOrOptions - A key of number formats, or additional {@link NumberOptions | options} for number formatting * * @returns Formatted value */ <Key extends string = string>(value: number, keyOrOptions: Key | ResourceKeys | NumberOptions<Key | ResourceKeys, Locales>): string; /** * Number Formatting * * @remarks * Overloaded `n`. About details, see the [call signature](composition#value-number-string) details. * * In this overloaded `n`, format in number format for a key registered in number formats at target locale. * * @param value - A number value * @param keyOrOptions - A key of number formats, or additional {@link NumberOptions | options} for number formatting * @param locale - A locale, it will be used over than global scope or local scope. * * @returns Formatted value */ <Key extends string = string>(value: number, keyOrOptions: Key | ResourceKeys | NumberOptions<Key | ResourceKeys, Locales>, locale: Locales): string; } /** * Composer Options * * @remarks * This is options to create composer. * * @VueI18nComposition */ export declare 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 IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales> = IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales>, _NumberFormats extends IntlNumberFormats<NumberSchema, NumberFormatsLocales> = IntlNumberFormats<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; } /** * Resolve locale message translation functions * * @remarks * This is the interface for {@link Composer} * * @VueI18nComposition */ export declare 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; } /** * Locale message translation functions * * @remarks * This is the interface for {@link Composer} * * @VueI18nComposition */ export declare interface ComposerTranslation<Messages = {}, 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 interpol