Translation of the text field into Spanish, Chinese, German

I want to translate the value of the text field into certain languages, such as Spanish, Chinese, German, etc., which all have in the drop-down list below, and I want to display the translated value of the text field in the label, but not get the translation value in the label.

<asp:TextBox ID="txtmessage" runat="server" /> <asp:DropDownList ID="drop" runat="server" AutoPostBack="true" onselectedindexchanged="drop_SelectedIndexChanged" > <asp:ListItem Value="en-US">English</asp:ListItem> <asp:ListItem Value="ja-JP">Japanese</asp:ListItem> <asp:ListItem Value="zh-CN">Chinse</asp:ListItem> <asp:ListItem Value="de-DE">Deutsch</asp:ListItem> </asp:DropDownList> <asp:Label ID="lblWelcome" meta:resourcekey="lblWelcome" Text="Welcome" runat="server" ></asp:Label> 

the code:

  protected void drop_SelectedIndexChanged(object sender, EventArgs e) { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(this.drop.SelectedValue); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(this.drop.SelectedValue); lblWelcome.text=txtmessage.text; } 
+6
source share
1 answer

Google is a great tool to use when searching for something similar. Google has Google Translate.

Here is an example of the code that you will need to modify to work on what you are doing.

 public static string Translate(string input, string languagePair, Encoding encoding) { string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}", input, languagePair); string result = String.Empty; using (WebClient webClient = new WebClient()) { webClient.Encoding = encoding; result = webClient.DownloadString(url); } HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(result); return doc.DocumentNode.SelectSingleNode("//textarea[@name='utrans']").InnerText; } //Get the HtmlAgilityPack here: http://www.codeplex.com/htmlagilitypack 
+11
source

Source: https://habr.com/ru/post/902938/


All Articles