There is such a code. It is necessary that the default language be set, and a message is displayed in this language by alert Your language RU | or | ENG . A message was also displayed in the selected language which is taken from the span. Spans in sss hide.

.lang { display: none; } .lang.visible { display: inline; visibility: hidden; font: 1em sans-serif; } 
  <div id="languages"> <label> <input type="radio" name="lang">RU </label> <label> <input type="radio" name="lang">ENG </label> </div> <div id="welcome-message"> <span class="lang lang-ru">Привет</span> <span class="lang lang-eng">Hello</span> , username! <span class="lang lang-ru">Рады тебя видеть!</span> </div> <button id="save">Save</button> 

Here is the code that I think can be used:

 var applyLanguage = function (lang) { alert('now language is: ' + lang); } var getCurrentLanguage = function () { var defaultLanguage = 'ru'; // return defaultLanguage; } var currentLang = getCurrentLanguage(); var langEls = document.getElementsByClassName('lang-' + currentLang); for (var i=0; i<langEls.length; i++) { var langEl = langEls[i]; // langEl.style.display = 'inline'; langEl.classList.add('visible'); } // $<prefix> == DOMElement var $save = document.querySelector('html body button#save') $save.addEventListener('click', function(){ alert(1); }); 

But I don’t know what's next

  • this can be realized in many ways .. for example, if a website is static then a json file is created and already on js we pull out the necessary json by clicking on it or just a few pages with Russian texts and English ... and when clicking on eng ru we simply follow the links, and But if a dynamic site ... hm - user33274
  • if the site is dynamic, then we store two types of text in the database and output the information we need on demand / request .. for wordpress there are a lot of translator plugins ... - user33274
  • This is not something for the site, I try it for myself, I threw the code that I think to implement - Artem Chepeliuk
  • well, then just ... make for example two pages .. one for ru, another for en and within the links are usual from one to another ... - user33274

0