Tuesday, July 27, 2010

Google 翻譯 API

<!-- Google翻譯的API -->
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
// load Google 翻譯的 API
google.load("language", "1");
// 處理翻譯
function translate()
{
  var lang = $j('#google_translation_language').val();
  switch (lang)
  {
    case 'zh-TW':
    case 'en':
    {
      var text = $j('#auction_item_description').html();
      google.language.translate(text, "ja", lang, function(result) {
        if (!result.error) {
          $j('#auction_item_description_translated').html(result.translation);
          $j('#auction_item_description_translated').removeClass('hidden');
          $j('#auction_item_description').addClass('hidden');
        }
        else alert(result.error.message);
      });
      break;
    }
    case 'original':
    default:
    {
      $j('#auction_item_description_translated').addClass('hidden');
      $j('#auction_item_description').removeClass('hidden');
    }
  }
}

No comments: