组件注入
ComponentCustomOptions
Vue I18n 的组件自定义属性
签名:
export interface ComponentCustomOptions;i18n
Vue I18n 组件选项
签名:
i18n?: VueI18nOptions;另请参见
ComponentCustomProperties
Vue I18n 的组件自定义选项
签名:
export interface ComponentCustomProperties;详情
这些属性会被注入到每个子组件中
$i18n
导出的全局作曲家实例,或全局 VueI18n 实例。
签名:
$i18n: VueI18n | ExportedGlobalComposer;详情
您可以获得从全局 作曲家 实例创建的 导出作曲家实例,或全局 VueI18n 实例。
您可以通过此属性引用的实例,在 组合式 API 模式 中获得导出的作曲家实例,在 传统 API 模式 中获得 VueI18n 实例。
通过此属性引用的实例所管理的语言环境、语言消息和其他资源在全局范围内有效。
如果未指定 i18n 组件选项,则与可引用的 i18n 实例 global 的 VueI18n 实例相同。
另请参见
$t(key)
本地化消息翻译
签名:
$t(key: Key): TranslateResult;详情
如果在响应性上下文中使用,当语言环境改变时将重新评估。
在 组合式 API 模式 中,$t 由 app.config.globalProperties 注入。输入/输出与 Composer 相同,并在 全局作用域 中工作。有关详细信息,请参见 Composer#t。
在 传统 API 模式 中,输入/输出与 VueI18n 实例相同。有关详细信息,请参见 VueI18n#t。
另请参见
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
返回值
翻译消息
$t(key, locale)
注意
此 API 签名仅在传统 API 模式下可用,直到 v9 版本支持。
本地化消息翻译
签名:
$t(key: Key, locale: Locale): TranslateResult;详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| locale | Locale | 语言环境,覆盖全局作用域或局部作用域的语言环境 |
返回值
翻译消息
$t(key, locale, list)
注意
此 API 签名仅在传统 API 模式下可用,直到 v9 版本支持。
本地化消息翻译
签名:
$t(key: Key, locale: Locale, list: unknown[]): TranslateResult;详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| locale | Locale | 语言环境,覆盖全局作用域或局部作用域的语言环境 |
| list | unknown[] | 列表插值的值 |
返回值
翻译消息
$t(key, locale, named)
注意
此 API 签名仅在传统 API 模式下可用,直到 v9 版本支持。
本地化消息翻译
签名:
$t(key: Key, locale: Locale, named: object): TranslateResult;详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| locale | Locale | 语言环境,覆盖全局作用域或局部作用域的语言环境 |
| named | object | 命名插值的值 |
返回值
翻译消息
$t(key, plural)
本地化消息翻译
签名:
$t(key: Key, plural: number): TranslateResult;注意
仅支持 组合式 API 模式,直到 v9 版本。v10 及更高版本也可以在传统 API 模式下使用。
详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| plural | number | 复数选择号 |
返回值
翻译消息
$t(key, plural, options)
本地化消息翻译
签名:
$t(key: Key, plural: number, options: TranslateOptions): TranslateResult;注意
仅支持 组合式 API 模式,直到 v9 版本。v10 及更高版本也可以在传统 API 模式下使用。
详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| plural | number | 复数选择号 |
| options | TranslateOptions | 选项,请参见 TranslateOptions |
返回值
翻译消息
$t(key, defaultMsg)
本地化消息翻译
签名:
$t(key: Key, defaultMsg: string): TranslateResult;注意
仅支持 组合式 API 模式,直到 v9 版本。v10 及更高版本也可以在传统 API 模式下使用。
详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| defaultMsg | string | 如果找不到翻译则返回的默认消息 |
返回值
翻译消息
$t(key, defaultMsg, options)
本地化消息翻译
签名:
$t(key: Key, defaultMsg: string, options: TranslateOptions): TranslateResult;注意
仅支持 组合式 API 模式,直到 v9 版本。v10 及更高版本也可以在传统 API 模式下使用。
详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| defaultMsg | string | 如果找不到翻译则返回的默认消息 |
| options | TranslateOptions | 选项,请参见 TranslateOptions |
返回值
翻译消息
$t(key, list)
本地化消息翻译
签名:
$t(key: Key, list: unknown[]): TranslateResult;详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| list | unknown[] | 列表插值的值 |
返回值
翻译消息
$t(key, list, plural)
本地化消息翻译
签名:
$t(key: Key, list: unknown[], plural: number): TranslateResult;注意
仅支持 组合式 API 模式,直到 v9 版本。v10 及更高版本也可以在传统 API 模式下使用。
详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| list | unknown[] | 列表插值的值 |
| plural | number | 复数选择号 |
返回值
翻译消息
$t(key, list, defaultMsg)
本地化消息翻译
签名:
$t(key: Key, list: unknown[], defaultMsg: string): TranslateResult;注意
仅支持 组合式 API 模式,直到 v9 版本。v10 及更高版本也可以在传统 API 模式下使用。
详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| list | unknown[] | 列表插值的值 |
| defaultMsg | string | 如果找不到翻译则返回的默认消息 |
返回值
翻译消息
$t(key, list, options)
本地化消息翻译
签名:
$t(key: Key, list: unknown[], options: TranslateOptions): TranslateResult;注意
仅支持 组合式 API 模式,直到 v9 版本。v10 及更高版本也可以在传统 API 模式下使用。
详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| list | unknown[] | 列表插值的值 |
| options | TranslateOptions | 选项,请参见 TranslateOptions |
返回值
翻译消息
$t(key, named)
本地化消息翻译
签名:
$t(key: Key, named: NamedValue): TranslateResult;详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| named | NamedValue | 命名插值的值 |
返回值
翻译消息
$t(key, named, plural)
本地化消息翻译
签名:
$t(key: Key, named: NamedValue, plural: number): TranslateResult;注意
仅支持 组合式 API 模式,直到 v9 版本。v10 及更高版本也可以在传统 API 模式下使用。
详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| named | NamedValue | 命名插值的值 |
| plural | number | 复数选择号 |
返回值
翻译消息
$t(key, named, defaultMsg)
本地化消息翻译
签名:
$t(key: Key, named: NamedValue, defaultMsg: string): TranslateResult;注意
仅支持 组合式 API 模式,直到 v9 版本。v10 及更高版本也可以在传统 API 模式下使用。
详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| named | NamedValue | 命名插值的值 |
| defaultMsg | string | 如果找不到翻译则返回的默认消息 |
返回值
翻译消息
$t(key, named, options)
本地化消息翻译
签名:
$t(key: Key, named: NamedValue, options: TranslateOptions): TranslateResult;注意
仅支持 组合式 API 模式,直到 v9 版本。v10 及更高版本也可以在传统 API 模式下使用。
详情
重载的 $t。有关详细信息,请参见 $t 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| named | NamedValue | 命名插值的值 |
| options | TranslateOptions | 选项,请参见 TranslateOptions |
返回值
翻译消息
$rt(message)
解析本地化消息翻译
签名:
$rt(message: MessageFunction<VueMessageType> | VueMessageType): string;详情
如果在响应性上下文中使用,当语言环境改变时将重新评估。
在 组合式 API 模式 中,$rt 由 app.config.globalProperties 注入。输入/输出与 Composer 相同,并在 全局作用域 中工作。有关详细信息,请参见 Composer#rt。
在 传统 API 模式 中,输入/输出与 VueI18n 实例相同。有关详细信息,请参见 VueI18n#rt。
另请参见
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| message | MessageFunction<VueMessageType> | VueMessageType | 要解析的目标本地化消息。您需要指定 $tm 返回的本地化消息。 |
返回值
翻译消息
$rt(message, plural, options)
解析复数的本地化消息翻译
签名:
$rt(message: MessageFunction<VueMessageType> | VueMessageType, plural: number, options?: TranslationOptions): string;详情
重载的 $rt。有关详细信息,请参见 $rt 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| message | MessageFunction<VueMessageType> | VueMessageType | 要解析的目标本地化消息。您需要指定 $tm 返回的本地化消息。 |
| plural | number | 要获取哪个复数字符串。1 返回第一个。 |
| options | TranslateOptions | 额外的 TranslateOptions |
返回值
翻译消息
$rt(message, list, options)
解析列表插值的本地化消息翻译
签名:
$rt(message: MessageFunction<VueMessageType> | VueMessageType, list: unknown[], options?: TranslationOptions): string;详情
重载的 $rt。有关详细信息,请参见 $rt 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| message | MessageFunction<VueMessageType> | VueMessageType | 要解析的目标本地化消息。您需要指定 $tm 返回的本地化消息。 |
| list | unknown[] | 列表插值的值。 |
| options | TranslateOptions | 额外的 TranslateOptions |
返回值
翻译消息
$rt(message, named, options)
解析命名插值的本地化消息翻译
签名:
$rt(message: MessageFunction<VueMessageType> | VueMessageType, named: NamedValue, options?: TranslationOptions): string;详情
重载的 $rt。有关详细信息,请参见 $rt 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| message | MessageFunction<VueMessageType> | VueMessageType | 要解析的目标本地化消息。您需要指定 $tm 返回的本地化消息。 |
| named | NamedValue | 命名插值的值。 |
| options | TranslateOptions | 额外的 TranslateOptions |
返回值
翻译消息
$te(key, locale)
翻译消息存在性检查
签名:
$te(key: Key, locale?: Locale): boolean;详情
有关详细信息,请参见 VueI18n#te
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
| locale | Locale | 可选,语言环境,覆盖全局作用域或局部作用域的语言环境 |
返回值
如果找到本地化消息,返回 true,否则返回 false。
$tm(key)
本地化消息获取器
签名:
$tm(key: Key): LocaleMessageValue<VueMessageType> | {}详情
如果指定了 i18n 组件选项,则优先从局部作用域的本地化消息中获取,而不是全局作用域的本地化消息。
如果未指定 i18n 组件选项,则从全局作用域的本地化消息中获取。
基于当前的 locale,将从 Composer 实例消息中返回本地化消息。
如果您更改了 locale,返回的本地化消息也将对应于该语言环境。
如果在 Composer 实例消息中没有给定 key 的本地化消息,它们将通过 回退机制 返回。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| key | Key | 目标本地化消息键 |
返回值
本地化消息
注意
您需要使用 $rt 来处理 $tm 返回的本地化消息。
$d(value)
日期时间格式化
签名:
$d(value: number | Date): DateTimeFormatResult | string;详情
如果在响应性上下文中使用,当语言环境改变时将重新评估。
在 组合式 API 模式 中,输入/输出与 VueI18n 实例相同。有关详细信息,请参见 VueI18n#d。
在 组合式 API 模式 中,$d 由 app.config.globalProperties 注入。输入/输出与 Composer 实例相同,并在 全局作用域 中工作。有关详细信息,请参见 Composer#d。
另请参见
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| value | number | Date | 值,时间戳数字或 Date 实例 |
返回值
格式化后的值
$d(value, key)
日期时间格式化
签名:
$d(value: number | Date, key: string): DateTimeFormatResult | string;详情
重载的 $d。有关详细信息,请参见 $d 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| value | number | Date | 值,时间戳数字或 Date 实例 |
| key | string | 日期时间格式的键 |
返回值
格式化后的值
$d(value, key, locale)
日期时间格式化
签名:
$d(value: number | Date, key: string, locale: Locale): DateTimeFormatResult | string;详情
重载的 $d。有关详细信息,请参见 $d 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| value | number | Date | 值,时间戳数字或 Date 实例 |
| key | string | 日期时间格式的键 |
| locale | Locale | 语言环境,覆盖全局作用域或局部作用域的语言环境 |
返回值
格式化后的值
$d(value, args)
日期时间格式化
签名:
$d(value: number | Date, args: { [key: string]: string | boolean | number }): DateTimeFormatResult;详情
重载的 $d。有关详细信息,请参见 $d 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| value | number | Date | 值,时间戳数字或 Date 实例 |
| args | { [key: string]: string } | 参数值 |
返回值
格式化后的值
$d(value, options)
日期时间格式化
签名:
$d(value: number | Date, options: DateTimeOptions): string;详情
重载的 $d。有关详细信息,请参见 $d 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| value | number | Date | 值,时间戳数字或 Date 实例 |
| options | DateTimeOptions | 选项,请参见 DateTimeOptions |
返回值
格式化后的值
$n(value)
数字格式化
签名:
$n(value: number): NumberFormatResult | string;详情
如果在响应性上下文中使用,当语言环境改变时将重新评估。
在 传统 API 模式 中,输入/输出与 VueI18n 实例相同。有关详细信息,请参见 VueI18n#n。
在 组合式 API 模式 中,$n 由 app.config.globalProperties 注入。输入/输出与 Composer 实例相同,并在 全局作用域 中工作。有关详细信息,请参见 Composer#n。
另请参见
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| value | number | 数字值 |
返回值
格式化后的值
$n(value, key)
数字格式化
签名:
$n(value: number, key: string): NumberFormatResult | string;详情
重载的 $n。有关详细信息,请参见 $n 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| value | number | 数字值 |
| key | string | 数字格式的键 |
返回值
格式化后的值
$n(value, key, locale)
数字格式化
签名:
$n(value: number, key: string, locale: Locale): NumberFormatResult | string;详情
重载的 $n。有关详细信息,请参见 $n 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| value | number | 数字值 |
| key | string | 数字格式的键 |
| locale | Locale | 语言环境,覆盖全局作用域或局部作用域的语言环境 |
返回值
格式化后的值
$n(value, args)
数字格式化
签名:
$n(value: number, args: { [key: string]: string | boolean | number }): NumberFormatResult;详情
重载的 $n。有关详细信息,请参见 $n 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| value | number | 数字值 |
| args | { [key: string]: string } | 参数值 |
返回值
格式化后的值
$n(value, key, args)
数字格式化
签名:
$n(value: number, key: string, args: { [key: string]: string | boolean | number }): NumberFormatResult详情
重载的 $n。有关详细信息,请参见 $n 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| value | number | 数字值 |
| key | string | 数字格式的键 |
| args | { [key: string]: string } | 参数值 |
返回值
格式化后的值
$n(value, key, locale, args)
数字格式化
签名:
$n(value: number, key: string, locale: Locale, args: { [key: string]: string | boolean | number }): NumberFormatResult详情
重载的 $n。有关详细信息,请参见 $n 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| value | number | 数字值 |
| key | string | 数字格式的键 |
| locale | Locale | 语言环境,覆盖全局作用域或局部作用域的语言环境 |
| args | { [key: string]: string } | 参数值 |
返回值
格式化后的值
$n(value, options)
数字格式化
签名:
$n(value: number, options: NumberOptions): string;详情
重载的 $n。有关详细信息,请参见 $n 的说明。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| value | number | 数字值 |
| options | NumberOptions | 选项,请参见 NumberOptions |
返回值
格式化后的值