Skip to content

vue-i18n / general / ComposerTranslation

Interface: ComposerTranslation()<Messages, Locales, DefinedLocaleMessage, C, M, ResourceKeys>

Vue I18n Composition

Locale message translation functions

Remarks

This is the interface for Composer

Type Parameters

Type ParameterDefault type
Messages extends Record<string, any>object
Locales"en-US"
DefinedLocaleMessage extends RemovedIndexResources<DefineLocaleMessage>RemovedIndexResources<DefineLocaleMessage>
CIsEmptyObject<DefinedLocaleMessage> extends false ? JsonPaths<{ [K in keyof DefinedLocaleMessage]: DefinedLocaleMessage[K] }> : never
MIsEmptyObject<Messages> extends false ? TranslationsPaths<Messages> : never
ResourceKeys extends C | MIsNever<C> extends false ? IsNever<M> extends false ? C | M : C : IsNever<M> extends false ? M : never

Call Signature

ts
ComposerTranslation<Key>(key): string;

Locale message translation

Type Parameters

Type Parameter
Key extends string

Parameters

ParameterTypeDescription
keynumber | ResourceKeys | KeyA target locale message key

Returns

string

Translated message

Remarks

If this is used in a reactive context, it will re-evaluate once the locale changes.

If I18nScope 'local' or Some UseI18nOptions are specified at useI18n, it’s translated in preferentially local scope locale messages than global scope locale messages.

If not, then it’s translated with global scope locale messages.

See about:

Call Signature

ts
ComposerTranslation<Key>(key, plural): string;

Locale message translation for plurals

Type Parameters

Type Parameter
Key extends string

Parameters

ParameterTypeDescription
keynumber | ResourceKeys | KeyA target locale message key
pluralnumberWhich plural string to get. 1 returns the first one.

Returns

string

Translated message

Remarks

Overloaded t.

In this overloaded t, return a pluralized translation message.

You can also suppress the warning, when the translation missing according to the options.

See about:

Call Signature

ts
ComposerTranslation<Key>(
   key, 
   plural, 
   options): string;

Locale message translation for plurals

Type Parameters

Type Parameter
Key extends string

Parameters

ParameterTypeDescription
keynumber | ResourceKeys | KeyA target locale message key
pluralnumberWhich plural string to get. 1 returns the first one.
optionsTranslateOptions<Locales>Additional options for translation

Returns

string

Translated message

Remarks

Overloaded t.

In this overloaded t, return a pluralized translation message.

You can also suppress the warning, when the translation missing according to the options.

About details of options, see the TranslateOptions.

See about:

Call Signature

ts
ComposerTranslation<Key>(key, defaultMsg): string;

Locale message translation for missing default message

Type Parameters

Type Parameter
Key extends string

Parameters

ParameterTypeDescription
keynumber | ResourceKeys | KeyA target locale message key
defaultMsgstringA default message to return if no translation was found

Returns

string

Translated message

Remarks

Overloaded t.

In this overloaded t, if no translation was found, return a default message.

You can also suppress the warning, when the translation missing according to the options.

Call Signature

ts
ComposerTranslation<Key>(
   key, 
   defaultMsg, 
   options): string;

Locale message translation for missing default message

Type Parameters

Type Parameter
Key extends string

Parameters

ParameterTypeDescription
keynumber | ResourceKeys | KeyA target locale message key
defaultMsgstringA default message to return if no translation was found
optionsTranslateOptions<Locales>Additional options for translation

Returns

string

Translated message

Remarks

Overloaded t.

In this overloaded t, if no translation was found, return a default message.

You can also suppress the warning, when the translation missing according to the options.

About details of options, see the TranslateOptions.

Call Signature

ts
ComposerTranslation<Key>(key, list): string;

Locale message translation for list interpolations

Type Parameters

Type Parameter
Key extends string

Parameters

ParameterTypeDescription
keynumber | ResourceKeys | KeyA target locale message key
listunknown[]A values of list interpolation

Returns

string

Translated message

Remarks

Overloaded t.

In this overloaded t, the locale messages should contain a {0}, {1}, … for each placeholder in the list.

You can also suppress the warning, when the translation missing according to the options.

See about:

Call Signature

ts
ComposerTranslation<Key>(
   key, 
   list, 
   plural): string;

Locale message translation for list interpolations and plurals

Type Parameters

Type Parameter
Key extends string

Parameters

ParameterTypeDescription
keynumber | ResourceKeys | KeyA target locale message key
listunknown[]A values of list interpolation
pluralnumberWhich plural string to get. 1 returns the first one.

Returns

string

Translated message

Remarks

Overloaded t.

In this overloaded t, the locale messages should contain a {0}, {1}, … for each placeholder in the list, and return a pluralized translation message.

See about:

Call Signature

ts
ComposerTranslation<Key>(
   key, 
   list, 
   defaultMsg): string;

Locale message translation for list interpolations and missing default message

Type Parameters

Type Parameter
Key extends string

Parameters

ParameterTypeDescription
keynumber | ResourceKeys | KeyA target locale message key
listunknown[]A values of list interpolation
defaultMsgstringA default message to return if no translation was found

Returns

string

Translated message

Remarks

Overloaded t.

See about:

In this overloaded t, the locale messages should contain a {0}, {1}, … for each placeholder in the list, and if no translation was found, return a default message.

Call Signature

ts
ComposerTranslation<Key>(
   key, 
   list, 
   options): string;

Locale message translation for list interpolations

Type Parameters

Type Parameter
Key extends string

Parameters

ParameterTypeDescription
keynumber | ResourceKeys | KeyA target locale message key
listunknown[]A values of list interpolation
optionsTranslateOptions<Locales>Additional options for translation

Returns

string

Translated message

Remarks

Overloaded t.

In this overloaded t, the locale messages should contain a {0}, {1}, … for each placeholder in the list.

You can also suppress the warning, when the translation missing according to the options.

About details of options, see the TranslateOptions.

How to usage for details:

Call Signature

ts
ComposerTranslation<Key>(key, named): string;

Locale message translation for named interpolations

Type Parameters

Type Parameter
Key extends string

Parameters

ParameterTypeDescription
keynumber | ResourceKeys | KeyA target locale message key
namedNamedValueA values of named interpolation

Returns

string

Translated message

Remarks

Overloaded t.

In this overloaded t, for each placeholder x, the locale messages should contain a {x} token.

You can also suppress the warning, when the translation missing according to the options.

See about:

Call Signature

ts
ComposerTranslation<Key>(
   key, 
   named, 
   plural): string;

Locale message translation for named interpolations and plurals

Type Parameters

Type Parameter
Key extends string

Parameters

ParameterTypeDescription
keynumber | ResourceKeys | KeyA target locale message key
namedNamedValueA values of named interpolation
pluralnumberWhich plural string to get. 1 returns the first one.

Returns

string

Translated message

Remarks

Overloaded t.

In this overloaded t, for each placeholder x, the locale messages should contain a {x} token, and return a pluralized translation message.

See about:

Call Signature

ts
ComposerTranslation<Key>(
   key, 
   named, 
   defaultMsg): string;

Locale message translation for named interpolations and plurals

Type Parameters

Type Parameter
Key extends string

Parameters

ParameterTypeDescription
keynumber | ResourceKeys | KeyA target locale message key
namedNamedValueA values of named interpolation
defaultMsgstringA default message to return if no translation was found

Returns

string

Translated message

Remarks

Overloaded t.

In this overloaded t, for each placeholder x, the locale messages should contain a {x} token, and if no translation was found, return a default message.

See about:

Call Signature

ts
ComposerTranslation<Key>(
   key, 
   named, 
   options): string;

Locale message translation for named interpolations

Type Parameters

Type Parameter
Key extends string

Parameters

ParameterTypeDescription
keynumber | ResourceKeys | KeyA target locale message key
namedNamedValueA values of named interpolation
optionsTranslateOptions<Locales>Additional options for translation

Returns

string

Translated message

Remarks

Overloaded t.

In this overloaded t, for each placeholder x, the locale messages should contain a {x} token.

You can also suppress the warning, when the translation missing according to the options.

About details of options, see the TranslateOptions.

How to usage for details:

Released under the MIT License.