如何将html页面从英语翻译成阿拉伯语c# [英] How to translate html Page From English To Arabic c#
本文介绍了如何将html页面从英语翻译成阿拉伯语c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的,
有没有办法将Html页面从语言转换为另一个用户C#
i已经使用
public string TranslateData( string 资源)
{
// string fromCulture = from .Name;
// string toCulture = to.Name;
// string translationMode = string.Concat(fromCulture,_,toCulture);
string url = String .Format( http://babelfish.yahoo.com/translate_txt?lp= {0}& tt = urltext& intl = 1& doit = done& urltext = { 1}, en_ar,HttpUtility.UrlEncode(resource));
WebClient webClient = new WebClient();
webClient.Encoding = System.Text.Encoding.Default;
string page = webClient.DownloadString(url);
int start = page.IndexOf( < div style = \padding:0.6em; \>)+ < div style = \padding:0.6em; \> .Length;
int finish = page.IndexOf( < / div>,开始);
string retVal = page.Substring(start,finish - start);
return retVal;
}
和结果是
附加信息:远程服务器返回错误:(414)Request-URI太大。
其中资源是Html内容页面
谢谢
解决方案
public void TransBride( string textvalue)
{
string appId = A70C584051881A30549986E65FF4B92B95B353A5; // 转到http://msdn.microsoft.com/en-us/library/ff512386.aspx获取AppId。
// string textvalue =为我翻译;
string 来自 = en;
string to = ar跨度>;
string uri = http:// api.microsofttranslator.com/v2/Http.svc/Translate?appId = + appId + & ; text = + textvalue + & from = + 来自 + & to = + to;
HttpWebRequest httpWebRequest =(HttpWebRequest)WebRequest.Create(uri);
WebResponse response = null ;
尝试
{
response = httpWebRequest.GetResponse();
使用(Stream stream = response.GetResponseStream())
{
DataContractSerializer dcs = new DataContractSerializer(Type.GetType( System.String));
string translation =( string )dcs.ReadObject(stream);
txtBrideAra.Text =翻译;
}
}
catch (WebException e)
{
ProcessWebException(e, 无法翻译);
}
最后
{
if (回复!= null )
{
response.Close();
response = null ;
}
}
}。
public void TransBride( string textvalue)
{
string appId = A70C584051881A30549986E65FF4B92B95B353A5; // 访问http://msdn.microsoft.com/en-us/library/ff512386.aspx获取AppId。
// string textvalue =为我翻译;
string 来自 = en;
string to = ar跨度>;
string uri = http:// api.microsofttranslator.com/v2/Http.svc/Translate?appId = + appId + & ; text = + textvalue + & from = + 来自 + & to = + to;
HttpWebRequest httpWebRequest =(HttpWebRequest)WebRequest.Create(uri);
WebResponse response = null ;
尝试
{
response = httpWebRequest.GetResponse();
使用(Stream stream = response.GetResponseStream())
{
DataContractSerializer dcs = new DataContractSerializer(Type.GetType( System.String));
string translation =( string )dcs.ReadObject(stream);
txtBrideAra.Text =翻译;
}
}
catch (WebException e)
{
ProcessWebException(e, 无法翻译);
}
最后
{
if (回复!= null )
{
response.Close();
response = null ;
}
}
}
************ ****
按钮点击
TransBride(txtBride.Text);
Dear All,
Is There Any Way To Translate Html Page from Language to another User C#
i have Used
public string TranslateData(string resource)
{
// string fromCulture = from.Name;
// string toCulture = to.Name;
// string translationMode = string.Concat(fromCulture, "_", toCulture);
string url = String.Format("http://babelfish.yahoo.com/translate_txt?lp={0}&tt=urltext&intl=1&doit=done&urltext={1}", "en_ar", HttpUtility.UrlEncode(resource));
WebClient webClient = new WebClient();
webClient.Encoding = System.Text.Encoding.Default;
string page = webClient.DownloadString(url);
int start = page.IndexOf("<div style=\"padding:0.6em;\">") + "<div style=\"padding:0.6em;\">".Length;
int finish = page.IndexOf("</div>", start);
string retVal = page.Substring(start, finish - start);
return retVal;
}
and the result Was
Additional information: The remote server returned an error: (414) Request-URI Too Large.
where resource is The Html Content Page
Thanks
解决方案
public void TransBride(string textvalue) { string appId = "A70C584051881A30549986E65FF4B92B95B353A5";//go to http://msdn.microsoft.com/en-us/library/ff512386.aspx to obtain AppId. // string textvalue = "Translate this for me"; string from = "en"; string to = "ar"; string uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=" + appId + "&text=" + textvalue + "&from=" + from + "&to=" + to; HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri); WebResponse response = null; try { response = httpWebRequest.GetResponse(); using (Stream stream = response.GetResponseStream()) { DataContractSerializer dcs = new DataContractSerializer(Type.GetType("System.String")); string translation = (string)dcs.ReadObject(stream); txtBrideAra.Text = translation; } } catch (WebException e) { ProcessWebException(e, "Failed to translate"); } finally { if (response != null) { response.Close(); response = null; } } }.
public void TransBride(string textvalue) { string appId = "A70C584051881A30549986E65FF4B92B95B353A5";//go to http://msdn.microsoft.com/en-us/library/ff512386.aspx to obtain AppId. // string textvalue = "Translate this for me"; string from = "en"; string to = "ar"; string uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=" + appId + "&text=" + textvalue + "&from=" + from + "&to=" + to; HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri); WebResponse response = null; try { response = httpWebRequest.GetResponse(); using (Stream stream = response.GetResponseStream()) { DataContractSerializer dcs = new DataContractSerializer(Type.GetType("System.String")); string translation = (string)dcs.ReadObject(stream); txtBrideAra.Text = translation; } } catch (WebException e) { ProcessWebException(e, "Failed to translate"); } finally { if (response != null) { response.Close(); response = null; } } }
****************
in button click
TransBride(txtBride.Text);
这篇关于如何将html页面从英语翻译成阿拉伯语c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文