loadTranslation()
API Reference for the loadTranslation() function.
Overview
The loadTranslation()
function is the primary way to customize translation loading behavior.
In production, your translations need to be stored so that they can be rendered in your app.
By default, your translations will be stored in the GT CDN.
You can specify a loadTranslation()
function to get translations from a different source, such as:
- From your app's bundle (most common)
- From a database
- From an API
- From a different CDN
We have integrated support for loading translations from local files in your app's bundle. Follow this guide to set up local translations in your React app.
Reference
Parameters
Prop | Type | Default |
---|---|---|
locale | string | - |
Description
Type | Description |
---|---|
locale | The locale for which translations should be loaded. |
Returns
A Promise<any>
that resolves to either a string or JSX object containing the translations for the given locale.
Setup
You must import the loadTranslation()
function and assign it as a prop to the <GTProvider>
component.
Examples
Load translations from local files
When configured to use local translations, the gt-react-cli translate
command, translations are saved to the ./src/_gt
directory.
Load translations from your own CDN
Notes
loadTranslation()
gives you the ability to customize how translations are loaded in your app in production.- Its most common use case is for adding local translations
Next steps
- Learn about why you might want to use local translations