Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
23
rated 0 times [  27] [ 4]  / answers: 1 / hits: 16175  / 13 Years ago, sat, march 12, 2011, 12:00:00

I am working on a multilangual website right now.
I am currently including the related language file ('lange/_en.php') for language phrases.
To change languages users will select their language from a < select > item. The thing i want to do is changing related phrases (and urls too if possible) in the page without refreshing or submitting the page.



I remember i saw something like this in web but i have no idea where.



Any help or any ideas about how this thing can be done?


More From » php

 Answers
8

The issue with this is that a language change doesn't only affect a small section of the page, it affects the whole page. So really, you are left with three choices.




  1. The simple way which is indeed reloading the whole page. It's easy to implement, easy to maintain, and doesn't require you to make sure that JavaScript currently running on your page is aware of the new language at runtime.


  2. The complicated way which is getting all the new markup via AJAX and replacing the content of the <body> tag with the reloaded content. This will cause issues with other scripts running (such as image carousels, etc.) that holds a reference to an element so you have to reinitialize every single script that is running on settimeout() on your page.


  3. The close to impossible way which is to have a client side dictionary, selecting each relevant tag, and changing its contents with the new language. This is a pain to setup and a pain to maintain. You literally need a section tailored to each specific page. Again, if you have scripts with strings, you'll have to make sure that the strings they use are updated to the new language.




You are better off simply reloading the page. It will work without JavaScript and it's a one time deal that won't bother users.


[#93313] Thursday, March 10, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sam

Total Points: 711
Total Questions: 96
Total Answers: 107

Location: Burkina Faso
Member since Thu, Dec 23, 2021
2 Years ago
;