Composition API

Composer

Composer interfaces

Signature:

export interface Composer<Messages = {}, DateTimeFormats = {}, NumberFormats = {}, Message = VueMessageType> 

Details

This is the interface for being used for Vue 3 Composition API.

availableLocales

Signature:

readonly availableLocales: Locale[];

Details

The list of available locales in messages in lexical order.

datetimeFormats

Signature:

readonly datetimeFormats: ComputedRef<DateTimeFormats>;

Details

The datetime formats of localization.

See Also

escapeParameter

Signature:

escapeParameter: boolean;

Details

Whether interpolation parameters are escaped before the message is translated.

See Also

fallbackFormat

Signature:

fallbackFormat: boolean;

Details

Whether suppress warnings when falling back to either fallbackLocale or root.

See Also

fallbackLocale

Signature:

fallbackLocale: WritableComputedRef<FallbackLocale>;

Details

The current fallback locales this Composer instance is using.

See Also

fallbackRoot

Signature:

fallbackRoot: boolean;

Details

Whether to fall back to root level (global scope) localization when localization fails.

See Also

fallbackWarn

Signature:

fallbackWarn: boolean | RegExp;

Details

Whether suppress fall back warnings when localization fails.

See Also

id

Signature:

id: number;

Details

Instance ID.

inheritLocale

Signature:

inheritLocale: boolean;

Details

Whether inherit the root level locale to the component localization locale.

See Also

isGlobal

Signature:

readonly isGlobal: boolean;

Details

Whether this composer instance is global or not

locale

Signature:

locale: WritableComputedRef<Locale>;

Details

The current locale this Composer instance is using.

If the locale contains a territory and a dialect, this locale contains an implicit fallback.

See Also

messages

Signature:

readonly messages: ComputedRef<Messages>;

Details

The locale messages of localization.

See Also

missingWarn

Signature:

missingWarn: boolean | RegExp;

Details

Whether suppress warnings outputted when localization fails.

See Also

modifiers

Signature:

readonly modifiers: LinkedModifiers<Message>;

Details

Custom Modifiers for linked messages.

See Also

numberFormats

Signature:

readonly numberFormats: ComputedRef<NumberFormats>;

Details

The number formats of localization.

See Also

pluralRules

Signature:

readonly pluralRules: PluralizationRules;

Details

A set of rules for word pluralization

See Also

warnHtmlMessage

Signature:

warnHtmlMessage: boolean;

Details

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.

See Also

d(value)

Datetime formatting

Signature:

d(value: number | Date | string): string;

Details

If this is used in a reactive context, it will re-evaluate once the locale changes.

If UseI18nScope 'local' or Some UseI18nOptions are specified at useI18n, it’s translated in preferentially local scope datetime formats than global scope datetime formats.

If not, then it’s formatted with global scope datetime formats.

See Also

Parameters

ParameterTypeDescription
valuenumber | Date | stringA value, timestamp number or Date instance or ISO 8601 string

Returns

Formatted value

d(value, key)

Datetime formatting

Signature:

d(value: number | Date | string, key: string): string;

Details

Overloaded d. About details, see the d details.

In this overloaded d, format in datetime format for a key registered in datetime formats.

Parameters

ParameterTypeDescription
valuenumber | Date | stringA value, timestamp number or Date instance or ISO 8601 string
keystringA key of datetime formats

Returns

Formatted value

d(value, key, locale)

Datetime formatting

Signature:

d(value: number | Date | string, key: string, locale: Locale): string;

Details

Overloaded d. About details, see the d details.

In this overloaded d, format in datetime format for a key registered in datetime formats at target locale

Parameters

ParameterTypeDescription
valuenumber | Date | stringA value, timestamp number or Date instance or ISO 8601 string
keystringA key of datetime formats
localeLocaleA locale, it will be used over than global scope or local scope.

Returns

Formatted value

d(value, options)

Datetime formatting

Signature:

d(value: number | Date | string, options: DateTimeOptions): string;

Details

Overloaded d. About details, see the d details.

You can also suppress the warning, when the formatting missing according to the options.

About details of options, see the .

Parameters

ParameterTypeDescription
valuenumber | Date | stringA value, timestamp number or Date instance or ISO 8601 string
optionsDateTimeOptionsAdditional for datetime formatting

Returns

Formatted value

getDateTimeFormat(locale)

Get datetime format

Signature:

getDateTimeFormat(locale: Locale): DateTimeFormat;

Details

get datetime format from Composer instance datetimeFormats.

Parameters

ParameterTypeDescription
localeLocaleA target locale

Returns

Datetime format

getLocaleMessage(locale)

Get locale message

Signature:

getLocaleMessage(locale: Locale): LocaleMessageDictionary<Message>;

Details

get locale message from Composer instance messages.

Parameters

ParameterTypeDescription
localeLocaleA target locale

Returns

Locale messages

getMissingHandler()

Get missing handler

Signature:

getMissingHandler(): MissingHandler | null;

See Also

Parameters

ParameterTypeDescription

Returns

MissingHandler

getNumberFormat(locale)

Get number format

Signature:

getNumberFormat(locale: Locale): NumberFormat;

Details

get number format from Composer instance numberFormats.

Parameters

ParameterTypeDescription
localeLocaleA target locale

Returns

Number format

getPostTranslationHandler()

Get post translation handler

Signature:

getPostTranslationHandler(): PostTranslationHandler<Message> | null;

See Also

Parameters

ParameterTypeDescription

Returns

mergeDateTimeFormat(locale, format)

Merge datetime format

Signature:

mergeDateTimeFormat(locale: Locale, format: DateTimeFormat): void;

Details

Merge datetime format to Composer instance datetimeFormats.

Parameters

ParameterTypeDescription
localeLocaleA target locale
formatDateTimeFormatA target datetime format

mergeLocaleMessage(locale, message)

Merge locale message

Signature:

mergeLocaleMessage(locale: Locale, message: LocaleMessageDictionary<Message>): void;

Details

Merge locale message to Composer instance messages.

Parameters

ParameterTypeDescription
localeLocaleA target locale
messageLocaleMessageDictionary<Message>A message

mergeNumberFormat(locale, format)

Merge number format

Signature:

mergeNumberFormat(locale: Locale, format: NumberFormat): void;

Details

Merge number format to Composer instance numberFormats.

Parameters

ParameterTypeDescription
localeLocaleA target locale
formatNumberFormatA target number format

n(value)

Number Formatting

Signature:

n(value: number): string;

Details

If this is used in a reactive context, it will re-evaluate once the locale changes.

If UseI18nScope 'local' or Some UseI18nOptions are specified at useI18n, it’s translated in preferentially local scope datetime formats than global scope datetime formats.

If not, then it’s formatted with global scope number formats.

See Also

Parameters

ParameterTypeDescription
valuenumberA number value

Returns

Formatted value

n(value, key)

Number Formatting

Signature:

n(value: number, key: string): string;

Details

Overloaded n. About details, see the n details.

In this overloaded n, format in number format for a key registered in number formats.

Parameters

ParameterTypeDescription
valuenumberA number value
keystringA key of number formats

Returns

Formatted value

n(value, key, locale)

Number Formatting

Signature:

n(value: number, key: string, locale: Locale): string;

Details

Overloaded n. About details, see the n details.

In this overloaded n, format in number format for a key registered in number formats at target locale.

Parameters

ParameterTypeDescription
valuenumberA number value
keystringA key of number formats
localeLocaleA locale, it will be used over than global scope or local scope.

Returns

Formatted value

n(value, options)

Number Formatting

Signature:

n(value: number, options: NumberOptions): string;

Details

Overloaded n. About details, see the n details.

You can also suppress the warning, when the formatting missing according to the options.

About details of options, see the .

Parameters

ParameterTypeDescription
valuenumberA number value
optionsNumberOptionsAdditional for number formatting

Returns

Formatted value

rt(message)

Resolve locale message translation

Signature:

rt(message: MessageFunction<Message> | Message): string;

Details

If this is used in a reactive context, it will re-evaluate once the locale changes.

If UseI18nScope 'local' or Some UseI18nOptions are specified at useI18n, it’s translated in preferentially local scope locale messages than global scope locale messages.

If not, then it’s translated with global scope locale messages.

See Also

TIP

The use-case for rt is for programmatic locale messages translation with using tm, v-for, javascript for statement.

WARNING

rt differs from t in that it processes the locale message directly, not the key of the locale message. There is no internal fallback with rt. You need to understand and use the structure of the locale messge returned by tm.

Parameters

ParameterTypeDescription
messageMessageFunction<Message> | MessageA target locale message to be resolved. You will need to specify the locale message returned by tm.

Returns

Translated message

rt(message, plural, options)

Resolve locale message translation for plurals

Signature:

rt(message: MessageFunction<Message> | Message, plural: number, options?: TranslateOptions): string;

Details

Overloaded rt. About details, see the rt details.

In this overloaded rt, return a pluralized translation message.

See Also

TIP

The use-case for rt is for programmatic locale messages translation with using tm, v-for, javascript for statement.

WARNING

rt differs from t in that it processes the locale message directly, not the key of the locale message. There is no internal fallback with rt. You need to understand and use the structure of the locale messge returned by tm.

Parameters

ParameterTypeDescription
messageMessageFunction<Message> | MessageA target locale message to be resolved. You will need to specify the locale message returned by tm.
pluralnumberWhich plural string to get. 1 returns the first one.
optionsTranslateOptionsAdditional for translation

Returns

Translated message

rt(message, list, options)

Resolve locale message translation for list interpolations

Signature:

rt(message: MessageFunction<Message> | Message, list: unknown[], options?: TranslateOptions): string;

Details

Overloaded rt. About details, see the rt details.

In this overloaded rt, return a pluralized translation message.

See Also

TIP

The use-case for rt is for programmatic locale messages translation with using tm, v-for, javascript for statement.

WARNING

rt differs from t in that it processes the locale message directly, not the key of the locale message. There is no internal fallback with rt. You need to understand and use the structure of the locale messge returned by tm.

Parameters

ParameterTypeDescription
messageMessageFunction<Message> | MessageA target locale message to be resolved. You will need to specify the locale message returned by tm.
listunknown[]A values of list interpolation.
optionsTranslateOptionsAdditional for translation

Returns

Translated message

rt(message, named, options)

Resolve locale message translation for named interpolations

Signature:

rt(message: MessageFunction<Message> | Message, named: NamedValue, options?: TranslateOptions): string;

Details

Overloaded rt. About details, see the rt details.

In this overloaded rt, for each placeholder x, the locale messages should contain a {x} token.

See Also

TIP

The use-case for rt is for programmatic locale messages translation with using tm, v-for, javascript for statement.

WARNING

rt differs from t in that it processes the locale message directly, not the key of the locale message. There is no internal fallback with rt. You need to understand and use the structure of the locale messge returned by tm.

Parameters

ParameterTypeDescription
messageMessageFunction<Message> | MessageA target locale message to be resolved. You will need to specify the locale message returned by tm.
namedNamedValueA values of named interpolation.
optionsTranslateOptionsAdditional for translation

Returns

Translated message

setDateTimeFormat(locale, format)

Set datetime format

Signature:

setDateTimeFormat(locale: Locale, format: DateTimeFormat): void;

Details

Set datetime format to Composer instance datetimeFormats.

Parameters

ParameterTypeDescription
localeLocaleA target locale
formatDateTimeFormatA target datetime format

setLocaleMessage(locale, message)

Set locale message

Signature:

setLocaleMessage(locale: Locale, message: LocaleMessageDictionary<Message>): void;

Details

Set locale message to Composer instance messages.

Parameters

ParameterTypeDescription
localeLocaleA target locale
messageLocaleMessageDictionary<Message>A message

setMissingHandler(handler)

Set missing handler

Signature:

setMissingHandler(handler: MissingHandler | null): void;

See Also

Parameters

ParameterTypeDescription
handlerMissingHandler | nullA MissingHandler

setNumberFormat(locale, format)

Set number format

Signature:

setNumberFormat(locale: Locale, format: NumberFormat): void;

Details

Set number format to Composer instance numberFormats.

Parameters

ParameterTypeDescription
localeLocaleA target locale
formatNumberFormatA target number format

setPostTranslationHandler(handler)

Set post translation handler

Signature:

setPostTranslationHandler(handler: PostTranslationHandler<Message> | null): void;

See Also

Parameters

ParameterTypeDescription
handlerPostTranslationHandler<Message> | nullA

t(key)

Locale message translation

Signature:

t(key: Path | number): string;

Details

If this is used in a reactive context, it will re-evaluate once the locale changes.

If UseI18nScope 'local' or Some UseI18nOptions are specified at useI18n, it’s translated in preferentially local scope locale messages than global scope locale messages.

If not, then it’s translated with global scope locale messages.

See Also

Parameters

ParameterTypeDescription
keyPath | numberA target locale message key

Returns

Translated message

t(key, plural, options)

Locale message translation for plurals

Signature:

t(key: Path | number, plural: number, options?: TranslateOptions): string;

Details

Overloaded t. About details, see the t 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 .

See Also

Parameters

ParameterTypeDescription
keyPath | numberA target locale message key
pluralnumberWhich plural string to get. 1 returns the first one.
optionsTranslateOptionsAdditional for translation

Returns

Translated message

t(key, defaultMsg, options)

Locale message translation for missing default message

Signature:

t(key: Path | number, defaultMsg: string, options?: TranslateOptions): string;

Details

Overloaded t. About details, see the t 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 .

Parameters

ParameterTypeDescription
keyPath | numberA target locale message key
defaultMsgstringA default message to return if no translation was found
optionsTranslateOptionsAdditional for translation

Returns

Translated message

t(key, list, options)

Locale message translation for list interpolations

Signature:

t(key: Path | number, list: unknown[], options?: TranslateOptions): string;

Details

Overloaded t. About details, see the t 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 .

See Also

Parameters

ParameterTypeDescription
keyPath | numberA target locale message key
listunknown[]A values of list interpolation
optionsTranslateOptionsAdditional for translation

Returns

Translated message

t(key, list, plural)

Locale message translation for list interpolations and plurals

Signature:

t(key: Path | number, list: unknown[], plural: number): string;

Details

Overloaded t. About details, see the t 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.

See Also

Parameters

ParameterTypeDescription
keyPath | numberA target locale message key
listunknown[]A values of list interpolation
pluralnumberWhich plural string to get. 1 returns the first one.

Returns

Translated message

t(key, list, defaultMsg)

Locale message translation for list interpolations and missing default message

Signature:

t(key: Path | number, list: unknown[], defaultMsg: string): string;

Details

Overloaded t. About details, see the t 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.

See Also

Parameters

ParameterTypeDescription
keyPath | numberA target locale message key
listunknown[]A values of list interpolation
defaultMsgstringA default message to return if no translation was found

Returns

Translated message

t(key, named, options)

Locale message translation for named interpolations

Signature:

t(key: Path | number, named: NamedValue, options?: TranslateOptions): string;

Details

Overloaded t. About details, see the t 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 .

See Also

Parameters

ParameterTypeDescription
keyPath | numberA target locale message key
namedNamedValueA values of named interpolation
optionsTranslateOptionsAdditional for translation

Returns

Translated message

t(key, named, plural)

Locale message translation for named interpolations and plurals

Signature:

t(key: Path | number, named: NamedValue, plural: number): string;

Details

Overloaded t. About details, see the t details.

In this overloaded t, for each placeholder x, the locale messages should contain a {x} token, and return a pluralized translation message.

See Also

Parameters

ParameterTypeDescription
keyPath | numberA target locale message key
namedNamedValueA values of named interpolation
pluralnumberWhich plural string to get. 1 returns the first one.

Returns

Translated message

t(key, named, defaultMsg)

Locale message translation for named interpolations and plurals

Signature:

t(key: Path | number, named: NamedValue, defaultMsg: string): string;

Details

Overloaded t. About details, see the t 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.

See Also

Parameters

ParameterTypeDescription
keyPath | numberA target locale message key
namedNamedValueA values of named interpolation
defaultMsgstringA default message to return if no translation was found

Returns

Translated message

te(key, locale)

Translation locale message exist

Signature:

te(key: Path, locale?: Locale): boolean;

Details

whether do exist locale message on Composer instance messages.

If you specified locale, check the locale messages of locale.

Parameters

ParameterTypeDescription
keyPathA target locale message key
localeLocaleA locale, it will be used over than global scope or local scope

Returns

If found locale message, true, else false

tm(key)

Locale messages getter

Signature:

tm(key: Path): LocaleMessageValue<Message> | {};

Details

If UseI18nScope 'local' or Some UseI18nOptions are specified at useI18n, it’s translated in preferentially local scope locale messages than global scope locale messages.

Based on the current locale, locale messages will be returned from Composer instance messages.

If you change the locale, the locale messages returned will also correspond to the locale.

If there are no locale messages for the given key in the composer instance messages, they will be returned with fallbacking.

WARNING

You need to use rt for the locale message returned by tm. see the rt details.

Parameters

ParameterTypeDescription
keyPathA target locale message key

Locale messages |

Examples

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 'vue
import { useI18n } from 'vue-i18n'

export default defineComponent({
  setup() {
    const { rt, tm } = useI18n({
      messages: {
        en: {
          contents: [
            {
              title: 'Title1',
              // ...
              paragraphs: [
                // ...
              ]
            }
          ]
        }
      }
      // ...
    })
    // ...
    return { ... , rt, tm }
  }
})

ComposerAdditionalOptions

Composer additional options for useI18n

Signature:

export interface ComposerAdditionalOptions 

Details

ComposerAdditionalOptions is extend for ComposerOptions, so you can specify these options.

See Also

useScope

ComposerOptions

Composer Options

Signature:

export interface ComposerOptions<Message = VueMessageType> 

Details

This is options to create composer.

datetimeFormats

Signature:

datetimeFormats?: DateTimeFormatsType;

Details

The datetime formats of localization.

Default Value

{}

See Also

escapeParameter

Signature:

escapeParameter?: boolean;

Details

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.

Default Value

false

See Also

fallbackFormat

Signature:

fallbackFormat?: boolean;

Details

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.

Default Value

false

See Also

fallbackLocale

Signature:

fallbackLocale?: FallbackLocale;

Details

The locale of fallback localization.

For more complex fallback definitions see fallback.

Default Value

The default 'en-US' for the locale if it's not specified, or it's locale value

See Also

fallbackRoot

Signature:

fallbackRoot?: boolean;

Details

In the component localization, whether to fallback to root level (global scope) localization when localization fails.

If false, it's not fallback to root.

Default Value

true

See Also

fallbackWarn

Signature:

fallbackWarn?: boolean | RegExp;

Details

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).

Default Value

true

See Also

flatJson

Signature:

flatJson?: boolean;

Details

Allow use flat json messages or not

Default Value

false

inheritLocale

Signature:

inheritLocale?: boolean;

Details

Whether inheritance the root level locale to the component localization locale.

If false, regardless of the root level locale, localize for each component locale.

Default Value

true

See Also

locale

Signature:

locale?: Locale;

Details

The locale of localization.

If the locale contains a territory and a dialect, this locale contains an implicit fallback.

Default Value

'en-US'

See Also

messageResolver

Signature:

messageResolver?: MessageResolver;

Details

A message resolver to resolve 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 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 is enabled, so the message will need to be resolved as well.

The message resolver is called indirectly by the following APIs:

TIP

🆕 v9.2+

WARNING

If you use the message resolver, the flatJson setting will be ignored. That is, you need to resolve the flat JSON by yourself.

Default Value

undefined

See Also

Examples

Here is an example of how to set it up using your createI18n:

import { createI18n } from 'vue-i18n'

// your message resolver
function messageResolver(obj, path) {
  // simple message resolving!
  const msg = obj[path]
  return msg != null ? msg : null
}

// call with I18n option
const i18n = createI18n({
  legacy: false,
  locale: 'ja',
  messageResolver, // set your message resolver
  messages: {
    en: { ... },
    ja: { ... }
  }
})

// the below your something to do ...
// ...

messages

Signature:

messages?: LocaleMessages<Message>;

Details

The locale messages of localization.

Default Value

{}

See Also

missing

Signature:

missing?: MissingHandler;

Details

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.

Default Value

null

missingWarn

Signature:

missingWarn?: boolean | RegExp;

Details

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).

Default Value

true

See Also

modifiers

Signature:

modifiers?: LinkedModifiers<Message>;

Details

Custom Modifiers for linked messages.

See Also

numberFormats

Signature:

numberFormats?: NumberFormatsType;

Details

The number formats of localization.

Default Value

{}

See Also

pluralRules

Signature:

pluralRules?: PluralizationRules;

Details

A set of rules for word pluralization

Default Value

{}

See Also

postTranslation

Signature:

postTranslation?: PostTranslationHandler<Message>;

Details

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.

Default Value

null

warnHtmlMessage

Signature:

warnHtmlMessage?: boolean;

Details

Whether to allow the use locale messages of HTML formatting.

See the warnHtmlMessage property.

Default Value

'off'

See Also

MissingHandler

Signature:

export declare type MissingHandler = (locale: Locale, key: Path, insttance?: ComponentInternalInstance, type?: string) => string | void;

useI18n

Use Composition API for Vue I18n

Signature:

export declare function useI18n<Options extends UseI18nOptions = object, Messages extends Record<keyof Options['messages'], LocaleMessageDictionary<VueMessageType>> = Record<keyof Options['messages'], LocaleMessageDictionary<VueMessageType>>, DateTimeFormats extends Record<keyof Options['datetimeFormats'], DateTimeFormat> = Record<keyof Options['datetimeFormats'], DateTimeFormat>, NumberFormats extends Record<keyof Options['numberFormats'], NumberFormat> = Record<keyof Options['numberFormats'], NumberFormat>>(options?: Options): Composer<Options['messages'], Options['datetimeFormats'], Options['numberFormats']>;

Details

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.

Parameters

ParameterTypeDescription
optionsOptionsAn options, see UseI18nOptions

Returns

Composer instance

Examples

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>

UseI18nOptions

I18n Options for useI18n

Signature:

export declare type UseI18nOptions = ComposerAdditionalOptions & ComposerOptions;

Details

UseI18nOptions is inherited ComposerAdditionalOptions and ComposerOptions, so you can specify these options.

See Also

VueMessageType

Signature:

export declare type VueMessageType = string | VNode;