Change Language Code Within Url Javascript/nodejs
I have common header file includes navbar in which have multilanguage dropdown. when i select dropdown language, translates page without any issues. But when i move to other pages,
Solution 1:
- on
load
see if language is set or not incookie
. - set selected language in
cookie
onsetLanguage
call.
$(document).ready(function() {
//read previously set cookie value
var selectedLanguage = $.cookie( 'selectedLanguage' );
// 1. on load see if language is set or not in cookie.
selectedLanguage = selectedLanguage ? selectedLanguage : 'en';
setLanguage(selectedLanguage);
function setLanguage(lan){
$.cookie('selectedLanguage', lan);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js" integrity="sha256-1A78rJEdiWTzco6qdn3igTBv9VupN3Q1ozZNTR4WE/Y=" crossorigin="anonymous"></script>
Post a Comment for "Change Language Code Within Url Javascript/nodejs"