Skip to content

vue-i18n / general / MessageContext

Interface: MessageContext<T>

Vue I18n General

The message context.

Type Parameters

Type ParameterDefault type
Tstring

Methods

linked()

Call Signature

ts
linked(key, modifier?): MessageType<T>;

Resolve linked message.

Parameters
ParameterTypeDescription
keystringA message key
modifier?stringA modifier
Returns

MessageType<T>

A resolve message.

Call Signature

ts
linked(
   key, 
   modifier?, 
type?): MessageType<T>;

Overloaded linked

Parameters
ParameterTypeDescription
keystringA message key
modifier?stringA modifier
type?stringA message type
Returns

MessageType<T>

A resolve message.

Call Signature

ts
linked(key, options?): MessageType<T>;

Overloaded linked

Parameters
ParameterTypeDescription
keystringA message key
options?LinkedOptionsAn LinkedOptions | linked options
Returns

MessageType<T>

A resolve message.


list()

ts
list(index): unknown;

Resolve message value from list.

Parameters

ParameterTypeDescription
indexnumberAn index of message values.

Returns

unknown

A resolved message value.

Example

js
const messages = {
  en: {
    greeting: ({ list }) => `hello, ${list(0)}!`
  }
}

named()

ts
named(key): unknown;

Resolve message value from named.

Parameters

ParameterTypeDescription
keystringA key of message value.

Returns

unknown

A resolved message value.

Example

js
const messages = {
  en: {
    greeting: ({ named }) => `hello, ${named('name')}!`
  }
}

plural()

ts
plural(messages): T;

Resolve message with plural index.

Parameters

ParameterTypeDescription
messagesT[]the messages, that is resolved with plural index with translation function.

Returns

T

A resolved message.

Remarks

That's resolved with plural index with translation function.

Example

js
const messages = {
  en: {
    car: ({ plural }) => plural(['car', 'cars']),
    apple: ({ plural, named }) =>
      plural([
        'no apples',
        'one apple',
        `${named('count')} apples`
      ])
  }
}

Properties

type

ts
type: string;

The message type to be handled by the message function.

Remarks

Usually text, you need to return string in message function.


values

ts
values: Record<string, unknown>;

The message values.

Remarks

The message values are the argument values passed from translation function, such as $t, t, or translate.

Example

vue-i18n $t (or t) case:

html
<p>{{ $t('greeting', { name: 'DIO' }) }}</p> <!-- `{ name: 'DIO' }` is message values -->

@intlify/core (@intlify/core-base) translate case:

js
translate(context, 'foo.bar', ['dio']) // `['dio']` is message values

Released under the MIT License.