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?
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.
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.
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 onsettimeout()
on your page.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.
check this plugin out:
http://keith-wood.name/localisation.html
It changes language 'on the fly' without going back to server side.
Image reload prototype if-modified i posted about image content update to selected language without reloading the page.
The image takes the value thats sent and updates to language/country code (which is bound to language) on DB and updates image content (characters) to match their keyboard layout..
Hope its some use
精彩评论