InlineTranslationOptions
API reference for the InlineTranslationOptions type
Overview
The InlineTranslationOptions type is used to pass variables to inline translations and specify their render behaviour.
You can also add context and an identifier to the translation.
It’s used with useGT and msg to pass variables to inline string translations.
Build-time translation:
useGT and msg translations happen at build time; however, variables are never translated.
Instead, they’re inserted into the translation with formatting.
Make sure to follow the deployment guide here.
Reference
Parameters
Prop
Type
Description
| Prop | Description |
|---|---|
variables | An object in which the keys specify where each value is mapped within the string. |
$context | Optionally include $context as a variable in the variables object to provide context for the content (used for translation). |
$id | Optionally include $id as a variable in the variables object to provide an identifier for use with the translation editor. |
Examples
Context
To add context to a string, use the $context prop.
import { useGT } from 'gt-react';
const Component = () => {
const t = useGT();
return <div>{t('Hello, world!', { $context: 'a formal greeting' })}</div>;
};Passing variables
To add a variable to the string, use the {variable-name} syntax, where curly braces wrap the variable name.
import { useGT } from 'gt-react';
const Component = () => {
const t = useGT();
return <div>{t('Hello, {username}! How\'s your day going?', { username: 'Brian123' })}</div>;
};Using the ICU message format
gt-react supports the ICU message format, which also lets you format your variables.
import { useGT } from 'gt-react';
const Component = () => {
const t = useGT();
return <div>
{ t(
'Your account balance: {dollars, number, ::currency/USD}!',
{
"dollars" : 1000000,
}
) }
</div>;
};See the ICU message format documentation for more information on the ICU message format.
Notes
InlineTranslationOptionsis used for inline string translations.- The
variablesobject passes values into the text. - The
variablesOptionsobject defines how the variables behave.
Next steps
- See
useGTfor more information on inline string translations. - See
ICU message formatfor more information on formatting options.
How is this guide?