when we use Google Browser translation, we will encounter "Google Browser can not translate this page content" confusion, the following small series for everyone to share a "Google browser can not translate this Web content solution" article, hoping to help everyone.
This article describes how to use urllib to retrieve googletranslate (Google translate,
The code is as follows:
#! /Usr/bin/env python3#-*-Coding: UTF-8 -*-# File Name: gt1.py# Purpose:# Creation Date: 1390366260# Last Modified: Wed 22 Jan 2014 06:14:11 PM CST# Release By: Doom. zhou
Import urllib. requestImport sys
Typ = sys. getfilesystemencoding ()
Def translate
Call Google translation API for translation
#!/usr/bin/python #coding: UTF-8 import sys reload (SYS) sys.setdefaultencoding (' UTF8 ') from xml.etree import Eleme Nttree as ET #引入解析xml文件的模块 import re import urllib,urllib2 #引入接入网络接口API的模块 from socket import error as SocketError IM Port errno import OS import string #调用google translator API to translate def
Create a new ANSI PHP file, and then make a class:
Copy Code code as follows:
Header ("content-type:text/html; Charset=utf-8 ");
Class google_api_translator{
Public $opts = Array ("text" => "", "Language_pair" => "En|it");
Public $out = "";
function Setopts ($opts) {
if ($opts ["text"]!= "") $this->opts["Text" = $opts ["text"];
if ($opts ["Language_pair"]!= "") $this->opts["Language_pair"] = $opts ["Language_pair"];
}
function translate
/* Google Translate PHP interface* Official Written 2009-03-28* http://blog.csdn.net/aprin/* Note: If the translated text is UTF-8 encoded, delete the Mb_convert_encoding function*/Class Google_api_translator {Public $url = "http://translate.google.com/translate_t";Public $text = "";//Translated textPublic $out = ""; Translation outputfunction SetText ($text) {$this->text = $text;}function
Description
1. Use Google translation services to obtain translations and voice;
2. Use MPlayer to play the resulting sound file, so if you want to play the voice, make sure that the MPlayer program is found in path, and if there is no mplayer, set the Use_tts to False to run. That
Main (Use_tts=false)
3. Exit the program, enter "X" and return.
Copy the Code code as follows:
#! /usr/bin/env python
#coding =utf-8
Import requests
def
Made a small tool, integrated Google translation, but the translation of Chinese characters changed, TK value is also changing, for the Chinese character with the original TK will not, engaged a night, did not find the TK algorithm.Later found that the wrong TK can also translate, do not know why, first make use of it.JS code: Google
A translation function is used in the project, that is, after the translation is submitted to Google, the returned results are obtained.
First, find out the context of Google translation:Request Processing
After submitting the translation, check what the request and response are:
VcHLzOG9u7XEVVJMPC9zdHJvbmc + PC9wPgo8cD48L3A + CjxwcmUgY2xhc3M9 "brush: java;"> url = httl: // translate.google.cn/translate_a/t
Google code: Insert after meta name="google-translate-customization" content="4bd8dffe75af5007-16fa37f088724895-g08c0457d35008bb8-47">meta>and insert the following code where you want the button to appear:Bing Code:div id=' Microsofttranslatorwidget ' class=' light ' style =' color:white;background-color: #555555 '>div>script type=' Text/javascript '>SetTimeou
---restore content starts---Using the Google Language API for the translation of your entire site, we can use the free Google API to do the processing for multi-lingual functions.Put in an HTML file Use the Google language API to translate your entire website
PHP Code:
Copy Code code as follows:
#!/usr/bin/php-q
/**
* PHP Script for Google Translate
* @author: Yishan Wang
* @version: 1.0.0
*/
Class Google_api_translator
{
Public $url = "http://translate.google.com/translate_t";
Public $text = "";
Public $out = "";
Public $ip = ';
function SetText ($text) {
$this->text = $text;
}
function translate
Method a direct translation and pronunciation
1 Open the browser, enter "g.cn" in the Address bar, and click the "Translate" link at the bottom:
2 or directly in the address bar input Google translated URL http://translate.google.cn, access to Google translation interface:
3 directly enter or paste text into the left text edit box:
Today I found Google's translation tool is very useful, you go to http://translate.google.com/translate_tools? Hl = en SL = ZH-CN, select the language in which your webpage is used, and the corresponding
Code . For example, if you select Chinese Simplified, the following code is generated:
Script SRC
=
"
Http://www.gmodules.com/ig/ifr? Url = http://www.google.com/ig/modules/translatemypage.xmlup_source_language=zh-CNw=160h=60title=border=output=js
"
>
Script
>
put it in
1. First note that the first word in the English sentence should be capitalized,2. End of sentence, use a full period.3. English words and the preceding punctuation to leave a space, such as: you. is should be you. Is you .....4. In English as the main translation language, translated into other languages, the translation of the results of the translation into Chinese, judge whether the statement is fluent. -----This is the key.Use Google to
Python is very fun .. It took 5 to 6 hours. Based on some examples on the internet, I wrote a Google Translate desktop version. The interface and functions are simple and can only be translated between Chinese and English. Mainly to learn Python
It is very convenient to use Glade on the interface. After painting, you only need to link the signal, and glade with pygtk is very convenient.
The source code of
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.