Skip to main content
Version: 4.x.x

Providing default value

Sometimes, it is also good to provide the default value of a translation directly in your code. The default value will be rendered when there is value missing in both current and fallback language.

To provide default value, just append it to the key with "," delimiter.

<h1>{{my_key,My default translation.}}<h1>

If you would like to use "," or ":" characters in your default value, you will have to escape them with "\" character.

<h1>{{my_key,Use backslash to escape \, or \: characters.}}<h1>

Using default when translating imperatively

To provide default value to translate method, provide it as defaultValue property of props object.

tg.translate({key: 'my_key', defaultValue: 'This is my default value.'})
.then(translation => ...);

or provide the value as 4th parameter.

tg.translate('my_key', undefined, undefined, 'This is my default value.')
.then(translation => ...);

You can do the same with instant method.

const translation = tg.instant({
key: 'my_key',
defaultValue: 'This is my default value.'}

or provide the value as 5th parameter.

const translation = tg.instant(
'This is my default value.'