jquery - How to change the language in multiple pages at once? -
i have dropdown button offers 2 languages, native , english. thing is, when change in english, changes text on page, rest of pages still in native. script connected of them. there missed do? here code dropdown:
<div class="dropdown pull-right"> <button class="btn btn-success dropdown-toggle btn-lg" id="menu1" type="button" data-toggle="dropdown">Јазик / language <span class="caret"></span></button> <ul class="dropdown-menu" role="menu" aria-labelledby="menu1"> <li role="presentation" value="1"><a role="menuitem" tabindex="-1" href="#">Македонски</a></li> <li role="presentation" value="2"><a role="menuitem" tabindex="-1" href="#">english</a></li> </ul> </div>
and here how change text in script. these 2 two pages in site:
$("ul li").on('click', function () { var val = $(this).val(); if(val==2){ $("#buy").html("buy ticket"); $("#validate").html("validate ticket"); $("#q1").html("how many tickets buy?"); $("#back").html("back"); $("#q2").html("please enter" + "<span class='den'></span>" + "denars in slot labeled 'enter'"); $("#q3").html("please take ticket/s , change!"); $("#q4").html("thank you"); $("#q5").html("please show barcode on ticket in front of camera."); $("#q6").html("successful validation! thank you!"); }else{ $("#buy").html("Купи карта"); $("#validate").html("Валидирај карта"); $("#q1").html("Колку карти сакате да купите?"); $("#back").html("Назад"); $("#q2").html("Ве молиме внесете вредност од" + "<span class='den'></span>" + "денари во слотот назначен со „ВНЕСИ“."); $("#q3").html("Ве молиме подигнете ја/ги картата/те и кусурот."); $("#q4").html("Ви благодариме!"); $("#q5").html("Ве молиме покажете го баркодот од картата пред камерата"); $("#q6").html("Успешна валидација! Ви благодариме!"); } });
when navigate 1 page another, none of state of first page, or of javascript state, passed second page; second page loads scratch if first page had never existed.
i assume in pages navigation menu same across pages, though may identical across pages, what's happening when go page page b entire page, including common navigation stuff getting loaded , rendered scratch, in initial, pre-on-click state.
there multiple techniques can use pass bit of state 1 page next. scenario, easiest cookie.
what set cookie lang=1 or lang=2 whenever language changed. make language switching code separate function can called on-click, on page load (or page ready). on page load/ready, if lang cookie present, call language switching function value of lang cookie. pages have same code click , page load/ready.
Comments
Post a Comment