vue-i18n
- Version 9.14.1
- Published
- 1.63 MB
- 3 dependencies
- MIT license
Install
npm i vue-i18n
yarn add vue-i18n
pnpm add vue-i18n
Overview
Internationalization plugin for Vue.js
Index
Variables
Functions
Interfaces
Composer
- availableLocales
- d
- datetimeFormats
- escapeParameter
- fallbackFormat
- fallbackLocale
- fallbackRoot
- fallbackWarn
- getDateTimeFormat()
- getLocaleMessage()
- getMissingHandler()
- getNumberFormat()
- getPostTranslationHandler()
- id
- inheritLocale
- isGlobal
- locale
- mergeDateTimeFormat()
- mergeLocaleMessage()
- mergeNumberFormat()
- messages
- missingWarn
- modifiers
- n
- numberFormats
- pluralRules
- rt
- setDateTimeFormat()
- setLocaleMessage()
- setMissingHandler()
- setNumberFormat()
- setPostTranslationHandler()
- t
- te()
- tm()
- warnHtmlMessage
VueI18n
- availableLocales
- d
- datetimeFormats
- escapeParameterHtml
- fallbackLocale
- formatFallbackMessages
- formatter
- getChoiceIndex
- getDateTimeFormat
- getLocaleMessage
- getNumberFormat
- id
- locale
- mergeDateTimeFormat
- mergeLocaleMessage
- mergeNumberFormat
- messages
- missing
- modifiers
- n
- numberFormats
- pluralizationRules
- postTranslation
- preserveDirectiveContent
- rt
- setDateTimeFormat
- setLocaleMessage
- setNumberFormat
- silentFallbackWarn
- silentTranslationWarn
- sync
- t
- tc
- te()
- tm
- warnHtmlInMessage
VueI18nOptions
- availableLocales
- datetimeFormats
- escapeParameterHtml
- fallbackLocale
- fallbackRoot
- flatJson
- formatFallbackMessages
- formatter
- locale
- messageResolver
- messages
- missing
- modifiers
- numberFormats
- pluralizationRules
- postTranslation
- preserveDirectiveContent
- sharedMessages
- silentFallbackWarn
- silentTranslationWarn
- sync
- warnHtmlInMessage
Type Aliases
- Choice
- ComponentI18nScope
- ComposerExtender
- CustomBlocks
- DatetimeFormatProps
- DateTimeFormatResult
- DefaultDateTimeFormatSchema
- DefaultLocaleMessageSchema
- DefaultNumberFormatSchema
- Disposer
- I18nMode
- I18nOptions
- I18nScope
- LocaleMessageObject
- MissingHandler
- NumberFormatProps
- NumberFormatResult
- PluralizationRulesMap
- TranslateResult
- TranslationDirective
- UseI18nOptions
- VTDirectiveValue
- VueI18nExtender
- VueI18nResolveLocaleMessageTranslation
- VueMessageType
- WarnHtmlInMessageLevel
Variables
variable DatetimeFormat
const DatetimeFormat: new () => { $props: VNodeProps & DatetimeFormatProps & BaseFormatProps;};
Datetime Format Component
Remarks
See the following items for property about details
[FormattableProps](component#formattableprops) [BaseFormatProps](component#baseformatprops) [Custom Formatting](../guide/essentials/datetime#custom-formatting)
Not supported IE, due to no support
Intl.DateTimeFormat#formatToParts
in [IE](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-datetimeformat)
variable I18nD
const I18nD: new () => { $props: VNodeProps & DatetimeFormatProps & BaseFormatProps;};
variable I18nInjectionKey
const I18nInjectionKey: any;
Injection key for useI18n
Remarks
The global injection key for I18n instances with
useI18n
. this injection key is used in Web Components. Specify the i18n instance created by createI18n together withprovide
function.
variable I18nN
const I18nN: new () => { $props: VNodeProps & NumberFormatProps & BaseFormatProps };
variable I18nT
const I18nT: new () => { $props: VNodeProps & TranslationProps };
variable NumberFormat
const NumberFormat: new () => { $props: VNodeProps & NumberFormatProps & BaseFormatProps;};
Number Format Component
Remarks
See the following items for property about details
[FormattableProps](component#formattableprops) [BaseFormatProps](component#baseformatprops) [Custom Formatting](../guide/essentials/number#custom-formatting)
Not supported IE, due to no support
Intl.NumberFormat#formatToParts
in [IE](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-numberformat)
variable Translation
const Translation: new () => { $props: VNodeProps & TranslationProps };
Translation Component
Remarks
See the following items for property about details
[TranslationProps](component#translationprops) [BaseFormatProps](component#baseformatprops) [Component Interpolation](../guide/advanced/component)
Example 1
<div id="app"><!-- ... --><i18n keypath="term" tag="label" for="tos"><a :href="url" target="_blank">{{ $t('tos') }}</a></i18n><!-- ... --></div>import { createApp } from 'vue'import { createI18n } from 'vue-i18n'const messages = {en: {tos: 'Term of Service',term: 'I accept xxx {0}.'},ja: {tos: '利用規約',term: '私は xxx の{0}に同意します。'}}const i18n = createI18n({locale: 'en',messages})const app = createApp({data: {url: '/term'}}).use(i18n).mount('#app')
variable VERSION
const VERSION: string;
Vue I18n Version
Remarks
Semver format. Same format as the package.json
version
field.
Functions
function castToVueI18n
castToVueI18n: ( i18n: I18n) => VueI18n< {}, {}, {}, string, never, string, Composer<{}, {}, {}, string, never, string>> & { install: (Vue: any, options?: any) => void };
Cast to VueI18n legacy compatible type
Parameter i18n
An instance of I18n
Returns
A i18n instance which is casted to VueI18n type
:new: provided by **vue-i18n-bridge only**
Remarks
This API is provided only with [vue-i18n-bridge](https://vue-i18n.intlify.dev/guide/migration/ways.html#what-is-vue-i18n-bridge).
The purpose of this function is to convert an I18n instance created with createI18n(legacy: true) into a
vue-i18n@v8.x
compatible instance ofnew VueI18n
in a TypeScript environment.
function createI18n
createI18n: { < Legacy extends boolean = true, Options extends I18nOptions< { message: any; datetime: any; number: any }, Locale, | ComposerOptions< { message: any; datetime: any; number: any }, Locale, any, any, any, any, any, any, LocaleMessages<MessageSchema, MessagesLocales, any>, IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales>, IntlNumberFormats<NumberSchema, NumberFormatsLocales> > | VueI18nOptions< { message: any; datetime: any; number: any }, Locale, ComposerOptions< { message: any; datetime: any; number: any }, Locale, any, any, any, any, any, any, LocaleMessages<MessageSchema, MessagesLocales, any>, IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales>, IntlNumberFormats<NumberSchema, NumberFormatsLocales> > > > = I18nOptions< { message: any; datetime: any; number: any }, Locale, | ComposerOptions< { message: any; datetime: any; number: any }, Locale, any, any, any, any, any, any, LocaleMessages<MessageSchema, MessagesLocales, any>, IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales>, IntlNumberFormats<NumberSchema, NumberFormatsLocales> > | VueI18nOptions< { message: any; datetime: any; number: any }, Locale, ComposerOptions< { message: any; datetime: any; number: any }, Locale, any, any, any, any, any, any, LocaleMessages<MessageSchema, MessagesLocales, any>, IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales>, IntlNumberFormats<NumberSchema, NumberFormatsLocales> > > >, Messages extends Record< string, unknown > = Options['messages'] extends Record<string, unknown> ? Options['messages'] : {}, DateTimeFormats extends Record< string, unknown > = Options['datetimeFormats'] extends Record<string, unknown> ? Options['datetimeFormats'] : {}, NumberFormats extends Record< string, unknown > = Options['numberFormats'] extends Record<string, unknown> ? Options['numberFormats'] : {}, OptionLocale = Options['locale'] extends string ? Options['locale'] : Locale >( options: Options, LegacyVueI18n?: any ): (typeof options)['legacy'] extends true ? I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale, true> : (typeof options)['legacy'] extends false ? I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale, false> : I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale, Legacy>; < Schema extends object = any, Locales extends string | object = 'en-US', Legacy extends boolean = true, Options extends I18nOptions< SchemaParams<Schema, any>, LocaleParams<Locales>, | ComposerOptions< SchemaParams<Schema, any>, LocaleParams<Locales>, any, any, any, any, any, any, LocaleMessages<MessageSchema, MessagesLocales, any>, IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales>, IntlNumberFormats<NumberSchema, NumberFormatsLocales> > | VueI18nOptions< SchemaParams<Schema, any>, LocaleParams<Locales>, ComposerOptions< SchemaParams<Schema, any>, LocaleParams<Locales>, any, any, any, any, any, any, LocaleMessages<MessageSchema, MessagesLocales, any>, IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales>, IntlNumberFormats<NumberSchema, NumberFormatsLocales> > > > = I18nOptions< SchemaParams<Schema, any>, LocaleParams<Locales>, | ComposerOptions< SchemaParams<Schema, any>, LocaleParams<Locales>, any, any, any, any, any, any, LocaleMessages<MessageSchema, MessagesLocales, any>, IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales>, IntlNumberFormats<NumberSchema, NumberFormatsLocales> > | VueI18nOptions< SchemaParams<Schema, any>, LocaleParams<Locales>, ComposerOptions< SchemaParams<Schema, any>, LocaleParams<Locales>, any, any, any, any, any, any, LocaleMessages<MessageSchema, MessagesLocales, any>, IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales>, IntlNumberFormats<NumberSchema, NumberFormatsLocales> > > >, Messages extends Record<string, unknown> = NonNullable< Options['messages'] > extends Record<string, unknown> ? NonNullable<Options['messages']> : {}, DateTimeFormats extends Record<string, unknown> = NonNullable< Options['datetimeFormats'] > extends Record<string, unknown> ? NonNullable<Options['datetimeFormats']> : {}, NumberFormats extends Record<string, unknown> = NonNullable< Options['numberFormats'] > extends Record<string, unknown> ? NonNullable<Options['numberFormats']> : {}, OptionLocale = Options['locale'] extends string ? Options['locale'] : Locale >( options: Options, LegacyVueI18n?: any ): Options['legacy'] extends true ? I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale, true> : Options['legacy'] extends false ? I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale, false> : I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale, Legacy>;};
Vue I18n factory
Parameter options
An options, see the I18nOptions
Returns
I18n instance
Remarks
If you use Legacy API mode, you need to specify VueI18nOptions and
legacy: true
option.If you use composition API mode, you need to specify ComposerOptions.
[Getting Started](../guide/essentials/started) [Composition API](../guide/advanced/composition)
Example 1
case: for Legacy API
import { createApp } from 'vue'import { createI18n } from 'vue-i18n'// call with I18n optionconst i18n = createI18n({locale: 'ja',messages: {en: { ... },ja: { ... }}})const App = {// ...}const app = createApp(App)// install!app.use(i18n)app.mount('#app')Example 2
case: for composition API
import { createApp } from 'vue'import { createI18n, useI18n } from 'vue-i18n'// call with I18n optionconst i18n = createI18n({legacy: false, // you must specify 'legacy: false' optionlocale: 'ja',messages: {en: { ... },ja: { ... }}})const App = {setup() {// ...const { t } = useI18n({ ... })return { ... , t }}}const app = createApp(App)// install!app.use(i18n)app.mount('#app')
function useI18n
useI18n: { < Options extends UseI18nOptions< { message: any; datetime: any; number: any }, Locale, ComposerOptions< { message: any; datetime: any; number: any }, Locale, any, any, any, any, any, any, LocaleMessages<MessageSchema, MessagesLocales, any>, IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales>, IntlNumberFormats<NumberSchema, NumberFormatsLocales> > > = UseI18nOptions< { message: any; datetime: any; number: any }, Locale, ComposerOptions< { message: any; datetime: any; number: any }, Locale, any, any, any, any, any, any, LocaleMessages<MessageSchema, MessagesLocales, any>, IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales>, IntlNumberFormats<NumberSchema, NumberFormatsLocales> > > >( options?: Options ): Composer< NonNullable<Options['messages']>, NonNullable<Options['datetimeFormats']>, NonNullable<Options['numberFormats']>, Options['locale'] extends unknown ? string : Options['locale'] >; < Schema = any, Locales = 'en-US', Options extends UseI18nOptions< SchemaParams<Schema, any>, LocaleParams<Locales>, ComposerOptions< SchemaParams<Schema, any>, LocaleParams<Locales>, any, any, any, any, any, any, LocaleMessages<MessageSchema, MessagesLocales, any>, IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales>, IntlNumberFormats<NumberSchema, NumberFormatsLocales> > > = UseI18nOptions< SchemaParams<Schema, any>, LocaleParams<Locales>, ComposerOptions< SchemaParams<Schema, any>, LocaleParams<Locales>, any, any, any, any, any, any, LocaleMessages<MessageSchema, MessagesLocales, any>, IntlDateTimeFormats<DateTimeSchema, DateTimeFormatsLocales>, IntlNumberFormats<NumberSchema, NumberFormatsLocales> > > >( options?: Options ): Composer< NonNullable<Options['messages']>, NonNullable<Options['datetimeFormats']>, NonNullable<Options['numberFormats']>, Options['locale'] extends unknown ? string : Options['locale'], any, ( Options['locale'] extends unknown ? string : Options['locale'] ) extends Locale ? any : any >;};
Use Composition API for Vue I18n
Parameter options
An options, see UseI18nOptions
Returns
Composer instance
Remarks
This function is mainly used by
setup
.If options are specified, Composer instance is created for each component and you can be localized on the component.
If options are not specified, you can be localized using the global Composer.
Example 1
case: Component resource base localization
<template><form><label>{{ t('language') }}</label><select v-model="locale"><option value="en">en</option><option value="ja">ja</option></select></form><p>message: {{ t('hello') }}</p></template><script>import { useI18n } from 'vue-i18n'export default {setup() {const { t, locale } = useI18n({locale: 'ja',messages: {en: { ... },ja: { ... }}})// Something to do ...return { ..., t, locale }}}</script>
function vTDirective
vTDirective: (i18n: I18n) => ObjectDirective<T>;
Interfaces
interface BaseFormatProps
interface BaseFormatProps {}
BaseFormat Props for Components that is offered Vue I18n
Remarks
The interface definitions of the underlying props of components such as Translation, DatetimeFormat, and NumberFormat.
property i18n
i18n?: Composer;
Remarks
A composer instance with an existing scope.
This option takes precedence over the
scope
option.
property locale
locale?: Locale;
Remarks
Specifies the locale to be used for the component.
If specified, the global scope or the locale of the parent scope of the target component will not be overridden and the specified locale will be used.
property scope
scope?: ComponentI18nScope;
Remarks
Specifies the scope to be used in the target component.
You can specify either
global
orparent
.If
global
is specified, global scope is used, else thenparent
is specified, the scope of the parent of the target component is used.If the parent is a global scope, the global scope is used, if it's a local scope, the local scope is used.
property tag
tag?: string | object;
Remarks
Used to wrap the content that is distribute in the slot. If omitted, the slot content is treated as Fragments.
You can specify a string-based tag name, such as
p
, or the object for which the component is defined.
interface Composer
interface Composer< Messages extends Record<string, any> = {}, DateTimeFormats extends Record<string, any> = {}, NumberFormats extends Record<string, any> = {}, OptionLocale = Locale, ResourceLocales = | PickupLocales<NonNullable<Messages>> | PickupLocales<NonNullable<DateTimeFormats>> | PickupLocales<NonNullable<NumberFormats>>, Locales = OptionLocale extends Locale ? IsNever<ResourceLocales> extends true ? Locale : ResourceLocales : OptionLocale | ResourceLocales> extends ComposerCustom {}
Composer interfaces
Remarks
This is the interface for being used for Vue 3 Composition API.
property availableLocales
readonly availableLocales: Locales[];
Remarks
The list of available locales in
messages
in lexical order.
property d
d: ComposerDateTimeFormatting< DateTimeFormats, Locales, RemoveIndexSignature<{ [K in keyof DefineDateTimeFormat]: DefineDateTimeFormat[K]; }>>;
Datetime formatting
Remarks
About details functions, See the ComposerDateTimeFormatting
property datetimeFormats
readonly datetimeFormats: ComputedRef<{ [K in keyof DateTimeFormats]: DateTimeFormats[K];}>;
Remarks
The datetime formats of localization.
[Datetime Formatting](../guide/essentials/datetime)
property escapeParameter
escapeParameter: boolean;
Remarks
Whether interpolation parameters are escaped before the message is translated.
[HTML Message](../guide/essentials/syntax#html-message)
property fallbackFormat
fallbackFormat: boolean;
Remarks
Whether suppress warnings when falling back to either
fallbackLocale
or root.[Fallbacking](../guide/essentials/fallback)
property fallbackLocale
fallbackLocale: WritableComputedRef<FallbackLocales<Locales>>;
Remarks
The current fallback locales this Composer instance is using.
[Fallbacking](../guide/essentials/fallback)
property fallbackRoot
fallbackRoot: boolean;
Remarks
Whether to fall back to root level (global scope) localization when localization fails.
[Fallbacking](../guide/essentials/fallback)
property fallbackWarn
fallbackWarn: boolean | RegExp;
Remarks
Whether suppress fall back warnings when localization fails.
[Fallbacking](../guide/essentials/fallback)
property id
id: number;
Remarks
Instance ID.
property inheritLocale
inheritLocale: boolean;
Remarks
Whether inherit the root level locale to the component localization locale.
[Local Scope](../guide/essentials/scope#local-scope-2)
property isGlobal
readonly isGlobal: boolean;
Remarks
Whether this composer instance is global or not
property locale
locale: WritableComputedRef<Locales>;
Remarks
The current locale this Composer instance is using.
If the locale contains a territory and a dialect, this locale contains an implicit fallback.
[Scope and Locale Changing](../guide/essentials/scope)
property messages
readonly messages: ComputedRef<{ [K in keyof Messages]: Messages[K];}>;
Remarks
The locale messages of localization.
[Getting Started](../guide/essentials/started)
property missingWarn
missingWarn: boolean | RegExp;
Remarks
Whether suppress warnings outputted when localization fails.
[Fallbacking](../guide/essentials/fallback)
property modifiers
readonly modifiers: LinkedModifiers<VueMessageType>;
Remarks
Custom Modifiers for linked messages.
[Custom Modifiers](../guide/essentials/syntax#custom-modifiers)
property n
n: ComposerNumberFormatting< NumberFormats, Locales, RemoveIndexSignature<{ [K in keyof DefineNumberFormat]: DefineNumberFormat[K]; }>>;
Number Formatting
Remarks
About details functions, See the ComposerNumberFormatting
property numberFormats
readonly numberFormats: ComputedRef<{ [K in keyof NumberFormats]: NumberFormats[K];}>;
Remarks
The number formats of localization.
[Number Formatting](../guide/essentials/number)
property pluralRules
readonly pluralRules: PluralizationRules;
Remarks
A set of rules for word pluralization
[Custom Pluralization](../guide/essentials/pluralization#custom-pluralization)
property rt
rt: ComposerResolveLocaleMessageTranslation<Locales>;
Resolve locale message translation
Remarks
About details functions, See the ComposerResolveLocaleMessageTranslation
property t
t: ComposerTranslation< Messages, Locales, RemoveIndexSignature<{ [K in keyof DefineLocaleMessage]: DefineLocaleMessage[K]; }>>;
Locale message translation
Remarks
About details functions, See the ComposerTranslation
property warnHtmlMessage
warnHtmlMessage: 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.[HTML Message](../guide/essentials/syntax#html-message) [Change
warnHtmlInMessage
option default value](../guide/migration/breaking#change-warnhtmlinmessage-option-default-value)
method getDateTimeFormat
getDateTimeFormat: < DateTimeSchema extends Record<string, any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<DateTimeFormats>> = PickupLocales< NonNullable<DateTimeFormats> >, Return = any>( locale: LocaleSchema | Locale) => Return;
Get datetime format
Parameter locale
A target locale
Returns
Datetime format
Remarks
get datetime format from Composer instance [datetimeFormats](composition#datetimeformats).
method getLocaleMessage
getLocaleMessage: < MessageSchema extends LocaleMessage<any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<Messages>> = PickupLocales< NonNullable<Messages> >, Return = any>( locale: LocaleSchema | Locale) => Return;
Get locale message
Parameter locale
A target locale
Returns
Locale messages
Remarks
get locale message from Composer instance [messages](composition#messages).
method getMissingHandler
getMissingHandler: () => MissingHandler | null;
Get missing handler
Returns
[missing](composition#missing)
method getNumberFormat
getNumberFormat: < NumberSchema extends Record<string, any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<NumberFormats>> = PickupLocales< NonNullable<NumberFormats> >, Return = any>( locale: LocaleSchema | Locale) => Return;
Get number format
Parameter locale
A target locale
Returns
Number format
Remarks
get number format from Composer instance [numberFormats](composition#numberFormats).
method getPostTranslationHandler
getPostTranslationHandler: () => PostTranslationHandler<VueMessageType> | null;
Get post translation handler
Returns
[missing](composition#posttranslation)
method mergeDateTimeFormat
mergeDateTimeFormat: < DateTimeSchema extends Record<string, any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<DateTimeFormats>> = PickupLocales< NonNullable<DateTimeFormats> >, Formats = Record<string, any> | DateTimeSchema>( locale: LocaleSchema | Locale, format: Formats) => void;
Merge datetime format
Parameter locale
A target locale
Parameter format
A target datetime format
Remarks
Merge datetime format to Composer instance [datetimeFormats](composition#datetimeformats).
method mergeLocaleMessage
mergeLocaleMessage: < MessageSchema extends LocaleMessage<any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<Messages>> = PickupLocales< NonNullable<Messages> >, Message = Record<string, any> | MessageSchema>( locale: LocaleSchema | Locale, message: Message) => void;
Merge locale message
Parameter locale
A target locale
Parameter message
A message
Remarks
Merge locale message to Composer instance [messages](composition#messages).
method mergeNumberFormat
mergeNumberFormat: < NumberSchema extends Record<string, any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<NumberFormats>> = PickupLocales< NonNullable<NumberFormats> >, Formats = Record<string, any> | NumberSchema>( locale: LocaleSchema | Locale, format: Formats) => void;
Merge number format
Parameter locale
A target locale
Parameter format
A target number format
Remarks
Merge number format to Composer instance [numberFormats](composition#numberFormats).
method setDateTimeFormat
setDateTimeFormat: < DateTimeSchema extends Record<string, any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<DateTimeFormats>> = PickupLocales< NonNullable<DateTimeFormats> >, FormatsType = any, Formats extends FormatsType = FormatsType>( locale: LocaleSchema | Locale, format: Formats) => void;
Set datetime format
Parameter locale
A target locale
Parameter format
A target datetime format
Remarks
Set datetime format to Composer instance [datetimeFormats](composition#datetimeformats).
method setLocaleMessage
setLocaleMessage: < MessageSchema extends LocaleMessage<any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<Messages>> = PickupLocales< NonNullable<Messages> >, MessageType = any, Message extends MessageType = MessageType>( locale: LocaleSchema | Locale, message: Message) => void;
Set locale message
Parameter locale
A target locale
Parameter message
A message
Remarks
Set locale message to Composer instance [messages](composition#messages).
method setMissingHandler
setMissingHandler: (handler: MissingHandler | null) => void;
Set missing handler
Parameter handler
[missing](composition#missing)
method setNumberFormat
setNumberFormat: < NumberSchema extends Record<string, any> = never, LocaleSchema extends string = string, Locale extends PickupLocales<NonNullable<NumberFormats>> = PickupLocales< NonNullable<NumberFormats> >, FormatsType = any, Formats extends FormatsType = FormatsType>( locale: LocaleSchema | Locale, format: Formats) => void;
Set number format
Parameter locale
A target locale
Parameter format
A target number format
Remarks
Set number format to Composer instance [numberFormats](composition#numberFormats).
method setPostTranslationHandler
setPostTranslationHandler: ( handler: PostTranslationHandler<VueMessageType> | null) => void;
Set post translation handler
Parameter handler
[missing](composition#posttranslation)
method te
te: < Str extends string, Key extends PickupKeys<Messages> = PickupKeys<Messages>>( key: Str | Key, locale?: Locales) => boolean;
Translation locale message exist
Parameter key
A target locale message key
Parameter locale
A locale, it will be used over than global scope or local scope
Returns
If found locale message,
true
, elsefalse
, Note thatfalse
is returned even if the value present in the key is not translatable, yet iftranslateExistCompatible
is set totrue
, it will returntrue
if the key is available, even if the value is not translatable.Remarks
whether do exist locale message on Composer instance [messages](composition#messages).
If you specified
locale
, check the locale messages oflocale
.
method tm
tm: < Key extends string, ResourceKeys extends PickupKeys<Messages> = PickupKeys<Messages>, Locale extends PickupLocales<NonNullable<Messages>> = PickupLocales< NonNullable<Messages> >, Target = any, Return = ResourceKeys extends ResourcePath<Target> ? ResourceValue<Target, ResourceKeys> : Record<string, any>>( key: Key | ResourceKeys) => Return;
Locale messages getter
Parameter key
A target locale message key
Locale messages
Remarks
If [UseI18nScope](general#usei18nscope)
'local'
or Some [UseI18nOptions](composition#usei18noptions) are specified atuseI18n
, 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).You need to use
rt
for the locale message returned bytm
. see the [rt](composition#rt-message) details.Example 1
template block:
<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:
import { defineComponent } from 'vueimport { useI18n } from 'vue-i18n'export default defineComponent({setup() {const { rt, tm } = useI18n({messages: {en: {contents: [{title: 'Title1',// ...paragraphs: [// ...]}]}}// ...})// ...return { ... , rt, tm }}})
interface ComposerAdditionalOptions
interface ComposerAdditionalOptions {}
Composer additional options for
useI18n
Remarks
ComposerAdditionalOptions
is extend for ComposerOptions, so you can specify these options.[useI18n](composition#usei18n)
property useScope
useScope?: I18nScope;
interface ComposerCustom
interface ComposerCustom {}
The type custom definition of Composer
Remarks
The interface that can extend Composer.
The type defined by 3rd party (e.g. nuxt/i18n)
Example 1
// vue-i18n.d.ts (`.d.ts` file at your app)declare module 'vue-i18n' {interface ComposerCustom {localeCodes: string[]}}
interface ComposerDateTimeFormatting
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 ? C | M : C : IsNever<M> extends false ? M : never> {}
Datetime formatting functions
Remarks
This is the interface for Composer
call signature
(value: number | Date | string): string;
Datetime formatting
Parameter value
A value, timestamp number or
Date
instance or ISO 8601 stringReturns
Formatted value
[Datetime formatting](../guide/essentials/datetime)
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 atuseI18n
, 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.
call signature
<Value extends number | Date | string = number, Key extends string = string>( value: Value, keyOrOptions: | Key | ResourceKeys | DateTimeOptions<Key | ResourceKeys, Locales>): string;
Datetime formatting
Parameter value
A value, timestamp number or
Date
instance or ISO 8601 stringParameter keyOrOptions
A key of datetime formats, or additional options for datetime formatting
Returns
Formatted value
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.
call signature
<Value extends number | Date | string = number, Key extends string = string>( value: Value, keyOrOptions: | Key | ResourceKeys | DateTimeOptions<Key | ResourceKeys, Locales>, locale: Locales): string;
Datetime formatting
Parameter value
A value, timestamp number or
Date
instance or ISO 8601 stringParameter keyOrOptions
A key of datetime formats, or additional options for datetime formatting
Parameter locale
A locale, it will be used over than global scope or local scope.
Returns
Formatted value
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
interface ComposerNumberFormatting
interface ComposerNumberFormatting< NumberFormats extends Record<string, any> = {}, 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 functions
Remarks
This is the interface for Composer
call signature
(value: number): string;
Number Formatting
Parameter value
A number value
Returns
Formatted value
[Number formatting](../guide/essentials/number)
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 atuseI18n
, 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.
call signature
<Key extends string = string>( value: number, keyOrOptions: Key | ResourceKeys | NumberOptions<Key | ResourceKeys, Locales>): string;
Number Formatting
Parameter value
A number value
Parameter keyOrOptions
A key of number formats, or additional options for number formatting
Returns
Formatted value
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.
call signature
<Key extends string = string>( value: number, keyOrOptions: | Key | ResourceKeys | NumberOptions<Key | ResourceKeys, Locales>, locale: Locales): string;
Number Formatting
Parameter value
A number value
Parameter keyOrOptions
A key of number formats, or additional options for number formatting
Parameter locale
A locale, it will be used over than global scope or local scope.
Returns
Formatted value
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.
interface ComposerOptions
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>> {}
Composer Options
Remarks
This is options to create composer.
property datetimeFormats
datetimeFormats?: { [K in keyof _DateTimeFormats]: DateTimeSchema;};
Remarks
The datetime formats of localization.
[Datetime Formatting](../guide/essentials/datetime)
property escapeParameter
escapeParameter?: 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. 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.[HTML Message](../guide/essentials/syntax#html-message)
property fallbackFormat
fallbackFormat?: 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.[Fallbacking](../guide/essentials/fallback)
property fallbackLocale
fallbackLocale?: FallbackLocale;
Remarks
The locale of fallback localization.
For more complex fallback definitions see fallback.
[Fallbacking](../guide/essentials/fallback)
property fallbackRoot
fallbackRoot?: boolean;
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.[Fallbacking](../guide/essentials/fallback)
property fallbackWarn
fallbackWarn?: 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
).[Fallbacking](../guide/essentials/fallback)
property flatJson
flatJson?: boolean;
Remarks
Allow use flat json messages or not
property inheritLocale
inheritLocale?: boolean;
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.[Local Scope](../guide/essentials/scope#local-scope-2)
property locale
locale?: Locale;
Remarks
The locale of localization.
If the locale contains a territory and a dialect, this locale contains an implicit fallback.
[Scope and Locale Changing](../guide/essentials/scope)
property messageCompiler
messageCompiler?: MessageCompiler;
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 1
Here is an example of how to custom message compiler with
intl-messageformat
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 hereconst 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 optionconst i18n = createI18n({legacy: false,locale: 'ja',messageCompiler, // set your message compilermessages: {en: {hello: 'hello world!',greeting: 'hi, {name}!',// ICU Message formatphoto: `You have {numPhotos, plural,=0 {no photos.}=1 {one photo.}other {# photos.}}`},}})// the below your something to do ...// ...:new: v9.3+
The Custom Message Format is an experimental feature. It may receive breaking changes or be removed in the future.
[Custom Message Format](../guide/advanced/format)
property messageResolver
messageResolver?: MessageResolver;
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 1
Here is an example of how to set it up using your
createI18n
:import { createI18n } from 'vue-i18n'// your message resolverfunction messageResolver(obj, path) {// simple message resolving!const msg = obj[path]return msg != null ? msg : null}// call with I18n optionconst i18n = createI18n({legacy: false,locale: 'ja',messageResolver, // set your message resolvermessages: {en: { ... },ja: { ... }}})// the below your something to do ...// ...:new: v9.2+
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.[Fallbacking](../guide/essentials/fallback)
property messages
messages?: { [K in keyof _Messages]: MessageSchema;};
Remarks
The locale messages of localization.
[Getting Started](../guide/essentials/started)
property missing
missing?: MissingHandler;
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.
property missingWarn
missingWarn?: boolean | RegExp;
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
).[Fallbacking](../guide/essentials/fallback)
property modifiers
modifiers?: LinkedModifiers<VueMessageType>;
Remarks
Custom Modifiers for linked messages.
[Custom Modifiers](../guide/essentials/syntax#custom-modifiers)
property numberFormats
numberFormats?: { [K in keyof _NumberFormats]: NumberSchema;};
Remarks
The number formats of localization.
[Number Formatting](../guide/essentials/number)
property pluralRules
pluralRules?: PluralizationRules;
Remarks
A set of rules for word pluralization
[Custom Pluralization](../guide/essentials/pluralization#custom-pluralization)
property postTranslation
postTranslation?: PostTranslationHandler<VueMessageType>;
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.
property translateExistCompatible
translateExistCompatible?: boolean;
Remarks
An option to make
te
behavior specification before v9.6:new: v9.10+
This flag will be removed in v10.
[GitHub Issue](https://github.com/intlify/vue-i18n-next/issues/1738)
[
te
](composition#te-key-locale)
property warnHtmlMessage
warnHtmlMessage?: boolean;
Remarks
Whether to allow the use locale messages of HTML formatting.
See the warnHtmlMessage property.
[HTML Message](../guide/essentials/syntax#html-message) [Change
warnHtmlInMessage
option default value](../guide/migration/breaking#change-warnhtmlinmessage-option-default-value)
interface ComposerResolveLocaleMessageTranslation
interface ComposerResolveLocaleMessageTranslation<Locales = 'en-US'> {}
Resolve locale message translation functions
Remarks
This is the interface for Composer
call signature
(message: MessageFunction<VueMessageType> | VueMessageType): string;
Resolve locale message translation
Parameter message
A target locale message to be resolved. You will need to specify the locale message returned by
tm
.Returns
Translated message
[Scope and Locale Changing](../guide/essentials/scope)
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 atuseI18n
, 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.
The use-case for
rt
is for programmatic locale messages translation with usingtm
,v-for
, javascriptfor
statement.rt
differs fromt
in that it processes the locale message directly, not the key of the locale message. There is no internal fallback withrt
. You need to understand and use the structure of the locale messge returned bytm
.
call signature
( message: MessageFunction<VueMessageType> | VueMessageType, plural: number, options?: TranslateOptions<Locales>): string;
Resolve locale message translation for plurals
Parameter message
A target locale message to be resolved. You will need to specify the locale message returned by
tm
.Parameter plural
Which plural string to get. 1 returns the first one.
Parameter options
Additional options for translation
Returns
Translated message
[Pluralization](../guide/essentials/pluralization)
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.The use-case for
rt
is for programmatic locale messages translation with usingtm
,v-for
, javascriptfor
statement.rt
differs fromt
in that it processes the locale message directly, not the key of the locale message. There is no internal fallback withrt
. You need to understand and use the structure of the locale messge returned bytm
.
call signature
( message: MessageFunction<VueMessageType> | VueMessageType, list: unknown[], options?: TranslateOptions<Locales>): string;
Resolve locale message translation for list interpolations
Parameter message
A target locale message to be resolved. You will need to specify the locale message returned by
tm
.Parameter list
A values of list interpolation.
Parameter options
Additional options for translation
Returns
Translated message
[List interpolation](../guide/essentials/syntax#list-interpolation)
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.The use-case for
rt
is for programmatic locale messages translation with usingtm
,v-for
, javascriptfor
statement.rt
differs fromt
in that it processes the locale message directly, not the key of the locale message. There is no internal fallback withrt
. You need to understand and use the structure of the locale messge returned bytm
.
call signature
( message: MessageFunction<VueMessageType> | VueMessageType, named: NamedValue, options?: TranslateOptions<Locales>): string;
Resolve locale message translation for named interpolations
Parameter message
A target locale message to be resolved. You will need to specify the locale message returned by
tm
.Parameter named
A values of named interpolation.
Parameter options
Additional options for translation
Returns
Translated message
[Named interpolation](../guide/essentials/syntax#named-interpolation)
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.The use-case for
rt
is for programmatic locale messages translation with usingtm
,v-for
, javascriptfor
statement.rt
differs fromt
in that it processes the locale message directly, not the key of the locale message. There is no internal fallback withrt
. You need to understand and use the structure of the locale messge returned bytm
.
interface ComposerTranslation
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 functions
Remarks
This is the interface for Composer
call signature
<Key extends string>(key: Key | ResourceKeys | number): string;
Locale message translation
Parameter key
A target locale message key
Returns
Translated message
[Scope and Locale Changing](../guide/essentials/scope)
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 atuseI18n
, 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.
call signature
<Key extends string>( key: Key | ResourceKeys | number, plural: number, options?: TranslateOptions<Locales>): string;
Locale message translation for plurals
Parameter key
A target locale message key
Parameter plural
Which plural string to get. 1 returns the first one.
Parameter options
Additional options for translation
Returns
Translated message
[Pluralization](../guide/essentials/pluralization)
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 TranslateOptions.
call signature
<Key extends string>( key: Key | ResourceKeys | number, defaultMsg: string, options?: TranslateOptions<Locales>): string;
Locale message translation for missing default message
Parameter key
A target locale message key
Parameter defaultMsg
A default message to return if no translation was found
Parameter options
Additional options for translation
Returns
Translated 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 TranslateOptions.
call signature
<Key extends string>( key: Key | ResourceKeys | number, list: unknown[], options?: TranslateOptions<Locales>): string;
Locale message translation for list interpolations
Parameter key
A target locale message key
Parameter list
A values of list interpolation
Parameter options
Additional options for translation
Returns
Translated message
[List interpolation](../guide/essentials/syntax#list-interpolation)
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 TranslateOptions.
call signature
<Key extends string>( key: Key | ResourceKeys | number, list: unknown[], plural: number): string;
Locale message translation for list interpolations and plurals
Parameter key
A target locale message key
Parameter list
A values of list interpolation
Parameter plural
Which plural string to get. 1 returns the first one.
Returns
Translated message
[Pluralization](../guide/essentials/pluralization) [List interpolation](../guide/essentials/syntax#list-interpolation)
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.
call signature
<Key extends string>( key: Key | ResourceKeys | number, list: unknown[], defaultMsg: string): string;
Locale message translation for list interpolations and missing default message
Parameter key
A target locale message key
Parameter list
A values of list interpolation
Parameter defaultMsg
A default message to return if no translation was found
Returns
Translated message
[List interpolation](../guide/essentials/syntax#list-interpolation)
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.
call signature
<Key extends string>( key: Key | ResourceKeys | number, named: NamedValue, options?: TranslateOptions<Locales>): string;
Locale message translation for named interpolations
Parameter key
A target locale message key
Parameter named
A values of named interpolation
Parameter options
Additional options for translation
Returns
Translated message
[Named interpolation](../guide/essentials/syntax#named-interpolation)
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 TranslateOptions.
call signature
<Key extends string>( key: Key | ResourceKeys | number, named: NamedValue, plural: number): string;
Locale message translation for named interpolations and plurals
Parameter key
A target locale message key
Parameter named
A values of named interpolation
Parameter plural
Which plural string to get. 1 returns the first one.
Returns
Translated message
[Pluralization](../guide/essentials/pluralization) [Named interpolation](../guide/essentials/syntax#named-interpolation)
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.
call signature
<Key extends string>( key: Key | ResourceKeys | number, named: NamedValue, defaultMsg: string): string;
Locale message translation for named interpolations and plurals
Parameter key
A target locale message key
Parameter named
A values of named interpolation
Parameter defaultMsg
A default message to return if no translation was found
Returns
Translated message
[Named interpolation](../guide/essentials/syntax#named-interpolation)
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.
interface CustomBlock
interface CustomBlock<Message = VueMessageType> {}
interface DefineDateTimeFormat
interface DefineDateTimeFormat extends IntlDateTimeFormat {}
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 1
// 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}}}
interface DefineLocaleMessage
interface DefineLocaleMessage extends LocaleMessage<VueMessageType> {}
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 1
// type.d.ts (`.d.ts` file at your app)import { DefineLocaleMessage } from 'vue-i18n'declare module 'vue-i18n' {export interface DefineLocaleMessage {title: stringmenu: {login: string}}}
interface DefineNumberFormat
interface DefineNumberFormat extends IntlNumberFormat {}
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 1
// 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}}}
interface ExportedGlobalComposer
interface ExportedGlobalComposer {}
Exported global composer instance
Remarks
This interface is the [global composer](general#global) that is provided interface that is injected into each component with
app.config.globalProperties
.
property availableLocales
readonly availableLocales: Locale[];
Available locales
Remarks
This property is proxy-like property for
Composer#availableLocales
. About details, see the [Composer#availableLocales](composition#availablelocales)
property fallbackLocale
fallbackLocale: FallbackLocale;
Fallback locale
Remarks
This property is proxy-like property for
Composer#fallbackLocale
. About details, see the [Composer#fallbackLocale](composition#fallbacklocale)
property locale
locale: Locale;
Locale
Remarks
This property is proxy-like property for
Composer#locale
. About details, see the [Composer#locale](composition#locale)
interface FormattableProps
interface FormattableProps<Value, Format> extends BaseFormatProps {}
Formattable Props
Remarks
The props used in DatetimeFormat, or NumberFormat component
interface Formatter
interface Formatter {}
method interpolate
interpolate: (message: string, values: any, path: string) => Array<any> | null;
interface I18n
interface I18n< Messages extends Record<string, unknown> = {}, DateTimeFormats extends Record<string, unknown> = {}, NumberFormats extends Record<string, unknown> = {}, OptionLocale = Locale, Legacy = boolean> {}
I18n instance
Remarks
The instance required for installation as the Vue plugin
property allowComposition
readonly allowComposition: boolean;
The property whether or not the Composition API is available
Remarks
If you specified
allowComposition: true
option in Legacy API mode, returntrue
, elsefalse
. else you use the Composition API mode, this property will always returntrue
.
property global
readonly global: Legacy extends true ? VueI18n<Messages, DateTimeFormats, NumberFormats, OptionLocale> : Legacy extends false ? Composer<Messages, DateTimeFormats, NumberFormats, OptionLocale> : unknown;
The property accessible to the global Composer instance or VueI18n instance
Remarks
If the [I18n#mode](general#mode) is
'legacy'
, then you can access to a global VueI18n instance, else then [I18n#mode](general#mode) is'composition'
, you can access to the global Composer instance.An instance of this property is **global scope***.
property mode
readonly mode: I18nMode;
Vue I18n API mode
Remarks
If you specified
legacy: true
option increateI18n
, returnlegacy
, elsecomposition
method dispose
dispose: () => void;
Release global scope resource
method install
install: (app: App, ...options: unknown[]) => void;
Install entry point
Parameter app
A target Vue app instance
Parameter options
An install options
interface I18nAdditionalOptions
interface I18nAdditionalOptions {}
I18n Additional Options
Remarks
Specific options for createI18n
property allowComposition
allowComposition?: boolean;
Whether to allow the Composition API to be used in Legacy API mode.
Remarks
If this option is enabled, you can use useI18n in Legacy API mode. This option is supported to support the migration from Legacy API mode to Composition API mode.
Note that the Composition API made available with this option doesn't work on SSR. [Composition API](../guide/advanced/composition)
property globalInjection
globalInjection?: boolean;
Whether to inject global properties & functions into for each component.
Remarks
If set to
true
, then properties and methods prefixed with$
are injected into Vue Component.[Implicit with injected properties and functions](../guide/advanced/composition#implicit-with-injected-properties-and-functions) [ComponentCustomProperties](injection#componentcustomproperties)
property legacy
legacy?: boolean;
Whether vue-i18n Legacy API mode use on your Vue App
Remarks
The default is to use the Legacy API mode. If you want to use the Composition API mode, you need to set it to
false
.[Composition API](../guide/advanced/composition)
interface I18nPluginOptions
interface I18nPluginOptions {}
Vue I18n plugin options
Remarks
An options specified when installing Vue I18n as Vue plugin with using
app.use
.
property globalInstall
globalInstall?: boolean;
Whether to globally install the components that is offered by Vue I18n
Remarks
If this option is enabled, the components will be installed globally at
app.use
time.If you want to install manually in the
import
syntax, you can set it tofalse
to install when needed.
property useI18nComponentName
useI18nComponentName?: boolean;
Whether to use the tag name
i18n
for Translation ComponentRemarks
This option is used for compatibility with Vue I18n v8.x.
If you can't migrate right away, you can temporarily enable this option, and you can work Translation Component.
interface TranslationProps
interface TranslationProps extends BaseFormatProps {}
Translation Component Props
interface VueI18n
interface VueI18n< Messages extends Record<string, any> = {}, DateTimeFormats extends Record<string, any> = {}, NumberFormats extends Record<string, any> = {}, OptionLocale = Locale, ResourceLocales = | PickupLocales<NonNullable<Messages>> | PickupLocales<NonNullable<DateTimeFormats>> | PickupLocales<NonNullable<NumberFormats>>, Locales = OptionLocale extends string ? [ResourceLocales] extends [never] ? Locale : ResourceLocales : OptionLocale | ResourceLocales, Composition extends Composer< Messages, DateTimeFormats, NumberFormats, OptionLocale > = Composer<Messages, DateTimeFormats, NumberFormats, OptionLocale>> {}
VueI18n legacy interfaces
Remarks
This interface is compatible with interface of
VueI18n
class (offered with Vue I18n v8.x).
property availableLocales
readonly availableLocales: Composition['availableLocales'];
Remarks
The list of available locales in
messages
in lexical order.
property d
d: VueI18nDateTimeFormatting< DateTimeFormats, Locales, RemoveIndexSignature<{ [K in keyof DefineDateTimeFormat]: DefineDateTimeFormat[K]; }>>;
Datetime formatting
Remarks
About details functions, See the VueI18nDateTimeFormatting
property datetimeFormats
readonly datetimeFormats: { [K in keyof DateTimeFormats]: DateTimeFormats[K];};
Remarks
The datetime formats of localization.
[Datetime Formatting](../guide/essentials/datetime)
property escapeParameterHtml
escapeParameterHtml: Composition['escapeParameter'];
Remarks
Whether interpolation parameters are escaped before the message is translated.
[HTML Message](../guide/essentials/syntax#html-message)
property fallbackLocale
fallbackLocale: FallbackLocales<Locales>;
Remarks
The current fallback locales this VueI18n instance is using.
[Fallbacking](../guide/essentials/fallback)
property formatFallbackMessages
formatFallbackMessages: Composition['fallbackFormat'];
Remarks
Whether suppress warnings when falling back to either
fallbackLocale
or root.[Fallbacking](../guide/essentials/fallback)
property formatter
formatter: Formatter;
Remarks
The formatter that implemented with Formatter interface.
Deprecated
See the [here](../guide/migration/breaking#remove-custom-formatter)
property getChoiceIndex
getChoiceIndex: (choice: Choice, choicesLength: number) => number;
Get choice index
Remarks
Get pluralization index for current pluralizing number and a given amount of choices.
Deprecated
Use
pluralizationRules
option instead ofgetChoiceIndex
.
property getDateTimeFormat
getDateTimeFormat: Composition['getDateTimeFormat'];
Get datetime format
Parameter locale
A target locale
Returns
Datetime format
Remarks
get datetime format from VueI18n instance [datetimeFormats](legacy#datetimeformats).
property getLocaleMessage
getLocaleMessage: Composition['getLocaleMessage'];
Get locale message
Parameter locale
A target locale
Returns
Locale messages
Remarks
get locale message from VueI18n instance [messages](legacy#messages).
property getNumberFormat
getNumberFormat: Composition['getNumberFormat'];
Get number format
Parameter locale
A target locale
Returns
Number format
Remarks
get number format from VueI18n instance [numberFormats](legacy#numberFormats).
property id
id: number;
Remarks
Instance ID.
property locale
locale: Locales;
Remarks
The current locale this VueI18n instance is using.
If the locale contains a territory and a dialect, this locale contains an implicit fallback.
[Scope and Locale Changing](../guide/essentials/scope)
property mergeDateTimeFormat
mergeDateTimeFormat: Composition['mergeDateTimeFormat'];
Merge datetime format
Parameter locale
A target locale
Parameter format
A target datetime format
Remarks
Merge datetime format to VueI18n instance [datetimeFormats](legacy#datetimeformats).
property mergeLocaleMessage
mergeLocaleMessage: Composition['mergeLocaleMessage'];
Merge locale message
Parameter locale
A target locale
Parameter message
A message
Remarks
Merge locale message to VueI18n instance [messages](legacy#messages).
property mergeNumberFormat
mergeNumberFormat: Composition['mergeNumberFormat'];
Merge number format
Parameter locale
A target locale
Parameter format
A target number format
Remarks
Merge number format to VueI18n instance [numberFormats](legacy#numberFormats).
property messages
readonly messages: { [K in keyof Messages]: Messages[K];};
Remarks
The locale messages of localization.
[Getting Started](../guide/essentials/started)
property missing
missing: MissingHandler | null;
Remarks
A handler for localization missing.
property modifiers
readonly modifiers: Composition['modifiers'];
Remarks
Custom Modifiers for linked messages.
[Custom Modifiers](../guide/essentials/syntax#custom-modifiers)
property n
n: VueI18nNumberFormatting< NumberFormats, Locales, RemoveIndexSignature<{ [K in keyof DefineNumberFormat]: DefineNumberFormat[K]; }>>;
Number Formatting
Remarks
About details functions, See the VueI18nNumberFormatting
property numberFormats
readonly numberFormats: { [K in keyof NumberFormats]: NumberFormats[K];};
Remarks
The number formats of localization.
[Number Formatting](../guide/essentials/number)
property pluralizationRules
pluralizationRules: Composition['pluralRules'];
A set of rules for word pluralization
[Custom Pluralization](../guide/essentials/pluralization#custom-pluralization)
property postTranslation
postTranslation: PostTranslationHandler<VueMessageType> | null;
Remarks
A handler for post processing of translation.
property preserveDirectiveContent
preserveDirectiveContent: boolean;
Remarks
Whether
v-t
directive's element should preservetextContent
after directive is unbinded.[Custom Directive](../guide/advanced/directive) [Remove preserveDirectiveContent option](../guide/migration/breaking#remove-preservedirectivecontent-option)
Deprecated
The
v-t
directive for Vue 3 now preserves the default content. Therefore, this option and its properties have been removed from the VueI18n instance.
property rt
rt: VueI18nResolveLocaleMessageTranslation<Locales>;
Resolve locale message translation
Remarks
About details functions, See the VueI18nResolveLocaleMessageTranslation
property setDateTimeFormat
setDateTimeFormat: Composition['setDateTimeFormat'];
Set datetime format
Parameter locale
A target locale
Parameter format
A target datetime format
Remarks
Set datetime format to VueI18n instance [datetimeFormats](legacy#datetimeformats).
property setLocaleMessage
setLocaleMessage: Composition['setLocaleMessage'];
Set locale message
Parameter locale
A target locale
Parameter message
A message
Remarks
Set locale message to VueI18n instance [messages](legacy#messages).
property setNumberFormat
setNumberFormat: Composition['setNumberFormat'];
Set number format
Parameter locale
A target locale
Parameter format
A target number format
Remarks
Set number format to VueI18n instance [numberFormats](legacy#numberFormats).
property silentFallbackWarn
silentFallbackWarn: Composition['fallbackWarn'];
Remarks
Whether suppress fallback warnings when localization fails.
property silentTranslationWarn
silentTranslationWarn: Composition['missingWarn'];
Remarks
Whether suppress warnings outputted when localization fails.
[Fallbacking](../guide/essentials/fallback)
property sync
sync: Composition['inheritLocale'];
Remarks
Whether synchronize the root level locale to the component localization locale.
[Local Scope](../guide/essentials/scope#local-scope-2)
property t
t: VueI18nTranslation< Messages, Locales, RemoveIndexSignature<{ [K in keyof DefineLocaleMessage]: DefineLocaleMessage[K]; }>>;
Locale message translation
Remarks
About details functions, See the VueI18nTranslation
property tc
tc: VueI18nTranslationChoice< Messages, Locales, RemoveIndexSignature<{ [K in keyof DefineLocaleMessage]: DefineLocaleMessage[K]; }>>;
Locale message pluralization
Remarks
About details functions, See the VueI18nTranslationChoice
property tm
tm: Composition['tm'];
Locale messages getter
Parameter key
A target locale message key
Locale messages
Remarks
If [i18n component options](injection#i18n) is specified, it’s get in preferentially local scope locale messages than global scope locale messages.
If [i18n component options](injection#i18n) isn't specified, it’s get with 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).You need to use
rt
for the locale message returned bytm
. see the [rt](legacy#rt-message) details.Example 1
template:
<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>import { createI18n } from 'vue-i18n'const i18n = createI18n({messages: {en: {contents: [{title: 'Title1',// ...paragraphs: [// ...]}]}}// ...})
property warnHtmlInMessage
warnHtmlInMessage: WarnHtmlInMessageLevel;
Remarks
Whether to allow the use locale messages of HTML formatting.
If you set
warn
orerror
, will check the locale messages on the VueI18n instance.If you are specified
warn
, a warning will be output at console.If you are specified
error
will occurred an Error.[HTML Message](../guide/essentials/syntax#html-message) [Change
warnHtmlInMessage
option default value](../guide/migration/breaking#change-warnhtmlinmessage-option-default-value)
method te
te: < Str extends string, Key extends PickupKeys<Messages> = PickupKeys<Messages>>( key: Str | Key, locale?: Locales) => boolean;
Translation locale message exist
Parameter key
A target locale message key
Parameter locale
A target locale
Returns
If found locale message,
true
, elsefalse
Remarks
whether do exist locale message on VueI18n instance [messages](legacy#messages).
If you specified
locale
, check the locale messages oflocale
.
interface VueI18nDateTimeFormatting
interface VueI18nDateTimeFormatting< 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 ? C | M : C : IsNever<M> extends false ? M : never> {}
Datetime formatting functions for VueI18n legacy interfaces
Remarks
This is the interface for VueI18n
call signature
(value: number | Date): DateTimeFormatResult;
Datetime formatting
Parameter value
A value, timestamp number or
Date
instanceReturns
Formatted value
[Datetime formatting](../guide/essentials/datetime)
Remarks
If this is used in a reactive context, it will re-evaluate once the locale changes.
If [i18n component options](injection#i18n) is specified, it’s formatted in preferentially local scope datetime formats than global scope locale messages.
If [i18n component options](injection#i18n) isn't specified, it’s formatted with global scope datetime formats.
call signature
<Value extends number | Date = number, Key extends string = string>( value: Value, key: Key | ResourceKeys): DateTimeFormatResult;
Datetime formatting
Parameter value
A value, timestamp number or
Date
instanceParameter key
A key of datetime formats
Returns
Formatted value
Remarks
Overloaded
d
. About details, see the [call signature](legacy#value-number-date-datetimeformatresult) details.
call signature
<Value extends number | Date = number, Key extends string = string>( value: Value, key: Key | ResourceKeys, locale: Locales): DateTimeFormatResult;
Datetime formatting
Parameter value
A value, timestamp number or
Date
instanceParameter key
A key of datetime formats
Parameter locale
A locale, it will be used over than global scope or local scope.
Returns
Formatted value
Remarks
Overloaded
d
. About details, see the [call signature](legacy#value-number-date-datetimeformatresult) details.
call signature
( value: number | Date, args: { [key: string]: string | boolean | number; }): DateTimeFormatResult;
Datetime formatting
Parameter value
A value, timestamp number or
Date
instanceParameter args
An argument values
Returns
Formatted value
Remarks
Overloaded
d
. About details, see the [call signature](legacy#value-number-date-datetimeformatresult) details.
interface VueI18nNumberFormatting
interface VueI18nNumberFormatting< NumberFormats extends Record<string, any> = {}, 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 functions for VueI18n legacy interfaces
Remarks
This is the interface for VueI18n
call signature
(value: number): NumberFormatResult;
Number formatting
Parameter value
A number value
Returns
Formatted value
[Number formatting](../guide/essentials/number)
Remarks
If this is used in a reactive context, it will re-evaluate once the locale changes.
If [i18n component options](injection#i18n) is specified, it’s formatted in preferentially local scope number formats than global scope locale messages.
If [i18n component options](injection#i18n) isn't specified, it’s formatted with global scope number formats.
call signature
<Key extends string = string>( value: number, key: Key | ResourceKeys): NumberFormatResult;
Number formatting
Parameter value
A number value
Parameter key
A key of number formats
Returns
Formatted value
Remarks
Overloaded
n
. About details, see the [call signature](legacy#value-number-numberformatresult) details.
call signature
<Key extends string = string>( value: number, key: Key | ResourceKeys, locale: Locales): NumberFormatResult;
Number formatting
Parameter value
A number value
Parameter key
A key of number formats
Parameter locale
A locale, it will be used over than global scope or local scope.
Returns
Formatted value
Remarks
Overloaded
n
. About details, see the [call signature](legacy#value-number-numberformatresult) details.
call signature
( value: number, args: { [key: string]: string | boolean | number; }): NumberFormatResult;
Number formatting
Parameter value
A number value
Parameter args
An argument values
Returns
Formatted value
Remarks
Overloaded
n
. About details, see the [call signature](legacy#value-number-numberformatresult) details.
interface VueI18nOptions
interface VueI18nOptions< Schema extends { message?: unknown; datetime?: unknown; number?: unknown; } = { message: DefaultLocaleMessageSchema; datetime: DefaultDateTimeFormatSchema; number: DefaultNumberFormatSchema; }, Locales extends | { messages: unknown; datetimeFormats: unknown; numberFormats: unknown; } | string = Locale, Options extends ComposerOptions<Schema, Locales> = ComposerOptions< Schema, Locales >> {}
VueI18n Options
Remarks
This option is compatible with
VueI18n
class constructor options (offered with Vue I18n v8.x)
property availableLocales
availableLocales?: Locale[];
Remarks
The list of available locales in messages in lexical order.
property datetimeFormats
datetimeFormats?: Options['datetimeFormats'];
Remarks
The datetime formats of localization.
[Datetime Formatting](../guide/essentials/datetime)
property escapeParameterHtml
escapeParameterHtml?: Options['escapeParameter'];
Remarks
If
escapeParameterHtml
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. 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
escapeParameterHtml
as true should not break existing functionality but provides a safeguard against a subtle type of XSS attack vectors.[HTML Message](../guide/essentials/syntax#html-message)
property fallbackLocale
fallbackLocale?: Options['fallbackLocale'];
Remarks
The locale of fallback localization.
For more complex fallback definitions see fallback.
[Fallbacking](../guide/essentials/fallback)
property fallbackRoot
fallbackRoot?: Options['fallbackRoot'];
Remarks
In the component localization, whether to fall back to root level (global scope) localization when localization fails.
If
false
, it's not fallback to root.[Fallbacking](../guide/essentials/fallback)
property flatJson
flatJson?: Options['flatJson'];
Remarks
Allow use flat json messages or not
property formatFallbackMessages
formatFallbackMessages?: Options['fallbackFormat'];
Remarks
Whether suppress warnings when falling back to either
fallbackLocale
or root.[Fallbacking](../guide/essentials/fallback)
property formatter
formatter?: Formatter;
Remarks
The formatter that implemented with Formatter interface.
Deprecated
See the [here](../guide/migration/breaking#remove-custom-formatter)
property locale
locale?: Options['locale'];
Remarks
The locale of localization.
If the locale contains a territory and a dialect, this locale contains an implicit fallback.
[Scope and Locale Changing](../guide/essentials/scope)
property messageResolver
messageResolver?: MessageResolver;
Remarks
A message resolver to resolve [
messages
](legacy#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
](legacy#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
](legacy#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
](legacy#t-key)- [
tc
](legacy#tc-key)- [
te
](legacy#te-key-locale)- [
tm
](legacy#tm-key)- [Translation component](component#translation)
Example 1
Here is an example of how to set it up using your
createI18n
:import { createI18n } from 'vue-i18n'// your message resolverfunction messageResolver(obj, path) {// simple message resolving!const msg = obj[path]return msg != null ? msg : null}// call with I18n optionconst i18n = createI18n({locale: 'ja',messageResolver, // set your message resolvermessages: {en: { ... },ja: { ... }}})// the below your something to do ...// ...:new: v9.2+
If you use the message resolver, the [
flatJson
](legacy#flatjson) setting will be ignored. That is, you need to resolve the flat JSON by yourself.[Fallbacking](../guide/essentials/fallback)
property messages
messages?: Options['messages'];
Remarks
The locale messages of localization.
[Getting Started](../guide/essentials/started)
property missing
missing?: Options['missing'];
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.
property modifiers
modifiers?: Options['modifiers'];
Remarks
Custom Modifiers for linked messages.
[Custom Modifiers](../guide/essentials/syntax#custom-modifiers)
property numberFormats
numberFormats?: Options['numberFormats'];
Remarks
The number formats of localization.
[Number Formatting](../guide/essentials/number)
property pluralizationRules
pluralizationRules?: Options['pluralRules'];
Remarks
A set of rules for word pluralization
[Custom Pluralization](../guide/essentials/pluralization#custom-pluralization)
property postTranslation
postTranslation?: Options['postTranslation'];
Remarks
A handler for post processing of translation. The handler gets after being called with the
$t
,t
,$tc
, andtc
.This handler is useful if you want to filter on translated text such as space trimming.
property preserveDirectiveContent
preserveDirectiveContent?: boolean;
Remarks
Whether
v-t
directive's element should preservetextContent
after directive is unbinded.[Custom Directive](../guide/advanced/directive) [Remove
preserveDirectiveContent
option](../guide/migration/breaking#remove-preservedirectivecontent-option)Deprecated
The
v-t
directive for Vue 3 now preserves the default content. Therefore, this option and its properties have been removed from the VueI18n instance.
property sharedMessages
sharedMessages?: LocaleMessages<VueMessageType>;
Remarks
The shared locale messages of localization for components. More detail see Component based localization.
[Shared locale messages for components](../guide/essentials/local#shared-locale-messages-for-components)
property silentFallbackWarn
silentFallbackWarn?: Options['fallbackWarn'];
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.[Fallbacking](../guide/essentials/fallback)
property silentTranslationWarn
silentTranslationWarn?: Options['missingWarn'];
Remarks
Whether suppress warnings outputted when localization fails.
If
true
, suppress localization fail warnings.If you use regular expression, you can suppress localization fail warnings that it match with translation key (e.g.
t
).[Fallbacking](../guide/essentials/fallback)
property sync
sync?: boolean;
Remarks
Whether synchronize the root level locale to the component localization locale.
If
false
, regardless of the root level locale, localize for each component locale.[Local Scope](../guide/essentials/scope#local-scope-2)
property warnHtmlInMessage
warnHtmlInMessage?: WarnHtmlInMessageLevel;
Remarks
Whether to allow the use locale messages of HTML formatting.
See the warnHtmlInMessage property.
[HTML Message](../guide/essentials/syntax#html-message) [Change
warnHtmlInMessage
option default value](../guide/migration/breaking#change-warnhtmlinmessage-option-default-value)
interface VueI18nTranslation
interface VueI18nTranslation< 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 functions for VueI18n legacy interfaces
Remarks
This is the interface for VueI18n
call signature
<Key extends string>(key: Key | ResourceKeys): TranslateResult;
Locale message translation.
Parameter key
A target locale message key
Returns
Translated message
[Scope and Locale Changing](../guide/essentials/scope)
Remarks
If this is used in a reactive context, it will re-evaluate once the locale changes.
If [i18n component options](injection#i18n) is specified, it’s translated in preferentially local scope locale messages than global scope locale messages.
If [i18n component options](injection#i18n) isn't specified, it’s translated with global scope locale messages.
call signature
<Key extends string>( key: Key | ResourceKeys, locale: Locales | Locale): TranslateResult;
Locale message translation.
Parameter key
A target locale message key
Parameter locale
A locale, it will be used over than global scope or local scope.
Returns
Translated message
Remarks
Overloaded
t
. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details.
call signature
<Key extends string>( key: Key | ResourceKeys, locale: Locales | Locale, list: unknown[]): TranslateResult;
Locale message translation.
Parameter key
A target locale message key
Parameter locale
A locale, it will be used over than global scope or local scope.
Parameter list
A values of list interpolation
Returns
Translated message
[List interpolation](../guide/essentials/syntax#list-interpolation)
Remarks
Overloaded
t
. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details.
call signature
<Key extends string>( key: Key | ResourceKeys, locale: Locales | Locale, named: Record<string, unknown>): TranslateResult;
Locale message translation.
Parameter key
A target locale message key
Parameter locale
A locale, it will be used over than global scope or local scope.
Parameter named
A values of named interpolation
Returns
Translated message
[Named interpolation](../guide/essentials/syntax#named-interpolation)
Remarks
Overloaded
t
. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details.
call signature
<Key extends string>(key: Key | ResourceKeys, list: unknown[]): TranslateResult;
Locale message translation.
Parameter key
A target locale message key
Parameter list
A values of list interpolation
Returns
Translated message
[List interpolation](../guide/essentials/syntax#list-interpolation)
Remarks
Overloaded
t
. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details.
call signature
<Key extends string>( key: Key | ResourceKeys, named: Record<string, unknown>): TranslateResult;
Locale message translation.
Parameter key
A target locale message key
Parameter named
A values of named interpolation
Returns
Translated message
[Named interpolation](../guide/essentials/syntax#named-interpolation)
Remarks
Overloaded
t
. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details.
interface VueI18nTranslationChoice
interface VueI18nTranslationChoice< 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 pluralization functions for VueI18n legacy interfaces
Remarks
This is the interface for VueI18n
call signature
<Key extends string = string>(key: Key | ResourceKeys): TranslateResult;
Locale message pluralization
Parameter key
A target locale message key
Returns
Pluraled message
[Pluralization](../guide/essentials/pluralization)
Remarks
If this is used in a reactive context, it will re-evaluate once the locale changes.
If [i18n component options](injection#i18n) is specified, it’s pluraled in preferentially local scope locale messages than global scope locale messages.
If [i18n component options](injection#i18n) isn't specified, it’s pluraled with global scope locale messages.
The plural choice number is handled with default
1
.
call signature
<Key extends string = string>( key: Key | ResourceKeys, locale: Locales | Locale): TranslateResult;
Locale message pluralization
Parameter key
A target locale message key
Parameter locale
A locale, it will be used over than global scope or local scope.
Returns
Pluraled message
Remarks
Overloaded
tc
. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult-2) details.
call signature
<Key extends string>(key: Key | ResourceKeys, list: unknown[]): TranslateResult;
Locale message pluralization
Parameter key
A target locale message key
Parameter list
A values of list interpolation
Returns
Pluraled message
Remarks
Overloaded
tc
. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult-2) details.
call signature
<Key extends string>( key: Key | ResourceKeys, named: Record<string, unknown>): TranslateResult;
Locale message pluralization
Parameter key
A target locale message key
Parameter named
A values of named interpolation
Returns
Pluraled message
Remarks
Overloaded
tc
. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult-2) details.
call signature
<Key extends string>(key: Key | ResourceKeys, choice: number): TranslateResult;
Locale message pluralization
Parameter key
A target locale message key
Parameter choice
Which plural string to get. 1 returns the first one.
Returns
Pluraled message
Remarks
Overloaded
tc
. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult-2) details.
call signature
<Key extends string>( key: Key | ResourceKeys, choice: number, locale: Locales | Locale): TranslateResult;
Locale message pluralization
Parameter key
A target locale message key
Parameter choice
Which plural string to get. 1 returns the first one.
Parameter locale
A locale, it will be used over than global scope or local scope.
Returns
Pluraled message
Remarks
Overloaded
tc
. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult-2) details.
call signature
<Key extends string>( key: Key | ResourceKeys, choice: number, list: unknown[]): TranslateResult;
Locale message pluralization
Parameter key
A target locale message key
Parameter choice
Which plural string to get. 1 returns the first one.
Parameter list
A values of list interpolation
Returns
Pluraled message
Remarks
Overloaded
tc
. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult-2) details.
call signature
<Key extends string>( key: Key | ResourceKeys, choice: number, named: Record<string, unknown>): TranslateResult;
Locale message pluralization
Parameter key
A target locale message key
Parameter choice
Which plural string to get. 1 returns the first one.
Parameter named
A values of named interpolation
Returns
Pluraled message
Remarks
Overloaded
tc
. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult-2) details.
Type Aliases
type Choice
type Choice = number;
type ComponentI18nScope
type ComponentI18nScope = Exclude<I18nScope, 'local'>;
type ComposerExtender
type ComposerExtender = (composer: Composer) => Disposer | undefined;
type CustomBlocks
type CustomBlocks<Message = VueMessageType> = Array<CustomBlock<Message>>;
type DatetimeFormatProps
type DatetimeFormatProps = FormattableProps< number | Date, Intl.DateTimeFormatOptions>;
DatetimeFormat Component Props
type DateTimeFormatResult
type DateTimeFormatResult = string;
type DefaultDateTimeFormatSchema
type DefaultDateTimeFormatSchema< Schema = RemoveIndexSignature<{ [K in keyof DefineDateTimeFormat]: DefineDateTimeFormat[K]; }>> = IsEmptyObject<Schema> extends true ? IntlDateTimeFormat : Schema;
type DefaultLocaleMessageSchema
type DefaultLocaleMessageSchema< Schema = RemoveIndexSignature<{ [K in keyof DefineLocaleMessage]: DefineLocaleMessage[K]; }>> = IsEmptyObject<Schema> extends true ? LocaleMessage<VueMessageType> : Schema;
type DefaultNumberFormatSchema
type DefaultNumberFormatSchema< Schema = RemoveIndexSignature<{ [K in keyof DefineNumberFormat]: DefineNumberFormat[K]; }>> = IsEmptyObject<Schema> extends true ? IntlNumberFormat : Schema;
type Disposer
type Disposer = () => void;
type I18nMode
type I18nMode = 'legacy' | 'composition';
Vue I18n API mode
[I18n#mode](general#mode)
type I18nOptions
type I18nOptions< Schema extends { message?: unknown; datetime?: unknown; number?: unknown; } = { message: DefaultLocaleMessageSchema; datetime: DefaultDateTimeFormatSchema; number: DefaultNumberFormatSchema; }, Locales extends | { messages: unknown; datetimeFormats: unknown; numberFormats: unknown; } | string = Locale, Options extends | ComposerOptions<Schema, Locales> | VueI18nOptions<Schema, Locales> = | ComposerOptions<Schema, Locales> | VueI18nOptions<Schema, Locales>> = I18nAdditionalOptions & Options;
I18n Options for
createI18n
Remarks
I18nOptions
is inherited I18nAdditionalOptions, ComposerOptions and VueI18nOptions, so you can specify these options.
type I18nScope
type I18nScope = 'local' | 'parent' | 'global';
I18n Scope
[ComposerAdditionalOptions#useScope](composition#usescope) [useI18n](composition#usei18n)
type LocaleMessageObject
type LocaleMessageObject<Message = string> = LocaleMessageDictionary<Message>;
type MissingHandler
type MissingHandler = ( locale: Locale, key: Path, instance?: ComponentInternalInstance, type?: string) => string | void;
type NumberFormatProps
type NumberFormatProps = FormattableProps<number, Intl.NumberFormatOptions>;
NumberFormat Component Props
type NumberFormatResult
type NumberFormatResult = string;
type PluralizationRulesMap
type PluralizationRulesMap = { [locale: string]: PluralizationRule;};
type TranslateResult
type TranslateResult = string;
type TranslationDirective
type TranslationDirective<T = HTMLElement> = ObjectDirective<T>;
Translation Directive (
v-t
)Remarks
Update the element
textContent
that localized with locale messages.You can use string syntax or object syntax.
String syntax can be specified as a keypath of locale messages.
If you can be used object syntax, you need to specify as the object key the following params
- path: required, key of locale messages- locale: optional, locale- args: optional, for list or named formattingExample 1
<!-- string syntax: literal --><p v-t="'foo.bar'"></p><!-- string syntax: binding via data or computed props --><p v-t="msg"></p><!-- object syntax: literal --><p v-t="{ path: 'hi', locale: 'ja', args: { name: 'kazupon' } }"></p><!-- object syntax: binding via data or computed props --><p v-t="{ path: greeting, args: { name: fullName } }"></p>
type UseI18nOptions
type UseI18nOptions< Schema extends { message?: unknown; datetime?: unknown; number?: unknown; } = { message: DefaultLocaleMessageSchema; datetime: DefaultDateTimeFormatSchema; number: DefaultNumberFormatSchema; }, Locales extends | { messages: unknown; datetimeFormats: unknown; numberFormats: unknown; } | string = Locale, Options extends ComposerOptions<Schema, Locales> = ComposerOptions< Schema, Locales >> = ComposerAdditionalOptions & Options;
I18n Options for
useI18n
Remarks
UseI18nOptions
is inherited ComposerAdditionalOptions and ComposerOptions, so you can specify these options.[useI18n](composition#usei18n)
type VTDirectiveValue
type VTDirectiveValue = { path: string; locale?: Locale; args?: NamedValue; choice?: number; plural?: number;};
type VueI18nExtender
type VueI18nExtender = (vueI18n: VueI18n) => Disposer | undefined;
type VueI18nResolveLocaleMessageTranslation
type VueI18nResolveLocaleMessageTranslation<Locales = 'en-US'> = ComposerResolveLocaleMessageTranslation<Locales>;
Resolve locale message translation functions for VueI18n legacy interfaces
Remarks
This is the interface for VueI18n. This interface is an alias of ComposerResolveLocaleMessageTranslation.
type VueMessageType
type VueMessageType = string | ResourceNode | VNode;
type WarnHtmlInMessageLevel
type WarnHtmlInMessageLevel = 'off' | 'warn' | 'error';
Package Files (1)
Dependencies (3)
Dev Dependencies (2)
Peer Dependencies (1)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/vue-i18n
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/vue-i18n)
- HTML<a href="https://www.jsdocs.io/package/vue-i18n"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 7144 ms. - Missing or incorrect documentation? Open an issue for this package.