Copy link to clipboard
Copied
Hi everyone.
As I develop multi-lingual web sites, I find it practical when the visitor, upon changing the language, doesn't find himself at the index page to re-do all the work to get to the page where he was.
For that I use a different directory for each language.
I have a script that helps me change the directory dynamically. Here it is:
var lang_arr = ['en', 'de', 'fr', 'it', 'tr']; // define here available languages
function change_url(new_lang) {
if (!inArray(new_lang, lang_arr)) return false;
var url_pieces = document.location.pathname.split('/');
for (i = 0; i < url_pieces.length; i++) {
if (inArray(url_pieces, lang_arr)) {
url_pieces = new_lang;
window.location.href = document.location.origin + url_pieces.join('/') + document.location.search;
}
}
}
function inArray(needle, haystack) {
var length = haystack.length;
for (var i = 0; i < length; i++) {
if (haystack == needle) return true;
}
return false;
}
I have put that in the HTML for <head> of the page properties in the master page.
I then put a link on the page with the following in the Hyperlinks:
javascript:;" onclick="change_url('en')"
Why doesn't work? What am I missing? Any suggestions?
Jim
I hope you use tags <script></script>?
....Try to put your script before </body>. Use the following file.
Insert your code.
Save the file and place it on the page. ( File / Place)
Copy link to clipboard
Copied
I hope you use tags <script></script>?
....Try to put your script before </body>. Use the following file.
Insert your code.
Save the file and place it on the page. ( File / Place)
Copy link to clipboard
Copied
Thanks. In fact as you put it out, I had forgotten the <script> and </script> tags. It now works just fine.
Copy link to clipboard
Copied
hi, can you help me i need something like you, but i dont know how to do that if you can upload a text about it to learn step by step plz