Bước 1: Tạo 1 trang translation.php với code như sau: PHP: <?phpfunction PIPHP_GoogleTranslate($text, $lang1, $lang2) { $langs = array( 'simplified chinese' => 'zh-cn', 'traditional chinese' => 'zh-tw', 'english' => 'en', 'french' => 'fr', 'german' => 'de', 'italian' => 'it', 'japanese' => 'ja', 'korean' => 'ko', 'polish' => 'pl', 'portuguese' => 'pt', 'russian' => 'ru', 'spanish' => 'es', 'vietnamese' => 'vi', 'swedish' => 'sv'); $lang1 = strtolower($lang1); $lang2 = strtolower($lang2); $root = 'http://ajax.googleapis.com/ajax/services'; $url = $root . '/language/translate?v=1.0&q='; if (!isset($langs[$lang1]) || !isset($langs[$lang1])) return FALSE; $json = @file_get_contents($url . urlencode($text) . '&langpair='. $langs[$lang1] . '|' . $langs[$lang2]); if (!strlen($json)) return FALSE; $result = json_decode($json); return $result->responseData->translatedText; }?> Bước 2: Chèn code này vào index: PHP: <?phprequire "translation.php"; $text = "We hold these truths to be self-evident, that all " . "Men are created equal, that they are endowed by " . "Their creator with certain unalienable rights, that " . "Among these are life, liberty and the pursuit of " . "Happiness. That to secure these rights, governments " . "Are instituted among men, deriving their just powers " . "From the consent of the governed."; $from = 'English'; $to = 'Vietnamese'; $result = PIPHP_GoogleTranslate($text, $from, $to); if (!$result) echo "Translation failed!"; else echo "$result"; ?>