Maps API provides a possibility to display elements of user interface in several languages. The translation of the tiles in this case is not provided, as the labels on the tiles correspond to the language of the displayed country.

The default language is the same as that of the root html tag:

<html lang="it">

If the language is not specified in the root tag, then the default language — Russian — will be used.

Get or dynamically change the language using the corresponding methods of the map setLang:

map.getLang(); // returns 'it'

Currently supports the following languages:

  • en — English;
  • ru — Russian;
  • it — Italian;
  • cs — Czech;
  • es — Spanish.


Performs the translation of the user interface.

Adds two methods to the map: setLang and getLang. There is also a DG object.Locale object, which you can add to any external module, and there will appear the t method which you can use to perform a translation. Classes of modules, to which DG.Locale is added must contain the _map property and the Dictionary static property inside.

The basic dictionary for all dictionaries is DG.Dictionary, which stores the translation rules for words in plural forms (plural rules). When you create a module which uses its own dictionaries, you need to put them to the lang folder. For example, if you want to use Italian and Russian languages, you need to create the lang/it.js and lang/ru.js files. Examples of creation of dictionaries are given below.

Example of usage

Mixing of localization features to the module:

DG.LocaleExample = DG.Control.extend({
    includes: DG.Locale,
    statics: {
        Dictionary: {}

Subscribe to the langchange event:

this._map.on('langchange', this._updateText, this);

The translation of the string to the current language of the map:

container.innerHTML = this.t("{n} people", 16700000) + ' ' + this.t("regularly use 2GIS");

Create your own dictionaries in Italian and Russian:

lang/it.js file contents:

DG.LocaleExample.Dictionary.it = DG.extend({
    "{n} people" : ["{n} utente", "{n} utenti"],
    "regularly use 2GIS" : "utilizzano regolarmente 2GIS"
}, DG.Dictionary.it);

lang/ru.js file contents:

 DG.LocaleExample.Dictionary.ru = DG.extend({
    "{n} people" : ["{n} пользователь", "{n} пользователя", "{n} пользователей"],
    "regularly use 2GIS" : "регулярно используют 2GIS"
}, DG.Dictionary.ru);