vue-i18n / general / createI18n
Function: createI18n()
Call Signature
ts
function createI18n<Options, Messages, DateTimeFormats, NumberFormats, OptionLocale>(options): I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale>;Type Parameters
| Type Parameter | Default type |
|---|---|
Options extends I18nOptions<{ datetime: IntlDateTimeFormat; message: DefaultLocaleMessageSchema; number: IntlNumberFormat; }, string, ComposerOptions<{ datetime: IntlDateTimeFormat; message: DefaultLocaleMessageSchema; number: IntlNumberFormat; }, string, string, string, string, LocaleMessage<VueMessageType>, IntlDateTimeFormat, IntlNumberFormat, LocaleMessages<LocaleMessage<VueMessageType>, string, VueMessageType>, IntlDateTimeFormats<IntlDateTimeFormat, string>, IntlNumberFormats<IntlNumberFormat, string>>> | I18nOptions<{ datetime: IntlDateTimeFormat; message: DefaultLocaleMessageSchema; number: IntlNumberFormat; }, string, ComposerOptions<{ datetime: IntlDateTimeFormat; message: DefaultLocaleMessageSchema; number: IntlNumberFormat; }, string, string, string, string, LocaleMessage<VueMessageType>, IntlDateTimeFormat, IntlNumberFormat, LocaleMessages<LocaleMessage<VueMessageType>, string, VueMessageType>, IntlDateTimeFormats<IntlDateTimeFormat, string>, IntlNumberFormats<IntlNumberFormat, string>>> |
Messages extends Record<string, unknown> | Options["messages"] extends Record<string, unknown> ? any[any] : object |
DateTimeFormats extends Record<string, unknown> | Options["datetimeFormats"] extends Record<string, unknown> ? any[any] : object |
NumberFormats extends Record<string, unknown> | Options["numberFormats"] extends Record<string, unknown> ? any[any] : object |
OptionLocale | Options["locale"] extends string ? any[any] : string |
Parameters
| Parameter | Type |
|---|---|
options | Options |
Returns
I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale>
Call Signature
ts
function createI18n<Schema, Locales, Options, Messages, DateTimeFormats, NumberFormats, OptionLocale>(options): I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale>;Vue I18n General
Vue I18n factory
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
Schema extends object | LocaleMessage<VueMessageType> | The i18n resources (messages, datetimeFormats, numberFormats) schema, default LocaleMessage |
Locales extends string | object | "en-US" | The locales of i18n resource schema, default en-US |
Options extends I18nOptions<SchemaParams<Schema, VueMessageType>, LocaleParams<Locales>, ComposerOptions<SchemaParams<Schema, VueMessageType>, LocaleParams<Locales>, LocaleParams<Locales> extends object ? M : LocaleParams<Locales> extends string ? string & LocaleParams<Locales> : string, LocaleParams<Locales> extends object ? D : LocaleParams<Locales> extends string ? string & LocaleParams<Locales> : string, LocaleParams<Locales> extends object ? N : LocaleParams<Locales> extends string ? string & LocaleParams<Locales> : string, SchemaParams<Schema, VueMessageType> extends object ? M : LocaleMessage<VueMessageType>, SchemaParams<Schema, VueMessageType> extends object ? D : IntlDateTimeFormat, SchemaParams<Schema, VueMessageType> extends object ? N : IntlNumberFormat, LocaleMessages<SchemaParams<Schema, VueMessageType> extends object ? M : LocaleMessage<VueMessageType>, LocaleParams<Locales> extends object ? M : LocaleParams<Locales> extends string ? string & LocaleParams<Locales> : string, VueMessageType>, IntlDateTimeFormats<SchemaParams<Schema, VueMessageType> extends object ? D : IntlDateTimeFormat, LocaleParams<Locales> extends object ? D : LocaleParams<Locales> extends string ? string & LocaleParams<Locales> : string>, IntlNumberFormats<SchemaParams<Schema, VueMessageType> extends object ? N : IntlNumberFormat, LocaleParams<Locales> extends object ? N : LocaleParams<Locales> extends string ? string & LocaleParams<Locales> : string>>> | I18nOptions<SchemaParams<Schema, VueMessageType>, LocaleParams<Locales>, ComposerOptions<SchemaParams<Schema, VueMessageType>, LocaleParams<Locales>, LocaleParams<Locales> extends object ? M : LocaleParams<Locales> extends string ? string & LocaleParams<Locales> : string, LocaleParams<Locales> extends object ? D : LocaleParams<Locales> extends string ? string & LocaleParams<Locales> : string, LocaleParams<Locales> extends object ? N : LocaleParams<Locales> extends string ? string & LocaleParams<Locales> : string, SchemaParams<Schema, VueMessageType> extends object ? M : LocaleMessage<VueMessageType>, SchemaParams<Schema, VueMessageType> extends object ? D : IntlDateTimeFormat, SchemaParams<Schema, VueMessageType> extends object ? N : IntlNumberFormat, LocaleMessages<SchemaParams<Schema, VueMessageType> extends object ? M : LocaleMessage<VueMessageType>, LocaleParams<Locales> extends object ? M : LocaleParams<Locales> extends string ? string & LocaleParams<Locales> : string, VueMessageType>, IntlDateTimeFormats<SchemaParams<Schema, VueMessageType> extends object ? D : IntlDateTimeFormat, LocaleParams<Locales> extends object ? D : LocaleParams<Locales> extends string ? string & LocaleParams<Locales> : string>, IntlNumberFormats<SchemaParams<Schema, VueMessageType> extends object ? N : IntlNumberFormat, LocaleParams<Locales> extends object ? N : LocaleParams<Locales> extends string ? string & LocaleParams<Locales> : string>>> | - |
Messages extends Record<string, unknown> | NonNullable<Options["messages"]> extends Record<string, unknown> ? NonNullable<NonNullable<Options["messages"]>> : object | - |
DateTimeFormats extends Record<string, unknown> | NonNullable<Options["datetimeFormats"]> extends Record<string, unknown> ? NonNullable<NonNullable<Options["datetimeFormats"]>> : object | - |
NumberFormats extends Record<string, unknown> | NonNullable<Options["numberFormats"]> extends Record<string, unknown> ? NonNullable<NonNullable<Options["numberFormats"]>> : object | - |
OptionLocale | Options["locale"] extends string ? any[any] : string | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
options | Options | An options, see the I18nOptions |
Returns
I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale>
I18n instance
See about:
Example
js
import { createApp } from 'vue'
import { createI18n, useI18n } from 'vue-i18n'
// call with I18n option
const i18n = createI18n({
locale: 'ja',
messages: {
en: { ... },
ja: { ... }
}
})
const App = {
setup() {
// ...
const { t } = useI18n({ ... })
return { ... , t }
}
}
const app = createApp(App)
// install!
app.use(i18n)
app.mount('#app')