Use the youdao translation Api to implement English translation.

Source: Internet
Author: User

Use the youdao translation Api to implement English translation.

Youdao translation provides data interfaces for translation and word query. Through the data interface, you can get the Translation results or word query results of a piece of text. By calling the youdao translation API data interface, you can flexibly customize the translation and word query functions on your website or application. Step 1: Apply for interface api to youdao Open Platform http://fanyi.youdao.com/openapi? Path = data-mode when applying for an api Note: if the application is successful, a group of api information will be obtained. For example, my information is as follows:

API key: 1048394636 keyfrom: wangtuizhijia
  • Creation Time:
  • Website name: wangtuizhijia
  • Address: http://www.wangtuizhijia.com

Using the youdao translation interface is very simple. Their data is submitted through the get method, so we only need to splice the information. The following is a php-based translation and parameter description:

<? Php/** Request Method: get, encoding method: UTF-8 main function: English-Chinese Translation, while obtaining the youdao translation result and youdao dictionary result (may not) parameter description: type-the type of the returned result, which is fixed to the data format of the data doctype-returned result, xml, json, or jsonp version-version. The latest version is 1.1 q-the text to be translated, must be UTF-8 encoding, the length cannot exceed 200 characters, need to urlencode encoding only-optional parameter, dict means to get only dictionary data, translate means to get only translation data, all are obtained by default. Note: The dictionary results can only be translated from Chinese to English. The translation results can be translated from English, Japan, South Korea, France, Russia, west to Chinese, and errorCode: 0-normal 20-the text to be translated is too long 30-no valid translation is allowed 40-unsupported language type 50-invalid key 60-no dictionary result, takes effect only when obtaining dictionary results ***/ Class Youdao {public $ keyfrom; public $ key; public $ doctype;/* automatically configure the parameter **/function _ construct () {$ this-> keyfrom = 'wangtuizhijia '; $ this-> key = '000000'; $ this-> doctype = 'json ';} /** translate and return results ** $ content is the text to be translated **/public function translate ($ content) {$ youdao_api_url = 'HTTP: // fanyi.youdao.com/openapi.do? Keyfrom = '. $ this-> keyfrom. '& key = '. $ this-> key. '& type = data & doctype = '. $ this-> doctype. '& version = 1.1 & q = '. $ content; return json_decode (file_get_contents ($ youdao_api_url) ;}// set the text to be translated $ content = 'hello '; // instantiate the translation class $ Youdao = new Youdao (); $ translated_data = $ Youdao-> translate ($ content); // Youdao translation result, is an array $ translation_arr = $ translated_data-> translation; // youdao dictionary-basic dictionary, an object $ basic_obj = $ translated _ Data-> basic; // The pronunciation $ phonetic = $ basic-> phonetic; // The explanation is an array, because there are many meanings: $ explains_arr = $ basic-> explains; // youdao dictionary-network definition, which is an array containing the object $ web_arr = $ translated_data-> web;?>

Note:

When using the API key, the request frequency is limited to 1000 times per hour. If the limit is exceeded, the request will be banned.
If your application does require more than 1000 requests per hour, you can contact youdao through the translate-service@corp.youdao.com mailbox.

My blog address: Use youdao translation Api to implement English Translation

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.