<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
Source Language
</td>
<td>
<asp:DropDownList ID="ddlSource" runat="server">
<asp:ListItem Value="AF" Text="Afrikanns" />
<asp:ListItem Value="SQ" Text="Albanian" />
<asp:ListItem Value="AR" Text="Arabic" />
<asp:ListItem Value="HY" Text="Armenian" />
<asp:ListItem Value="EU" Text="Basque" />
<asp:ListItem Value="BN" Text="Bengali" />
<asp:ListItem Value="BG" Text="Bulgarian" />
<asp:ListItem Value="CA" Text="Catalan" />
<asp:ListItem Value="KM" Text="Cambodian" />
<asp:ListItem Value="ZH" Text="Chinese (Mandarin)" />
<asp:ListItem Value="HR" Text="Croation" />
<asp:ListItem Value="CS" Text="Czech" />
<asp:ListItem Value="DA" Text="Danish" />
<asp:ListItem Value="NL" Text="Dutch" />
<asp:ListItem Value="EN" Text="English" Selected="True" />
<asp:ListItem Value="ET" Text="Estonian" />
<asp:ListItem Value="FJ" Text="Fiji" />
<asp:ListItem Value="FI" Text="Finnish" />
<asp:ListItem Value="FR" Text="French" />
<asp:ListItem Value="KA" Text="Georgian" />
<asp:ListItem Value="DE" Text="German" />
<asp:ListItem Value="EL" Text="Greek" />
<asp:ListItem Value="GU" Text="Gujarati" />
<asp:ListItem Value="HE" Text="Hebrew" />
<asp:ListItem Value="HI" Text="Hindi" />
<asp:ListItem Value="HU" Text="Hungarian" />
<asp:ListItem Value="IS" Text="Icelandic" />
</asp:DropDownList>
</td>
<td>
</td>
<td>
Target Language
</td>
<td>
<asp:DropDownList ID="ddlTarget" runat="server">
<asp:ListItem Value="AF" Text="Afrikanns" />
<asp:ListItem Value="SQ" Text="Albanian" />
<asp:ListItem Value="AR" Text="Arabic" />
<asp:ListItem Value="HY" Text="Armenian" />
<asp:ListItem Value="EU" Text="Basque" />
<asp:ListItem Value="BN" Text="Bengali" />
<asp:ListItem Value="BG" Text="Bulgarian" />
<asp:ListItem Value="CA" Text="Catalan" />
<asp:ListItem Value="KM" Text="Cambodian" />
<asp:ListItem Value="ZH" Text="Chinese (Mandarin)" />
<asp:ListItem Value="HR" Text="Croation" />
<asp:ListItem Value="CS" Text="Czech" />
<asp:ListItem Value="DA" Text="Danish" />
<asp:ListItem Value="NL" Text="Dutch" />
<asp:ListItem Value="EN" Text="English" />
<asp:ListItem Value="ET" Text="Estonian" />
<asp:ListItem Value="FJ" Text="Fiji" />
<asp:ListItem Value="FI" Text="Finnish" />
<asp:ListItem Value="FR" Text="French" Selected="True" />
<asp:ListItem Value="KA" Text="Georgian" />
<asp:ListItem Value="DE" Text="German" />
<asp:ListItem Value="EL" Text="Greek" />
<asp:ListItem Value="GU" Text="Gujarati" />
<asp:ListItem Value="HE" Text="Hebrew" />
<asp:ListItem Value="HI" Text="Hindi" />
<asp:ListItem Value="HU" Text="Hungarian" />
<asp:ListItem Value="IS" Text="Icelandic" />
</asp:DropDownList>
</td>
<td>
<asp:Button Text="Translate" runat="server" OnClick="Translate" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox ID="txtSource" runat="server" TextMode="MultiLine" />
</td>
<td>
</td>
<td colspan="2">
<asp:TextBox ID="txtTarget" runat="server" TextMode="MultiLine" />
</td>
<td>
</td>
</tr>
</table>
protected void Translate(object sender, EventArgs e)
{
string url = "https://translation.googleapis.com/language/translate/v2?key=YOUR_API_KEY";
url += "&source=" + ddlSource.SelectedItem.Value;
url += "&target=" + ddlTarget.SelectedItem.Value;
url += "&q=" + Server.UrlEncode(txtSource.Text.Trim());
WebClient client = new WebClient();
string json = client.DownloadString(url);
JsonData jsonData = (new JavaScriptSerializer()).Deserialize<JsonData>(json);
txtTarget.Text = jsonData.Data.Translations[0].TranslatedText;
}
public class JsonData
{
public Data Data { get; set; }
}
public class Data
{
public List<Translation> Translations { get; set; }
}
public class Translation
{
public string TranslatedText { get; set; }
}
Protected Sub Translate(sender As Object, e As EventArgs)
Dim url As String = "https://translation.googleapis.com/language/translate/v2?key=YOUR_API_KEY"
url += "&source=" + ddlSource.SelectedItem.Value
url += "&target=" + ddlTarget.SelectedItem.Value
url += "&q=" + Server.UrlEncode(txtSource.Text.Trim())
Dim client As New WebClient()
Dim json As String = client.DownloadString(url)
Dim jsonData As JsonData = (New JavaScriptSerializer()).Deserialize(Of JsonData)(json)
txtTarget.Text = jsonData.Data.Translations(0).TranslatedText
End Sub
Public Class JsonData
Public Property Data() As Data
End Class
Public Class Data
Public Property Translations() As List(Of Translation)
End Class
Public Class Translation
Public Property TranslatedText() As String
End Class