MapStore offers the support for internationalization (I18N). To provide this functionality MapStore uses react-intl. In this section you can find which configuration and JS files are involved in the I18N system.
How MapStore chooses the current language
MapStore first checks the browser's language. If it is not supported, MapStore will be visible in english, if present, or the first language available. Anyway the locale can be forced using a flag locale=codeLang where codeLang can be one en,it,de... e.g.
A user can change the selected language from UI. MapStore will load the proper files to update the page localized in the selected language.
To provide support to a specific language MapStore need to have the necessary setup in the LocaleUtils.js file (see below [section for details about to configure this file]). In addition you need the proper translations files.
Let's imagine that the variable code is 'en', CODE is 'EN' standing for english. For each language you need to have messages file containing the localized strings, a flag image to identify the language and some html fragments (optional) for some specific plugins.
- Messages: located in
web\client\translationsfolder. For each language there is a json file named data.code-CODE.json. e.g.
- Flags: located in
web\client\components\I18N\images\flagsfolder. For each language flag image named code-CODE.png of 16px x 11px is required.
- Fragments: actually only for cookies policy .... (required only if the Cookie plugin is present) located in
web\client\translations\fragments\cookiefolder and named cookieDetails-code-CODE.html. We recommend to add it for any language you want to support at least by copying the english version.
How to configure supported languages in MapStore
You can configure MapStore to provide to the user only a restricted list of selectable languages by setting "initialState.defaultState.locales" variable in
localConfig.json. e.g :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Setting locales in localConfig.json file is doable only for supported locales present in LocaleUtils.js. The default behavior is to use those already configured in "supportedLocales" object. You can customize the messages by editing the data.code-CODE.json files.
locale property determines the language to use for the application. If not specified, the language will be selected checking the browser's locale first. If the browser locale is not supported, MapStore will select the first language available in
Example of localConfig.json with the optional locale property.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
locale could be useful inside custom application where the locale is stored in other sources rather than using the browser language:
1 2 3 4 5 6 7 8 9 10
How to add a new language
Let's say we want to add the russian language. In order to add a new language to MapStore you need to follow these steps:
- Update the
web\clientfolder adding the new language entry: Add the following in the
1 2 3 4
- Update the LocaleUtils.js file in
web\client\utils: add a param in the ensureIntl() function like and the relative require i.e:
- update the addLocaleData() call with the new locale obj i.e.:
- add the flag image for the selected language inside
- add the new translations file inside
data.ru-RU.json(remember to change the locale property of this file into
- create a fragment related to the cookie module inside