I need to change language in yandex maps, but I don't know how do it! Language in yandex maps can be changed static in script tag.
<script src="http://api-maps.yandex.ru/2.1/?lang=ru_RU&load=package.full"></script>
But I need to change language in running application.
For example, google maps have loader:
HTML Code
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
JavaScript Code
google.load('maps', '3.7', {
'other_params' : 'sensor=true&language=' + langCode,
'callback' : deviceReadyFunc
});
In yandex maps I have not found.
Solve this problem with localStorage and dynamic adding script-tag.
JavaScript Code
var script=document.createElement('script');
if (GLOBAL_LANGUAGE === 'en') {
script.src = 'http://api-maps.yandex.ru/2.1/?lang=en-US&load=package.full';
} else {
script.src = 'http://api-maps.yandex.ru/2.1/?lang=ru-RU&load=package.full';
}
document.getElementsByTagName('body')[0].appendChild(script);
script.onload = function() {
ymaps.ready(init);
};
In running application after change localStorage variable GLOBAL_LANGUAGE
I call reloadApp()
method:
reloadApp: function() {
location.href = '#home';
location.reload();
}
After this actions yandex maps change language in running application.