Reputation: 191
I am trying to create multilingual website using jquery.I just wanted to translate web content to another language automatically without page refresh..I was searching for this .. but most of them were like adding equivalent translated content for the default language..but I don't want to add the other language content manually and I want to achieve the translation with in the site instead of going Google translation page..so any one can assist me the best way to achieve this..if there is any package to do so please let me know.. Thanks in advance
Upvotes: 1
Views: 570
Reputation: 1047
You could do this, but bear in mind that you would need to request google's APIs every time you want to translate a text on your website and that translations may be wrong (Everyone can submit translations to translation services like google, turkish "üüüüüüüüüüüüüüüü" translated to "Pokemon" a while ago)
You would need some kind of <span class="translate-me">This is my text</span>
and a javascript like
$( '.translate-me' ).each( function() {
var textToTranslate = $( this ).text();
var translatedText = '';
$.ajax( {...} ); //request to google translate api
$( this ).text( translatedText );
} );
The best approach is using simple PHP and a fine translation system that has all translations stored in XML/PHP files or in the database, if you managed to keep your PHP code clean, maintainable and fast, there shouldn't be any problems.
You shouldn't really optimize pages to have no page-reloads, if you actually change the whole page with your actions
Having small parts of the page loading content without a reload is the real purpose of AJAX
Upvotes: 2