Skip to content

旧版 API

Choice

签名:

typescript
export type Choice = number;

已弃用

将在 vue-i18n v12 中移除

DateTimeFormatResult

签名:

typescript
export type DateTimeFormatResult = string;

已弃用

将在 vue-i18n v12 中移除

LocaleMessageObject

签名:

typescript
export type LocaleMessageObject<Message = string> = LocaleMessageDictionary<Message>;

已弃用

将在 vue-i18n v12 中移除

NumberFormatResult

签名:

typescript
export type NumberFormatResult = string;

已弃用

将在 vue-i18n v12 中移除

PluralizationRulesMap

签名:

typescript
export type PluralizationRulesMap = {
    [locale: string]: PluralizationRule;
};

已弃用

将在 vue-i18n v12 中移除

TranslateResult

签名:

typescript
export type TranslateResult = string;

已弃用

将在 vue-i18n v12 中移除

VueI18n

VueI18n 旧版接口

签名:

typescript
export interface VueI18n<Messages extends Record<string, any> = {}, DateTimeFormats extends Record<string, any> = {}, NumberFormats extends Record<string, any> = {}, OptionLocale = Locale, ResourceLocales = PickupLocales<NonNullable<Messages>> | PickupLocales<NonNullable<DateTimeFormats>> | PickupLocales<NonNullable<NumberFormats>>, Locales = Locale extends GeneratedLocale ? GeneratedLocale : OptionLocale extends string ? [ResourceLocales] extends [never] ? Locale : ResourceLocales : OptionLocale | ResourceLocales, Composition extends Composer<Messages, DateTimeFormats, NumberFormats, OptionLocale> = Composer<Messages, DateTimeFormats, NumberFormats, OptionLocale>>

已弃用

将在 vue-i18n v12 中移除

详情

此接口与 VueI18n 类接口(提供于 Vue I18n v8.x)兼容。

availableLocales

签名:

typescript
readonly availableLocales: Composition['availableLocales'];

详情

messages 中可用语言列表,按词典顺序排列。

d

日期时间格式化

签名:

typescript
d: VueI18nDateTimeFormatting<DateTimeFormats, Locales, RemoveIndexSignature<{
        [K in keyof DefineDateTimeFormat]: DefineDateTimeFormat[K];
    }>>;

详情

关于详细函数,请参阅 VueI18nDateTimeFormatting

datetimeFormats

签名:

typescript
readonly datetimeFormats: {
        [K in keyof DateTimeFormats]: DateTimeFormats[K];
    };

详情

本地化的时间格式。

另请参见

escapeParameterHtml

签名:

typescript
escapeParameterHtml: Composition['escapeParameter'];

详情

在消息翻译前是否转义插值参数。

另请参见

fallbackLocale

签名:

typescript
fallbackLocale: FallbackLocales<Locales>;

详情

当前 VueI18n 实例使用的回退语言环境。

另请参见

formatFallbackMessages

签名:

typescript
formatFallbackMessages: Composition['fallbackFormat'];

详情

回退到 fallbackLocale 或根目录时是否抑制警告。

另请参见

getDateTimeFormat

获取日期时间格式

签名:

typescript
getDateTimeFormat: Composition['getDateTimeFormat'];

详情

从 VueI18n 实例 datetimeFormats 获取日期时间格式。

getLocaleMessage

获取本地化消息

签名:

typescript
getLocaleMessage: Composition['getLocaleMessage'];

详情

从 VueI18n 实例 messages 获取本地化消息。

getNumberFormat

获取数字格式

签名:

typescript
getNumberFormat: Composition['getNumberFormat'];

详情

从 VueI18n 实例 numberFormats 获取数字格式。

id

签名:

typescript
id: number;

详情

实例 ID。

locale

签名:

typescript
locale: Locales;

详情

当前 VueI18n 实例使用的语言环境。

如果语言环境包含地区和方言,则该语言环境包含隐式回退。

另请参见

mergeDateTimeFormat

合并日期时间格式

签名:

typescript
mergeDateTimeFormat: Composition['mergeDateTimeFormat'];

详情

合并日期时间格式到 VueI18n 实例 datetimeFormats

mergeLocaleMessage

合并本地化消息

签名:

typescript
mergeLocaleMessage: Composition['mergeLocaleMessage'];

详情

合并本地化消息到 VueI18n 实例 messages

mergeNumberFormat

合并数字格式

签名:

typescript
mergeNumberFormat: Composition['mergeNumberFormat'];

详情

合并数字格式到 VueI18n 实例 numberFormats

messages

签名:

typescript
readonly messages: {
        [K in keyof Messages]: Messages[K];
    };

详情

本地化的消息。

另请参见

missing

签名:

typescript
missing: MissingHandler | null;

详情

本地化缺失处理程序。

modifiers

签名:

typescript
readonly modifiers: Composition['modifiers'];

详情

链接消息的自定义修饰符。

另请参见

n

数字格式化

签名:

typescript
n: VueI18nNumberFormatting<NumberFormats, Locales, RemoveIndexSignature<{
        [K in keyof DefineNumberFormat]: DefineNumberFormat[K];
    }>>;

详情

关于详细函数,请参阅 VueI18nNumberFormatting

numberFormats

签名:

typescript
readonly numberFormats: {
        [K in keyof NumberFormats]: NumberFormats[K];
    };

详情

本地化的数字格式。

另请参见

pluralizationRules

一组单词复数化规则

签名:

typescript
pluralizationRules: Composition['pluralRules'];

另请参见

postTranslation

签名:

typescript
postTranslation: PostTranslationHandler<VueMessageType> | null;

详情

翻译后处理处理程序。

rt

解析本地化消息翻译

签名:

typescript
rt: VueI18nResolveLocaleMessageTranslation<Locales>;

详情

关于详细函数,请参阅 VueI18nResolveLocaleMessageTranslation

setDateTimeFormat

设置日期时间格式

签名:

typescript
setDateTimeFormat: Composition['setDateTimeFormat'];

详情

设置日期时间格式到 VueI18n 实例 datetimeFormats

setLocaleMessage

设置本地化消息

签名:

typescript
setLocaleMessage: Composition['setLocaleMessage'];

详情

设置本地化消息到 VueI18n 实例 messages

setNumberFormat

设置数字格式

签名:

typescript
setNumberFormat: Composition['setNumberFormat'];

详情

设置数字格式到 VueI18n 实例 numberFormats

silentFallbackWarn

签名:

typescript
silentFallbackWarn: Composition['fallbackWarn'];

详情

本地化失败时是否抑制回退警告。

silentTranslationWarn

签名:

typescript
silentTranslationWarn: Composition['missingWarn'];

详情

本地化失败时是否抑制警告输出。

另请参见

sync

签名:

typescript
sync: Composition['inheritLocale'];

详情

是否同步根级别语言环境到组件本地化语言环境。

另请参见

t

本地化消息翻译

签名:

typescript
t: VueI18nTranslation<Messages, Locales, RemoveIndexSignature<{
        [K in keyof DefineLocaleMessage]: DefineLocaleMessage[K];
    }>>;

详情

关于详细函数,请参阅 VueI18nTranslation

tm

本地化消息获取器

签名:

typescript
tm: Composition['tm'];

详情

如果指定了 i18n 组件选项,则优先从局部作用域本地化消息中获取,而不是从全局作用域本地化消息中获取。

如果未指定 i18n 组件选项,则从全局作用域本地化消息中获取。

基于当前 locale,将从 Composer 实例消息中返回本地化消息。

如果你更改了 locale,返回的本地化消息也会相应对应。

如果在 composer 实例消息中没有给定 key 的本地化消息,则将使用 回退

WARNING

你需要使用 rt 来处理 tm 返回的本地化消息。请查看 rt 详情。

示例

模板:

html
<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>
js
import { createI18n } from 'vue-i18n'

const i18n = createI18n({
  messages: {
    en: {
      contents: [
        {
          title: 'Title1',
          // ...
          paragraphs: [
            // ...
          ]
        }
      ]
    }
  }
  // ...
})

warnHtmlInMessage

签名:

typescript
warnHtmlInMessage: WarnHtmlInMessageLevel;

详情

是否允许使用 HTML 格式的本地化消息。

如果你设置为 warnerror,将检查 VueI18n 实例的本地化消息。

如果你指定为 warn,将在控制台输出警告。

如果你指定为 error 将抛出错误。

另请参见

te(key, locale)

翻译本地化消息存在

签名:

typescript
te<Str extends string, Key extends PickupKeys<Messages> = PickupKeys<Messages>>(key: Str | Key, locale?: Locales): boolean;

详情

VueI18n 实例 messages 中是否存在本地化消息。

如果你指定了 locale,则检查该语言环境的本地化消息。

参数

参数类型描述
keyStr | Key目标本地化消息键
localeLocales目标语言环境

返回值

如果找到本地化消息,返回 true,否则返回 false

VueI18nDateTimeFormatting

VueI18n 旧版接口的日期时间格式化函数

签名:

typescript
export interface VueI18nDateTimeFormatting<DateTimeFormats extends Record<string, any> = {}, Locales = 'en-US', DefinedDateTimeFormat extends RemovedIndexResources<DefineDateTimeFormat> = RemovedIndexResources<DefineDateTimeFormat>, C = IsEmptyObject<DefinedDateTimeFormat> extends false ? PickupFormatPathKeys<{
    [K in keyof DefinedDateTimeFormat]: DefinedDateTimeFormat[K];
}> : never, M = IsEmptyObject<DateTimeFormats> extends false ? PickupFormatKeys<DateTimeFormats> : never, ResourceKeys extends C | M = IsNever<C> extends false ? IsNever<M> extends false ? C | M : C : IsNever<M> extends false ? M : never>

已弃用

将在 vue-i18n v12 中移除

详情

这是 VueI18n 的接口

(value: number | Date): DateTimeFormatResult;

日期时间格式化

签名:

typescript
(value: number | Date): DateTimeFormatResult;

详情

如果在反应式上下文中使用,当语言环境更改时会重新计算一次。

如果指定了 i18n 组件选项,则优先使用局部作用域日期时间格式,而不是全局作用域日期时间格式。

如果未指定 i18n 组件选项,则使用全局作用域日期时间格式。

另请参见

参数

参数类型描述
valuenumber | Date值,时间戳数字或 Date 实例

返回值

格式化后的值

(value: Value, key: Key | ResourceKeys): DateTimeFormatResult;

日期时间格式化

签名:

typescript
<Value extends number | Date = number, Key extends string = string>(value: Value, key: Key | ResourceKeys): DateTimeFormatResult;

详情

重载的 d。详情请参见 调用签名 详情。

参数

参数类型描述
valueValue值,时间戳数字或 Date 实例
keyKey | ResourceKeys日期时间格式的键

返回值

格式化后的值

(value: Value, key: Key | ResourceKeys, locale: Locales): DateTimeFormatResult;

日期时间格式化

签名:

typescript
<Value extends number | Date = number, Key extends string = string>(value: Value, key: Key | ResourceKeys, locale: Locales): DateTimeFormatResult;

详情

重载的 d。详情请参见 调用签名 详情。

参数

参数类型描述
valueValue值,时间戳数字或 Date 实例
keyKey | ResourceKeys日期时间格式的键
localeLocales语言环境,将优先使用该语言环境而非全局或局部作用域

返回值

格式化后的值

(value: number | Date, args: { [key: string]: string | boolean | number; }): DateTimeFormatResult;

日期时间格式化

签名:

typescript
(value: number | Date, args: {
        [key: string]: string | boolean | number;
    }): DateTimeFormatResult;

详情

重载的 d。详情请参见 调用签名 详情。

参数

参数类型描述
valuenumber | Date值,时间戳数字或 Date 实例
args{ [key: string]: string | boolean | number; }参数值

返回值

格式化后的值

VueI18nNumberFormatting

VueI18n 旧版接口的数字格式化函数

签名:

typescript
export interface VueI18nNumberFormatting<NumberFormats extends Record<string, any> = {}, Locales = 'en-US', DefinedNumberFormat extends RemovedIndexResources<DefineNumberFormat> = RemovedIndexResources<DefineNumberFormat>, C = IsEmptyObject<DefinedNumberFormat> extends false ? PickupFormatPathKeys<{
    [K in keyof DefinedNumberFormat]: DefinedNumberFormat[K];
}> : never, M = IsEmptyObject<NumberFormats> extends false ? PickupFormatKeys<NumberFormats> : never, ResourceKeys extends C | M = IsNever<C> extends false ? IsNever<M> extends false ? C | M : C : IsNever<M> extends false ? M : never>

已弃用

将在 vue-i18n v12 中移除

详情

这是 VueI18n 的接口

(value: number): NumberFormatResult;

数字格式化

签名:

typescript
(value: number): NumberFormatResult;

详情

如果在反应式上下文中使用,当语言环境更改时会重新计算一次。

如果指定了 i18n 组件选项,则优先使用局部作用域数字格式,而不是全局作用域数字格式。

如果未指定 i18n 组件选项,则使用全局作用域数字格式。

另请参见

参数

参数类型描述
valuenumber数字值

返回值

格式化后的值

(value: number, key: Key | ResourceKeys): NumberFormatResult;

数字格式化

签名:

typescript
<Key extends string = string>(value: number, key: Key | ResourceKeys): NumberFormatResult;

详情

重载的 n。详情请参见 调用签名 详情。

参数

参数类型描述
valuenumber数字值
keyKey | ResourceKeys数字格式的键

返回值

格式化后的值

(value: number, key: Key | ResourceKeys, locale: Locales): NumberFormatResult;

数字格式化

签名:

typescript
<Key extends string = string>(value: number, key: Key | ResourceKeys, locale: Locales): NumberFormatResult;

详情

重载的 n。详情请参见 调用签名 详情。

参数

参数类型描述
valuenumber数字值
keyKey | ResourceKeys数字格式的键
localeLocales语言环境,将优先使用该语言环境而非全局或局部作用域

返回值

格式化后的值

(value: number, args: { [key: string]: string | boolean | number; }): NumberFormatResult;

数字格式化

签名:

typescript
(value: number, args: {
        [key: string]: string | boolean | number;
    }): NumberFormatResult;

详情

重载的 n。详情请参见 调用签名 详情。

参数

参数类型描述
valuenumber数字值
args{ [key: string]: string | boolean | number; }参数值

返回值

格式化后的值

VueI18nOptions

VueI18n 选项

签名:

typescript
export interface VueI18nOptions<Schema extends {
    message?: unknown;
    datetime?: unknown;
    number?: unknown;
} = {
    message: DefaultLocaleMessageSchema;
    datetime: DefaultDateTimeFormatSchema;
    number: DefaultNumberFormatSchema;
}, Locales extends {
    messages: unknown;
    datetimeFormats: unknown;
    numberFormats: unknown;
} | string = Locale, Options extends ComposerOptions<Schema, Locales> = ComposerOptions<Schema, Locales>>

已弃用

将在 vue-i18n v12 中移除

详情

此选项兼容 VueI18n 类构造函数选项(提供于 Vue I18n v8.x)

availableLocales

签名:

typescript
availableLocales?: Locale[];

详情

消息中可用语言列表,按词典顺序排列。

默认值

[]

datetime

datetimeFormats

escapeParameterHtml

签名:

typescript
escapeParameterHtml?: Options['escapeParameter'];

详情

是否转义列表或命名插值值的参数。启用此选项时,该选项:

  • 转义 HTML 特殊字符 (<, >, ", ', &, /, =)
  • 通过以下方式净化最终翻译的 HTML 以防止 XSS 攻击:
    • 转义 HTML 属性值中的危险字符
    • 中和事件处理属性 (onclick, onerror 等)
    • 禁用 href、src、action、formaction 和 style 属性中的 javascript: URL

当翻译输出用于 v-html 且翻译资源包含 HTML 标记(例如围绕用户提供的值)时,这很有用。

这种使用模式主要发生在向 UI 组件传递预计算文本字符串时。

转义过程涉及将以下符号替换为其相应的 HTML 字符实体:<, >, ", '

escapeParameterHtml 设置为 true 不应破坏现有功能,但提供了针对细微 XSS 攻击向量的保护。

默认值

false

另请参见

fallbackLocale

签名:

typescript
fallbackLocale?: Options['fallbackLocale'];

详情

回退本地化语言环境。

有关更复杂的回退定义,请参见 fallback。

默认值

如果未指定 locale,则默认为 'en-US',或者为 locale

另请参见

fallbackRoot

签名:

typescript
fallbackRoot?: Options['fallbackRoot'];

详情

在组件本地化中,当本地化失败时是否回退到根级别(全局作用域)本地化。

如果 false,则不回退到根级别。

默认值

true

另请参见

flatJson

签名:

typescript
flatJson?: Options['flatJson'];

详情

是否允许使用扁平 JSON 消息

默认值

false

formatFallbackMessages

签名:

typescript
formatFallbackMessages?: Options['fallbackFormat'];

详情

回退到 fallbackLocale 或根目录时是否抑制警告。

默认值

false

另请参见

locale

签名:

typescript
locale?: Options['locale'];

详情

本地化语言环境。

如果语言环境包含地区和方言,则该语言环境包含隐式回退。

默认值

'en-US'

另请参见

message

messageResolver

签名:

typescript
messageResolver?: MessageResolver;

详情

用于解析 messages 的消息解析器。

如果没有指定,默认使用 vue-i18n 内部消息解析器。

你需要自己实现一个消息解析器,支持以下要求:

  • 使用作为消息解析器第一个参数传入的语言环境消息和第二个参数传入的路径来解析消息。
  • 如果无法解析消息,你需要返回 null
  • 如果你返回 null,如果启用了 fallbackLocale,消息解析器还会在回退时被调用,因此你也需要解析消息。

消息解析器间接由以下 API 调用:

TIP

🆕 v9.2+

WARNING

如果你使用消息解析器,将忽略 flatJson 设置。也就是说,你需要自己解析扁平 JSON。

默认值

undefined

另请参见

示例

以下是使用 createI18n 设置它的示例:

js
import { createI18n } from 'vue-i18n'

// 你的消息解析器
function messageResolver(obj, path) {
  // 简单的消息解析!
  const msg = obj[path]
  return msg != null ? msg : null
}

// 使用 I18n 选项调用
const i18n = createI18n({
  locale: 'ja',
  messageResolver, // 设置你的消息解析器
  messages: {
    en: { ... },
    ja: { ... }
  }
})

// 下面是你需要做的...
// ...

messages

missing

签名:

typescript
missing?: Options['missing'];

详情

本地化缺失处理程序。

处理程序在本地化目标语言环境、本地化路径键、Vue 实例和值时被调用。

如果分配了缺失处理程序,并且发生本地化缺失,则不会发出警告。

默认值

null

modifiers

签名:

typescript
modifiers?: Options['modifiers'];

详情

链接消息的自定义修饰符。

另请参见

number

numberFormats

pluralizationRules

签名:

typescript
pluralizationRules?: Options['pluralRules'];

详情

一组单词复数化规则

默认值

{}

另请参见

postTranslation

签名:

typescript
postTranslation?: Options['postTranslation'];

详情

翻译后处理处理程序。处理程序在 $tt 之后被调用。

如果你想要过滤翻译后的文本(例如去除空格),此处理程序很有用。

默认值

null

sharedMessages

签名:

typescript
sharedMessages?: LocaleMessages<VueMessageType>;

详情

用于组件的共享本地化消息。更多详情请参见基于组件的本地化。

默认值

undefined

另请参见

silentFallbackWarn

签名:

typescript
silentFallbackWarn?: Options['fallbackWarn'];

详情

当你缺少某种语言的翻译时是否进行模板插值。

如果 true,跳过为你"基础"语言编写模板;键就是你的模板。

默认值

false

另请参见

silentTranslationWarn

签名:

typescript
silentTranslationWarn?: Options['missingWarn'];

详情

本地化失败时是否抑制警告输出。

如果 true,抑制本地化失败警告。

如果你使用正则表达式,你可以抑制与翻译键(例如 t)匹配的本地化失败警告。

默认值

false

另请参见

sync

签名:

typescript
sync?: boolean;

详情

是否同步根级别语言环境到组件本地化语言环境。

如果 false,无论根级别语言环境如何,都将为每个组件语言环境进行本地化。

默认值

true

另请参见

warnHtmlInMessage

签名:

typescript
warnHtmlInMessage?: WarnHtmlInMessageLevel;

详情

是否允许使用 HTML 格式的本地化消息。

请参见 warnHtmlInMessage 属性。

默认值

'off'

另请参见

VueI18nResolveLocaleMessageTranslation

VueI18n 旧版接口的本地化消息解析翻译函数

签名:

typescript
export type VueI18nResolveLocaleMessageTranslation<Locales = 'en-US'> = ComposerResolveLocaleMessageTranslation<Locales>;

已弃用

将在 vue-i18n v12 中移除

详情

这是 VueI18n 的接口。此接口是 ComposerResolveLocaleMessageTranslation 的别名。

VueI18nTranslation

VueI18n 旧版接口的本地化消息翻译函数

签名:

typescript
export interface VueI18nTranslation<Messages extends Record<string, any> = {}, Locales = 'en-US', DefinedLocaleMessage extends RemovedIndexResources<DefineLocaleMessage> = RemovedIndexResources<DefineLocaleMessage>, C = IsEmptyObject<DefinedLocaleMessage> extends false ? PickupPaths<{
    [K in keyof DefinedLocaleMessage]: DefinedLocaleMessage[K];
}> : never, M = IsEmptyObject<Messages> extends false ? PickupKeys<Messages> : never, ResourceKeys extends C | M = IsNever<C> extends false ? IsNever<M> extends false ? C | M : C : IsNever<M> extends false ? M : never>

已弃用

将在 vue-i18n v12 中移除

详情

这是 VueI18n 的接口

(key: Key | ResourceKeys): TranslateResult;

本地化消息翻译。

签名:

typescript
<Key extends string>(key: Key | ResourceKeys): TranslateResult;

详情

如果在反应式上下文中使用,当语言环境更改时会重新计算一次。

如果指定了 i18n 组件选项,则优先使用局部作用域本地化消息,而不是全局作用域本地化消息。

如果未指定 i18n 组件选项,则使用全局作用域本地化消息。

另请参见

参数

参数类型描述
keyKey | ResourceKeys目标本地化消息键

返回值

翻译后的消息

(key: Key | ResourceKeys, named: Record<string, unknown>): TranslateResult;

本地化消息翻译。

签名:

typescript
<Key extends string>(key: Key | ResourceKeys, named: Record<string, unknown>): TranslateResult;

详情

重载的 t。详情请参见 调用签名 详情。

另请参见

参数

参数类型描述
keyKey | ResourceKeys目标本地化消息键
namedRecord<string, unknown>命名插值的值

返回值

翻译后的消息

(key: Key | ResourceKeys, named: NamedValue, plural: number): TranslateResult;

命名插值和复数的本地化消息翻译

签名:

typescript
<Key extends string>(key: Key | ResourceKeys, named: NamedValue, plural: number): TranslateResult;

详情

重载的 t。详情请参见 调用签名 详情。

在该重载的 t 中,对于每个占位符 x,本地化消息应包含 {x} 标记并返回复数化翻译消息。

另请参见

参数

参数类型描述
keyKey | ResourceKeys目标本地化消息键
namedNamedValue命名插值的值
pluralnumber要获取的复数字符串。1 返回第一个。

返回值

翻译后的消息

(key: Key | ResourceKeys, named: NamedValue, defaultMsg: string): TranslateResult;

命名插值和复数的本地化消息翻译

签名:

typescript
<Key extends string>(key: Key | ResourceKeys, named: NamedValue, defaultMsg: string): TranslateResult;

详情

重载的 t。详情请参见 调用签名 详情。

在该重载的 t 中,对于每个占位符 x,本地化消息应包含 {x} 标记,如果找不到翻译则返回默认消息。

另请参见

参数

参数类型描述
keyKey | ResourceKeys目标本地化消息键
namedNamedValue命名插值的值
defaultMsgstring如果找不到翻译则返回的默认消息

返回值

翻译后的消息

(key: Key | ResourceKeys, named: NamedValue, options: TranslateOptions<Locales>): TranslateResult;

命名插值的本地化消息翻译

签名:

typescript
<Key extends string>(key: Key | ResourceKeys, named: NamedValue, options: TranslateOptions<Locales>): TranslateResult;

详情

重载的 t。详情请参见 调用签名 详情。

在该重载的 t 中,对于每个占位符 x,本地化消息应包含 {x} 标记。

你还可以根据选项抑制翻译缺失时的警告。

有关选项的详情,请参见 。

另请参见

参数

参数类型描述
keyKey | ResourceKeys目标本地化消息键
namedNamedValue命名插值的值
optionsTranslateOptions<Locales>翻译的附加选项

返回值

翻译后的消息

(key: Key | ResourceKeys, plural: number): TranslateResult;

复数的本地化消息翻译

签名:

typescript
<Key extends string>(key: Key | ResourceKeys, plural: number): TranslateResult;

详情

重载的 t。详情请参见 调用签名 详情。

在该重载的 t 中,返回复数化翻译消息。

你还可以根据选项抑制翻译缺失时的警告。

另请参见

参数

参数类型描述
keyKey | ResourceKeys目标本地化消息键
pluralnumber要获取的复数字符串。1 返回第一个。

返回值

翻译后的消息

(key: Key | ResourceKeys, plural: number, options: TranslateOptions<Locales>): TranslateResult;

复数的本地化消息翻译

签名:

typescript
<Key extends string>(key: Key | ResourceKeys, plural: number, options: TranslateOptions<Locales>): TranslateResult;

详情

重载的 t。详情请参见 调用签名 详情。

在该重载的 t 中,返回复数化翻译消息。

你还可以根据选项抑制翻译缺失时的警告。

有关选项的详情,请参见 。

另请参见

参数

参数类型描述
keyKey | ResourceKeys目标本地化消息键
pluralnumber要获取的复数字符串。1 返回第一个。
optionsTranslateOptions<Locales>翻译的附加选项

返回值

翻译后的消息

(key: Key | ResourceKeys, defaultMsg: string): TranslateResult;

缺失默认消息的本地化消息翻译

签名:

typescript
<Key extends string>(key: Key | ResourceKeys, defaultMsg: string): TranslateResult;

详情

重载的 t。详情请参见 调用签名 详情。

在该重载的 t 中,如果找不到翻译则返回默认消息。

你还可以根据选项抑制翻译缺失时的警告。

参数

参数类型描述
keyKey | ResourceKeys目标本地化消息键
defaultMsgstring如果找不到翻译则返回的默认消息

返回值

翻译后的消息

(key: Key | ResourceKeys, defaultMsg: string, options: TranslateOptions<Locales>): TranslateResult;

缺失默认消息的本地化消息翻译

签名:

typescript
<Key extends string>(key: Key | ResourceKeys, defaultMsg: string, options: TranslateOptions<Locales>): TranslateResult;

详情

重载的 t。详情请参见 调用签名 详情。

在该重载的 t 中,如果找不到翻译则返回默认消息。

你还可以根据选项抑制翻译缺失时的警告。

有关选项的详情,请参见 。

参数

参数类型描述
keyKey | ResourceKeys目标本地化消息键
defaultMsgstring如果找不到翻译则返回的默认消息
optionsTranslateOptions<Locales>翻译的附加选项

返回值

翻译后的消息

(key: Key | ResourceKeys, list: unknown[]): TranslateResult;

本地化消息翻译。

签名:

typescript
<Key extends string>(key: Key | ResourceKeys, list: unknown[]): TranslateResult;

详情

重载的 t。详情请参见 调用签名 详情。

另请参见

参数

参数类型描述
keyKey | ResourceKeys目标本地化消息键
listunknown[]列表插值的值

返回值

翻译后的消息

(key: Key | ResourceKeys, list: unknown[], plural: number): TranslateResult;

列表插值和复数的本地化消息翻译

签名:

typescript
<Key extends string>(key: Key | ResourceKeys, list: unknown[], plural: number): TranslateResult;

详情

重载的 t。详情请参见 调用签名 详情。

在该重载的 t 中,本地化消息应包含 {0}{1}、… 为列表中的每个占位符,并返回复数化翻译消息。

另请参见

参数

参数类型描述
keyKey | ResourceKeys目标本地化消息键
listunknown[]列表插值的值
pluralnumber要获取的复数字符串。1 返回第一个。

返回值

翻译后的消息

(key: Key | ResourceKeys, list: unknown[], defaultMsg: string): TranslateResult;

列表插值和缺失默认消息的本地化消息翻译

签名:

typescript
<Key extends string>(key: Key | ResourceKeys, list: unknown[], defaultMsg: string): TranslateResult;

详情

重载的 t。详情请参见 调用签名 详情。

在该重载的 t 中,本地化消息应包含 {0}{1}、… 为列表中的每个占位符,如果找不到翻译则返回默认消息。

另请参见

参数

参数类型描述
keyKey | ResourceKeys目标本地化消息键
listunknown[]列表插值的值
defaultMsgstring如果找不到翻译则返回的默认消息

返回值

翻译后的消息

(key: Key | ResourceKeys, list: unknown[], options: TranslateOptions<Locales>): TranslateResult;

列表插值的本地化消息翻译

签名:

typescript
<Key extends string>(key: Key | ResourceKeys, list: unknown[], options: TranslateOptions<Locales>): TranslateResult;

详情

重载的 t。详情请参见 调用签名 详情。

在该重载的 t 中,本地化消息应包含 {0}{1}、… 为列表中的每个占位符。

你还可以根据选项抑制翻译缺失时的警告。

有关选项的详情,请参见 。

另请参见

参数

参数类型描述
keyKey | ResourceKeys目标本地化消息键
listunknown[]列表插值的值
optionsTranslateOptions<Locales>翻译的附加选项

返回值

翻译后的消息

WarnHtmlInMessageLevel

签名:

typescript
export type WarnHtmlInMessageLevel = 'off' | 'warn' | 'error';

已弃用

将在 vue-i18n v12 中移除