Sunday, January 9, 2011

Google Translation

I would like to share a Google Translate JavaScript plug-in.
To add a translation to your web pages you can use JavaScript and Google translate services.


Here is a sample that add a translate combo box to your page:
// define div tag where translation combobox will be placed
<div id="google_translate_element">
</div>


// define "new" translate element function  
<script>
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'uk',

    includedLanguages: 'et,tl',
  }, 'google_translate_element');
}
</script>


// add all necessary sources to do the translation 
<script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

pros:
- easy to use 
- using it you can create a copy of your blog/site to other languages 

cons:
- not all languages supported 
- engine itself is quite new and translation is not perfect


if you need translation to any language remove includedLanguages parameter

There are some useful links that may help you with building your copy:

No comments: