Localization
Gravity supports client-side localisation with the i18next package. The section explains how to translate the client side UI.
Last updated
Was this helpful?
Gravity supports client-side localisation with the i18next package. The section explains how to translate the client side UI.
Last updated
Was this helpful?
Locale files are stored inside the /src/locales
folder, and each language has its own folder of .json
files. The locales are split to match the same structure as the views.
All .json
files inside each locale folder are automatically imported and combined, so you can add more JSON files without explicitly importing them anywhere.
The locale files are simple JSON files containing the strings. The keys are always the same (in English) as these are referenced in the code. The string changes depending on the language.
Create a new folder inside the /locales
file with the local name eg. /fr
and add your JSON files.
Import the locale to app.js
and add it to the resources
section of the i18n config
.
Translations can be performed in three ways:
Using the useTranslation
hook (available anywhere)
Using props.t
(available in all View
components inside /views
)
Using ViewContext
(available anywhere)
To translate the table headers, you can pass the a string reference to the translation object to the translation
prop of the <Table/>
. The JSON object should be named header
.
There is a language switcher component at the top right of the UI for changing the language. You can add more languages to the dropdown in /components/locale
. You will need to import any additional flags you want to use.
Pro tip – ask to translate the JSON files to new languages.