UNPKG

2gis-maps

Version:

Interactive 2GIS maps API, based on Leaflet

75 lines (62 loc) 2.43 kB
<!DOCTYPE html> <html lang="it"> <head> <title>DGLocale demo</title> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="http://maps.api.2gis.ru/2.0/loader.js"></script> </head> <body> <div id="map" style="width: 100%; height: 600px; border: 1px solid #ccc;"></div> <script type="text/javascript"> var map; DG.then(function () { // plugin code // {APP_CORE}/src/{Plugin}/{Plugin}.js DG.LocaleExample = DG.Control.extend({ includes: DG.Locale, options: { position: 'topright' }, statics: { Dictionary: {} }, _container: null, onAdd: function (map) { this._container = DG.DomUtil.create('div', 'locale-example'); this._renderTranslation(); return this._container; }, //this function will be called every time when we change language _renderTranslation:function () { this._container.innerHTML = '<h1>' + this.t("{n} people", 16700000) + ' ' + this.t("regularly use 2GIS") + '</h1>'; } }); //{APP_CORE}/src/{Plugin}/lang/it.js DG.LocaleExample.Dictionary.it = DG.extend({ "{n} people" : ["{n} utente", "{n} utenti"], "regularly use 2GIS" : "utilizzano regolarmente 2GIS" }, DG.Dictionary.it); //{APP_CORE}/src/{Plugin}/lang/ru.js DG.LocaleExample.Dictionary.ru = DG.extend({ "{n} people" : ["{n} пользователь", "{n} пользователя", "{n} пользователей"], "regularly use 2GIS" : "регулярно используют 2GIS" }, DG.Dictionary.ru); //{APP_CORE}/src/{Plugin}/demo/index.html map = new DG.Map('map', { center: new DG.LatLng(54.980206086231, 82.898068362003), zoom: 13 }); map.addControl(new DG.LocaleExample()); var langMenu = DG.DomUtil.get('langMenu'); langMenu.onchange = function() { map.setLang(this.options[this.selectedIndex].value); } }); </script> Изменить язык карты: <select id="langMenu" size="1"> <option value="ru" selected="selected">ru</option> <option value="it">it</option> </select> </body> </html>