vue-i18n / general / MessageContext
Interface: MessageContext<T>
Vue I18n General
The message context.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | string |
Methods
linked()
Call Signature
linked(key, modifier?): MessageType<T>;Resolve linked message.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | A message key |
modifier? | string | A modifier |
Returns
MessageType<T>
A resolve message.
Call Signature
linked(
key,
modifier?,
type?): MessageType<T>;Overloaded linked
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | A message key |
modifier? | string | A modifier |
type? | string | A message type |
Returns
MessageType<T>
A resolve message.
Call Signature
linked(key, options?): MessageType<T>;Overloaded linked
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | A message key |
options? | LinkedOptions | An LinkedOptions | linked options |
Returns
MessageType<T>
A resolve message.
list()
list(index): unknown;Resolve message value from list.
Parameters
| Parameter | Type | Description |
|---|---|---|
index | number | An index of message values. |
Returns
unknown
A resolved message value.
Example
const messages = {
en: {
greeting: ({ list }) => `hello, ${list(0)}!`
}
}named()
named(key): unknown;Resolve message value from named.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | A key of message value. |
Returns
unknown
A resolved message value.
Example
const messages = {
en: {
greeting: ({ named }) => `hello, ${named('name')}!`
}
}plural()
plural(messages): T;Resolve message with plural index.
Parameters
| Parameter | Type | Description |
|---|---|---|
messages | T[] | 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
const messages = {
en: {
car: ({ plural }) => plural(['car', 'cars']),
apple: ({ plural, named }) =>
plural([
'no apples',
'one apple',
`${named('count')} apples`
])
}
}Properties
type
type: string;The message type to be handled by the message function.
Remarks
Usually text, you need to return string in message function.
values
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:
<p>{{ $t('greeting', { name: 'DIO' }) }}</p> <!-- `{ name: 'DIO' }` is message values -->@intlify/core (@intlify/core-base) translate case:
translate(context, 'foo.bar', ['dio']) // `['dio']` is message values