Localisation
Gravity Native supports client-side localisation with the i18n-js package. The section explains how to translate the native UI.
Last updated
Was this helpful?
Gravity Native supports client-side localisation with the i18n-js package. The section explains how to translate the native UI.
Last updated
Was this helpful?
Locale files are stored inside the /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 imported and combined inside the index.js file inside each locale folder. You need to import all of your individual locale files into the index file.
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 new locale file into the index.js
file
Import the locale to app.js
and add it to I18n config object.
Translations can be performed by importing the i18n
package and using the t function.
There is a language switcher component in the drawer nav for changing the language. You can add more languages to the dropdown in /components/locale
.
Pro tip – ask to translate the JSON files to new languages.