vue-i18n / general / createI18n
函数:createI18n()
调用签名
ts
function createI18n<Options, Messages, DateTimeFormats, NumberFormats, OptionLocale>(options): I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale>;类型参数
| 类型参数 | 默认类型 |
|---|---|
Options 扩展 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 扩展 Record<string, unknown> | Options["messages"] 扩展 Record<string, unknown> ? any[any] : object |
DateTimeFormats 扩展 Record<string, unknown> | Options["datetimeFormats"] 扩展 Record<string, unknown> ? any[any] : object |
NumberFormats 扩展 Record<string, unknown> | Options["numberFormats"] 扩展 Record<string, unknown> ? any[any] : object |
OptionLocale | Options["locale"] 扩展 string ? any[any] : string |
参数
| 参数 | 类型 |
|---|---|
options | Options |
返回值
I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale>
调用签名
ts
function createI18n<Schema, Locales, Options, Messages, DateTimeFormats, NumberFormats, OptionLocale>(options): I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale>;Vue I18n 工厂函数
类型参数
| 类型参数 | 默认类型 | 描述 |
|---|---|---|
Schema 扩展 object | LocaleMessage<VueMessageType> | i18n 资源(消息、datetimeFormats、numberFormats)模式,默认为 LocaleMessage |
Locales 扩展 string | object | "en-US" | i18n 资源模式的区域设置,默认为 en-US |
Options 扩展 I18nOptions<SchemaParams<Schema, VueMessageType>, LocaleParams<Locales>, ComposerOptions<SchemaParams<Schema, VueMessageType>, LocaleParams<Locales>, LocaleParams<Locales> 扩展 object ? M : LocaleParams<Locales> 扩展 string ? string & LocaleParams<Locales> : string, LocaleParams<Locales> 扩展 object ? D : LocaleParams<Locales> 扩展 string ? string & LocaleParams<Locales> : string, LocaleParams<Locales> 扩展 object ? N : LocaleParams<Locales> 扩展 string ? string & LocaleParams<Locales> : string, SchemaParams<Schema, VueMessageType> 扩展 object ? M : LocaleMessage<VueMessageType>, SchemaParams<Schema, VueMessageType> 扩展 object ? D : IntlDateTimeFormat, SchemaParams<Schema, VueMessageType> 扩展 object ? N : IntlNumberFormat, LocaleMessages<SchemaParams<Schema, VueMessageType> 扩展 object ? M : LocaleMessage<VueMessageType>, LocaleParams<Locales> 扩展 object ? M : LocaleParams<Locales> 扩展 string ? string & LocaleParams<Locales> : string, VueMessageType>, IntlDateTimeFormats<SchemaParams<Schema, VueMessageType> 扩展 object ? D : IntlDateTimeFormat, LocaleParams<Locales> 扩展 object ? D : LocaleParams<Locales> 扩展 string ? string & LocaleParams<Locales> : string, string>, IntlNumberFormats<SchemaParams<Schema, VueMessageType> 扩展 object ? N : IntlNumberFormat, LocaleParams<Locales> 扩展 object ? N : LocaleParams<Locales> 扩展 string ? string & LocaleParams<Locales> : string, string>> | - | |
Messages 扩展 Record<string, unknown> | NonNullable<Options["messages"]> 扩展 Record<string, unknown> ? NonNullable<NonNullable<Options["messages"]>> : object | - |
DateTimeFormats 扩展 Record<string, unknown> | NonNullable<Options["datetimeFormats"]> 扩展 Record<string, unknown> ? NonNullable<NonNullable<Options["datetimeFormats"]>> : object | - |
NumberFormats 扩展 Record<string, unknown> | NonNullable<Options["numberFormats"]> 扩展 Record<string, unknown> ? NonNullable<NonNullable<Options["numberFormats"]>> : object | - |
OptionLocale | Options["locale"] 扩展 string ? any[any] : string | - |
参数
| 参数 | 类型 | 描述 |
|---|---|---|
options | Options | 选项,请参见 I18nOptions |
返回值
I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale>
I18n 实例
参见:
示例
js
import { createApp } from 'vue'
import { createI18n, useI18n } from 'vue-i18n'
// 使用 I18n 选项调用
const i18n = createI18n({
locale: 'ja',
messages: {
en: { ... },
ja: { ... }
}
})
const App = {
setup() {
// ...
const { t } = useI18n({ ... })
return { ... , t }
}
}
const app = createApp(App)
// 安装!
app.use(i18n)
app.mount('#app')