<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 dictionaries.
Reference
Props
Prop | Type | Default |
---|---|---|
children | ReactNode | - |
projectId | string | - |
id? | string | undefined |
dictionary? | Dictionary | defaultDictionary |
locales? | string[] | - |
defaultLocale? | string | libraryDefaultLocale |
locale? | string | - |
cacheUrl? | string | 'https://cdn.gtx.dev' |
runtimeUrl? | string | 'https://runtime.gtx.dev' |
renderSettings? | RenderSettings | defaultRenderSettings |
_versionId? | string | - |
devApiKey? | string | - |
metadata? | object | - |
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. |
projectId? | The project ID required for General Translation cloud services. |
id? | The ID of a nested dictionary to limit the data sent to the client. This is useful for large projects with extensive dictionaries. |
dictionary? | The translation dictionary for the project. |
locales? | The list of approved locales for the project. |
defaultLocale? | The default locale to use if no other locale is found. |
locale? | The current locale, if already set. |
cacheUrl? | The URL of the cache service for fetching translations. |
runtimeUrl? | The URL of the runtime service for fetching translations. |
renderSettings? | The settings for rendering translations. |
_versionId? | The version ID for fetching translations. |
devApiKey? | The API key for development environments. |
metadata? | Additional metadata to pass to the context. |
Returns
React.JSX.Element|undefined
containing the children that were passed to this component.
Examples
Basic usage
Wrap your application in <GTProvider>
to add translation to your app.
Don't forget to add a list of supported locales to enable translation.
Dictionaries
You can also pass a dictionary to the <GTProvider>
component and then access it with the useDict()
hook.
For more information on using dictionaries, check out this guide.
Adding configuration
If you're not a fan of passing props directly to the <GTProvider>
component, you can create a configuration file and pass it to the component.
It also directly integrates with the gt-react-cli translate
command, so you don't have to specify things like locales manually as a parameter.
All you have to do is just pass this to the <GTProvider>
component.
Custom translation loader
You can use the loadTranslation
prop to load translations from a custom source.
This is useful when you need to load translations from a different source, such as a custom API.
Notes
- The
<GTProvider>
must wrap all<T>
components and other translation-related functions. Learn more here.
Next steps
- Learn more about the
<T>
component for translating text and components. - Check out translation components and functions:
<T>
,useGT()
, oruseDict()
.