General

createI18n

Vue I18n factory

Signature:

export declare function createI18n<Options extends I18nOptions = {}, 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): I18n<Options['messages'], Options['datetimeFormats'], Options['numberFormats'], Options['legacy'] extends boolean ? Options['legacy'] : true>;

Details

If you use Legacy API mode, you need toto specify VueI18nOptions and legacy: true option.

If you use composition API mode, you need to specify ComposerOptions.

See Also

Parameters

ParameterTypeDescription
optionsOptionsAn options, see the I18nOptions

Returns

I18n instance

Examples

Example 1:

case: for Legacy API

import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'

// call with I18n option
const 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 option
const i18n = createI18n({
  legacy: false, // you must specify 'legacy: false' option
  locale: 'ja',
  messages: {
    en: { ... },
    ja: { ... }
  }
})

const App = {
  setup() {
    // ...
    const { t } = useI18n({ ... })
    return { ... , t }
  }
}

const app = createApp(App)

// install!
app.use(i18n)
app.mount('#app')

ExportedGlobalComposer

Exported global composer instance

Signature:

export interface ExportedGlobalComposer 

Details

This interface is the global composer that is provided interface that is injected into each component with app.config.globalProperties.

availableLocales

Available locales

Signature:

readonly availableLocales: Locale[];

Details

This property is proxy-like property for Composer#availableLocales. About details, see the Composer#availableLocales

fallbackLocale

Fallback locale

Signature:

fallbackLocale: FallbackLocale;

Details

This property is proxy-like property for Composer#fallbackLocale. About details, see the Composer#fallbackLocale

locale

Locale

Signature:

locale: Locale;

Details

This property is proxy-like property for Composer#locale. About details, see the Composer#locale

I18n

I18n instance

Signature:

export interface I18n<Messages = {}, DateTimeFormats = {}, NumberFormats = {}, Legacy extends boolean = true> 

Details

The instance required for installation as the Vue plugin

global

The property accessible to the global Composer instance or VueI18n instance

Signature:

readonly global: Legacy extends true ? VueI18n<Messages, DateTimeFormats, NumberFormats> : Composer<Messages, DateTimeFormats, NumberFormats>;

Details

If the I18n#mode is 'legacy', then you can access to a global VueI18n instance, else then I18n#mode is 'composition' , you can access to the global Composer instance.

An instance of this property is global scope*.

mode

Vue I18n API mode

Signature:

readonly mode: I18nMode;

Details

If you specified legacy: true option in createI18n, return legacy, else composition

Default Value

'composition'

install(app, options)

Install entry point

Signature:

install(app: App, ...options: unknown[]): void;

Parameters

ParameterTypeDescription
appAppA target Vue app instance
optionsunknown[]An install options

I18nAdditionalOptions

I18n Additional Options

Signature:

export interface I18nAdditionalOptions 

Details

Specific options for createI18n

globalInjection

Whether Whether to inject global properties & functions into for each component.

Signature:

globalInjection?: boolean;

Details

If set to true, then properties and methods prefixed with $ are injected into Vue Component.

Default Value

false

See Also

legacy

Whether vue-i18n Legacy API mode use on your Vue App

Signature:

legacy?: boolean;

Details

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.

Default Value

true

See Also

I18nMode

Vue I18n API mode

Signature:

export declare type I18nMode = 'legacy' | 'composition';

See Also

I18nOptions

I18n Options for createI18n

Signature:

export declare type I18nOptions = I18nAdditionalOptions & (ComposerOptions | VueI18nOptions);

Details

I18nOptions is inherited I18nAdditionalOptions, ComposerOptions and VueI18nOptions, so you can specify these options.

I18nPluginOptions

Vue I18n plugin options

Signature:

export interface I18nPluginOptions 

Details

An options specified when installing Vue I18n as Vue plugin with using app.use.

globalInstall

Whether to globally install the components that is offered by Vue I18n

Signature:

globalInstall?: boolean;

Details

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 to false to install when needed.

Default Value

true

useI18nComponentName

Whether to use the tag name i18n for Translation Component

Signature:

useI18nComponentName?: boolean;

Details

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.

Default Value

false

I18nScope

I18n Scope

Signature:

export declare type I18nScope = 'local' | 'parent' | 'global';

See Also

VERSION

Vue I18n Version

Signature:

VERSION: string

Details

Semver format. Same format as the package.json version field.