Interface: Composer<Messages, DateTimeFormats, NumberFormats, OptionLocale, ResourceLocales, Locales>
Vue I18n Composition
Composer interfaces
Remarks
This is the interface for being used for Vue 3 Composition API.
Extends
Type Parameters
| Type Parameter | Default type |
|---|---|
Messages extends Record<string, any> | object |
DateTimeFormats extends Record<string, any> | object |
NumberFormats extends Record<string, any> | object |
OptionLocale | Locale |
ResourceLocales | | PickupLocales<NonNullable<Messages>> | PickupLocales<NonNullable<DateTimeFormats>> | PickupLocales<NonNullable<NumberFormats>> |
Locales | Locale extends GeneratedLocale ? GeneratedLocale : OptionLocale extends Locale ? IsNever<ResourceLocales> extends true ? Locale : ResourceLocales : OptionLocale | ResourceLocales |
Methods
getDateTimeFormat()
getDateTimeFormat<DateTimeSchema, LocaleSchema, Locale, Return>(locale): Return;Get datetime format
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
DateTimeSchema extends Record<string, any> | never | The datetime format schema, default never |
LocaleSchema extends string | string | - |
Locale extends string | PickupLocales<NonNullable<DateTimeFormats>> | - |
Return | IsNever<DateTimeSchema> extends true ? IsEmptyObject<DateTimeFormats> extends true ? RemoveIndexSignature<{ [key: string]: DateTimeFormatOptions; }> : NonNullable<DateTimeFormats>[Locale] : DateTimeSchema | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
locale | LocaleSchema | Locale | A target locale |
Returns
Return
Datetime format
Remarks
get datetime format from Composer instance Composer#datetimeFormats.
getLocaleMessage()
getLocaleMessage<MessageSchema, LocaleSchema, Locale, Return>(locale): Return;Get locale message
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
MessageSchema extends LocaleMessage<VueMessageType> | never | The locale message schema, default never |
LocaleSchema extends string | string | - |
Locale extends string | PickupLocales<NonNullable<Messages>> | - |
Return | IsNever<MessageSchema> extends true ? IsEmptyObject<Messages> extends true ? RemoveIndexSignature<{ [key: string]: LocaleMessageValue<VueMessageType>; }> : NonNullable<Messages>[Locale] : MessageSchema | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
locale | LocaleSchema | Locale | A target locale |
Returns
Return
Locale messages
Remarks
get locale message from Composer instance Composer#messages.
getMissingHandler()
getMissingHandler(): MissingHandler | null;Get missing handler
See about:
- Composer#missing
Returns
MissingHandler | null
getNumberFormat()
getNumberFormat<NumberSchema, LocaleSchema, Locale, Return>(locale): Return;Get number format
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
NumberSchema extends Record<string, any> | never | The number format schema, default never |
LocaleSchema extends string | string | - |
Locale extends string | PickupLocales<NonNullable<NumberFormats>> | - |
Return | IsNever<NumberSchema> extends true ? IsEmptyObject<NumberFormats> extends true ? RemoveIndexSignature<{ [key: string]: NumberFormatOptions; }> : NonNullable<NumberFormats>[Locale] : NumberSchema | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
locale | LocaleSchema | Locale | A target locale |
Returns
Return
Number format
Remarks
get number format from Composer instance Composer#numberFormats.
getPostTranslationHandler()
getPostTranslationHandler():
| PostTranslationHandler<VueMessageType>
| null;Get post translation handler
See about:
- Composer#missing
Returns
| PostTranslationHandler<VueMessageType> | null
mergeDateTimeFormat()
mergeDateTimeFormat<DateTimeSchema, LocaleSchema, Locale, Formats>(locale, format): void;Merge datetime format
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
DateTimeSchema extends Record<string, any> | never | The datetime format schema, default never |
LocaleSchema extends string | string | - |
Locale extends string | PickupLocales<NonNullable<DateTimeFormats>> | - |
Formats | IsNever<DateTimeSchema> extends true ? Record<string, any> : DateTimeSchema | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
locale | LocaleSchema | Locale | A target locale |
format | Formats | A target datetime format |
Returns
void
Remarks
Merge datetime format to Composer instance Composer#datetimeFormats.
mergeLocaleMessage()
mergeLocaleMessage<MessageSchema, LocaleSchema, Locale, Message>(locale, message): void;Merge locale message
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
MessageSchema extends LocaleMessage<VueMessageType> | never | The locale message schema, default never |
LocaleSchema extends string | string | - |
Locale extends string | PickupLocales<NonNullable<Messages>> | - |
Message | IsNever<MessageSchema> extends true ? Record<string, any> : MessageSchema | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
locale | LocaleSchema | Locale | A target locale |
message | Message | A message |
Returns
void
Remarks
Merge locale message to Composer instance Composer#messages.
mergeNumberFormat()
mergeNumberFormat<NumberSchema, LocaleSchema, Locale, Formats>(locale, format): void;Merge number format
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
NumberSchema extends Record<string, any> | never | The number format schema, default never |
LocaleSchema extends string | string | - |
Locale extends string | PickupLocales<NonNullable<NumberFormats>> | - |
Formats | IsNever<NumberSchema> extends true ? Record<string, any> : NumberSchema | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
locale | LocaleSchema | Locale | A target locale |
format | Formats | A target number format |
Returns
void
Remarks
Merge number format to Composer instance Composer#numberFormats.
setDateTimeFormat()
setDateTimeFormat<DateTimeSchema, LocaleSchema, Locale, FormatsType, Formats>(locale, format): void;Set datetime format
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
DateTimeSchema extends Record<string, any> | never | The datetime format schema, default never |
LocaleSchema extends string | string | - |
Locale extends string | PickupLocales<NonNullable<DateTimeFormats>> | - |
FormatsType | IsNever<DateTimeSchema> extends true ? IsEmptyObject<DateTimeFormats> extends true ? RemoveIndexSignature<{ [key: string]: DateTimeFormatOptions; }> : NonNullable<DateTimeFormats>[Locale] : DateTimeSchema | - |
Formats | FormatsType | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
locale | LocaleSchema | Locale | A target locale |
format | Formats | A target datetime format |
Returns
void
Remarks
Set datetime format to Composer instance Composer#datetimeFormats.
setLocaleMessage()
setLocaleMessage<MessageSchema, LocaleSchema, Locale, MessageType, Message>(locale, message): void;Set locale message
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
MessageSchema extends LocaleMessage<VueMessageType> | never | The locale message schema, default never |
LocaleSchema extends string | string | - |
Locale extends string | PickupLocales<NonNullable<Messages>> | - |
MessageType | IsNever<MessageSchema> extends true ? IsEmptyObject<Messages> extends true ? RemoveIndexSignature<{ [key: string]: LocaleMessageValue<VueMessageType>; }> : NonNullable<Messages>[Locale] : MessageSchema | - |
Message | MessageType | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
locale | LocaleSchema | Locale | A target locale |
message | Message | A message |
Returns
void
Remarks
Set locale message to Composer instance Composer#messages.
setMissingHandler()
setMissingHandler(handler): void;Set missing handler
See about:
- Composer#missing
Parameters
| Parameter | Type | Description |
|---|---|---|
handler | MissingHandler | null | A MissingHandler |
Returns
void
setNumberFormat()
setNumberFormat<NumberSchema, LocaleSchema, Locale, FormatsType, Formats>(locale, format): void;Set number format
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
NumberSchema extends Record<string, any> | never | The number format schema, default never |
LocaleSchema extends string | string | - |
Locale extends string | PickupLocales<NonNullable<NumberFormats>> | - |
FormatsType | IsNever<NumberSchema> extends true ? IsEmptyObject<NumberFormats> extends true ? RemoveIndexSignature<{ [key: string]: NumberFormatOptions; }> : NonNullable<NumberFormats>[Locale] : NumberSchema | - |
Formats | FormatsType | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
locale | LocaleSchema | Locale | A target locale |
format | Formats | A target number format |
Returns
void
Remarks
Set number format to Composer instance Composer#numberFormats.
setPostTranslationHandler()
setPostTranslationHandler(handler): void;Set post translation handler
See about:
- Composer#missing
Parameters
| Parameter | Type | Description |
|---|---|---|
handler | | PostTranslationHandler<VueMessageType> | null | A PostTranslationHandler |
Returns
void
te()
te<Str, Key>(key, locale?): boolean;Translation locale message exist
Type Parameters
| Type Parameter | Default type |
|---|---|
Str extends string | - |
Key extends string | number | symbol | PickupKeys<Messages> |
Parameters
| Parameter | Type | Description |
|---|---|---|
key | Str | Key | A target locale message key |
locale? | Locales | A locale, it will be used over than global scope or local scope |
Returns
boolean
If found locale message, true, else false, Note that false is returned even if the value present in the key is not translatable, yet if translateExistCompatible is set to true, it will return true if the key is available, even if the value is not translatable.
Remarks
whether do exist locale message on Composer instance Composer#messages.
If you specified locale, check the locale messages of locale.
tm()
tm<Key, ResourceKeys, Locale, Target, Return>(key): Return;Locale messages getter
Type Parameters
| Type Parameter | Default type |
|---|---|
Key extends string | - |
ResourceKeys extends string | number | symbol | PickupKeys<Messages> |
Locale extends string | PickupLocales<NonNullable<Messages>> |
Target | IsEmptyObject<Messages> extends false ? NonNullable<Messages>[Locale] : RemoveIndexSignature<{ [key: string]: LocaleMessageValue<VueMessageType>; }> |
Return | ResourceKeys extends ResourcePath<Target> ? ResourceValue<Target, ResourceKeys<ResourceKeys>> : Record<string, any> |
Parameters
| Parameter | Type | Description |
|---|---|---|
key | Key | ResourceKeys | A target locale message key |
Returns
Return
Locale messages
Remarks
If I18nScope 'local' or Some UseI18nOptions are specified at useI18n, it’s translated in preferentially local scope locale messages than global scope locale messages.
Based on the current locale, locale messages will be returned from Composer instance messages.
If you change the locale, the locale messages returned will also correspond to the locale.
If there are no locale messages for the given key in the composer instance messages, they will be returned with fallbacking.
WARNING
You need to use rt for the locale message returned by tm. see the rt details.
Example
template block:
<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>script block:
import { defineComponent } from 'vue
import { useI18n } from 'vue-i18n'
export default defineComponent({
setup() {
const { rt, tm } = useI18n({
messages: {
en: {
contents: [
{
title: 'Title1',
// ...
paragraphs: [
// ...
]
}
]
}
}
// ...
})
// ...
return { ... , rt, tm }
}
})Properties
availableLocales
readonly availableLocales: ComputedRef<Locales[]>;Remarks
The list of available locales in messages in lexical order.
d
d: ComposerDateTimeFormatting<DateTimeFormats, Locales, RemoveIndexSignature<{
[key: string]: DateTimeFormatOptions;
}>>;Datetime formatting
Remarks
About details functions, See the ComposerDateTimeFormatting
datetimeFormats
readonly datetimeFormats: ComputedRef<{ [K in string | number | symbol]: DateTimeFormats[K] }>;Remarks
The datetime formats of localization.
See about:
escapeParameter
escapeParameter: boolean;Remarks
Whether interpolation parameters are escaped before the message is translated.
See about:
fallbackFormat
fallbackFormat: boolean;Remarks
Whether suppress warnings when falling back to either fallbackLocale or root.
See about:
fallbackLocale
fallbackLocale: WritableComputedRef<FallbackLocales<Locales>>;Remarks
The current fallback locales this Composer instance is using.
See about:
fallbackRoot
fallbackRoot: boolean;Remarks
Whether to fall back to root level (global scope) localization when localization fails.
See about:
fallbackWarn
fallbackWarn: boolean | RegExp;Remarks
Whether suppress fall back warnings when localization fails.
See about:
id
id: number;Remarks
Instance ID.
inheritLocale
inheritLocale: boolean;Remarks
Whether inherit the root level locale to the component localization locale.
See about:
isGlobal
readonly isGlobal: boolean;Remarks
Whether this composer instance is global or not
locale
locale: WritableComputedRef<Locales>;Remarks
The current locale this Composer instance is using.
If the locale contains a territory and a dialect, this locale contains an implicit fallback.
See about:
messages
readonly messages: ComputedRef<{ [K in string | number | symbol]: Messages[K] }>;Remarks
The locale messages of localization.
See about:
missingWarn
missingWarn: boolean | RegExp;Remarks
Whether suppress warnings outputted when localization fails.
See about:
modifiers
readonly modifiers: LinkedModifiers<VueMessageType>;Remarks
Custom Modifiers for linked messages.
See about:
n
n: ComposerNumberFormatting<NumberFormats, Locales, RemoveIndexSignature<{
[key: string]: NumberFormatOptions;
}>>;Number Formatting
Remarks
About details functions, See the ComposerNumberFormatting
numberFormats
readonly numberFormats: ComputedRef<{ [K in string | number | symbol]: NumberFormats[K] }>;Remarks
The number formats of localization.
See about:
pluralRules
readonly pluralRules: PluralizationRules;Remarks
A set of rules for word pluralization
See about:
rt
rt: ComposerResolveLocaleMessageTranslation<Locales>;Resolve locale message translation
Remarks
About details functions, See the ComposerResolveLocaleMessageTranslation
t
t: ComposerTranslation<Messages, Locales, RemoveIndexSignature<{
[key: string]: LocaleMessageValue<VueMessageType>;
}>>;Locale message translation
Remarks
About details functions, See the ComposerTranslation
warnHtmlMessage
warnHtmlMessage: boolean;Remarks
Whether to allow the use locale messages of HTML formatting.
If you set false, will check the locale messages on the Composer instance.
If you are specified true, a warning will be output at console.
See about: