troubleshooting Question

Translate webpage of unlimited content using google translate.

Avatar of YYatin
YYatinFlag for India asked on
Scripting LanguagesWeb ComponentsWeb Services
3 Comments1 Solution1118 ViewsLast Modified:

I am working on a code where i need to convert the whole webpages with unlimited characters of content using google translate.

I know there is a limit of 2000 chars at a time for the conversion using google translate. but yet i need to implement this.

I have already achieved a target of translating unlimited content  using splitting the whole string in substrings and sending request to google translate using that substrings in a loop.

but now a new issue is generated in which if string contiains any html tags then in case of all the closed html tags in single string, I am geeting proper translation where as, when string splits and if at the time of splitting the string, any html tag remains unclosed, then from that place, whole string looses its format given using tags like <b>,<strong>,<td> etc. and whole translated text can not get the same HTML formating given in the same english(for ex.)  paragraph.

I am using google ajax api dll ( )  for setting the reference in vs 2005 and asp C# as my development environment.

plz help me as soon as possible as its very urgent and very imp for me to complete this task.

Thank you...
C# - Code Behind 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Google.API;
using Google.API.Translate;

public partial class _Default : System.Web.UI.Page 

protected void btn_Click(object sender, EventArgs e)
        litFullPara.Text = Text;

        string Para = "<font color='Red'><b>Since the first computer was made in the late fifties,the technology has developed extremely. Computers which took the place of a living-room then, are now being made in creditcard-formats.</b> More and more areas are being taken over by the computer. As computers are capable of handling large amounts of data in a very short time, they are well suited for wordprocessing. I guess that it won't be long till all the paper-archives are replaced by magnetic tapes and diskettes. A diskette can contain much more data than a written page, and it takes less place! It is possible to get the Norwegian telephone book on just one diskette.</font>";

        int length = Para.Length;
        string Reply = "";
        string[] splitString = Para.Split('.');

        foreach (string word in splitString)
            if(word != "")
                Reply = Reply +" "+ Translator.Translate(word, Language.English, Language.Hindi, TranslateFormat.html) +". "; 


.ASPX code :-

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
    <asp:Button ID="btn" Text="Click" runat="server" OnClick="btn_Click" /><br /><br />
    <asp:Literal ID="litFullPara" runat="server"></asp:Literal><br /><br />
    <asp:Literal ID="litSplitParas" runat="server"></asp:Literal>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros