Let your. Net Program translate Language

Source: Internet
Author: User

Let's take a look at the Bing SDK. It's all about English, but it's just a bit of a result, that's translation. You can write a program translation later ..

If you use the hook function, you can create a screen-based word translation tool, just like Kingsoft.

Refer to system. speech for the one I wrote last time. Assembly ..

 

 

Code

 Using system;
Using system. net;
Using system. xml;
Using system. IO;
Using leleapplication1;
Static class translationsample
{
Static void main ()
{
// Appid is the abbreviation of applicationid. It is a required parameter and needs to be created by the user. It may be that Microsoft wants to know who is using it.
// You need to register and create an appid in Bing Development Center (http://cn.bing.com/developers) that is an English website, use me here.
String appid = "305713700e4a0e87e1bd013c0e784e204e9163b6 ";

// The text you want to translate
String query = "what the fuck is English ";

// The original language of the translation. This is not gibberish. It is required that en-CN (Simplified Chinese) (Traditional Chinese en-TW (Simplified Chinese en-CN) (English en-US)
String sourelanguage = "En-us ";
// Target language for translation
String targetlanguage = "ZH-CN ";

String requeststring = string. Format ("http://api.search.live.net/xml.aspx? Appid = {0} & query = {1} & sources = Translation & Translation. sourcelanguage = {2} & Translation. targetlanguage = {3 }",
Appid, query, sourelanguage, targetlanguage );
// In fact, the above URL returns an XML file,
// <? XML version = "1.0" encoding = "UTF-8"?>
// <? Pageview_candidate?>
//-<Searchresponse xmlns = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/element" version = "2.2">
//-<Query>
// <Searchterms> what the fuck is English </searchterms>
// </Query>
//-<Tra: Translation xmlns: tra = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/translation">
//-<Tra: Results>
//-<Tra: translationresult>
// <Tra: translatedterm> fucking English </TRA: translatedterm>
// </TRA: translationresult>
// </TRA: Results>
// </TRA: Translation>
/// </Searchresponse>

// If you change to http://api.search.live.net/json.aspx? This path does not change. Then, an object in JSON format is returned. Of course, you can also return the SOAP format.
Httpwebrequest request = (httpwebrequest) httpwebrequest. Create (requeststring );
Httpwebresponse response = (httpwebresponse) request. getresponse ();
Xmldocument document = new xmldocument ();
Document. Load (response. getresponsestream ());

// Read the result. The read result is actually complicated. The actual reading result depends on the official example. Because sometimes there are several lists or errors returned, and so on .. This is just an example, so there is only one sentence.
Console. writeline (document. innertext );
Console. Read ();
}

}

 

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.