<GTProvider>
API Reference for the <GTProvider> component
Overview
The <GTProvider>
component provides General Translation (GT) context to its children, enabling them to access translated content.
It is required for any client-side translations on your application.
When to Use
- Wrap your entire application in
<GTProvider>
to enable translations on the client. - When working with dictionaries, optionally specify an
id
to limit the dictionary data sent to the client, optimizing performance for large dictionaries. - The
<GTProvider>
component is used for both inline<T>
and dictionary design patterns.
Reference
Props
Prop | Type | Default |
---|---|---|
children | ReactNode | - |
id? | string | undefined |
Description
Prop | Description |
---|---|
children | Any component or the parents of any component that needs to translate or access translation information on the client side. These should include any components using <T> , useGT , or other translation utilities. |
id? | The ID of a nested dictionary to limit the data sent to the client. This is useful for large projects with extensive dictionaries. |
Returns
JSX.Element|undefined
containing the children that were passed to this component.
Examples
Basic usage
Wrap your application in <GTProvider>
to provide translation context to your app.
If you are in development, you can use the devApiKey
prop to specify a development API key.
This will give you access to fast translations and will not cache any content in the CDN.
Once you are ready to deploy you can just leave the devApiKey
prop as undefined
,
and add your production api key to your environment.
Any translations created with the production api key will be distributed to the global CDN.
Supported locales
This example configures gt-react
with English (en-US
) as the default locale.
It exclusively supports translations in Spanish (es
) and French (fr
), and provides a description for context-aware translation.
The site will fallback to the best suited language if none of the locales match.
It will look for matching languages (i.e., en-US
and en-GB
), as well as the other preferred languages the user has set in their browser.
If all else fails, then it will fallback to the default language.
If you want to support all languages, leave locales
blank.
Additionally, locales can be configured on the GT dashboard.
Using the id
prop for subsets
Specify the id
prop to select a subset of the dictionaries
for translation.
In this example, any useGT()
and useElement()
hooks will only have access to the prefix1.prefix2
subset of the dictionary.
Notes
- The
<GTProvider>
must wrap all<T>
components and other translation-related components in client components. Read more about it here. - For server-side translations,
<GTProvider>
is not required but can still be used.
Next steps
- Learn more about the
<T>
component for translating text and components. - See i18n configuration for advanced customization options.