Learn how to a build a cloud-first strategyRegister Now


Translate webpage of unlimited content using google translate.

Posted on 2009-12-25
Medium Priority
Last Modified: 2012-06-21

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 (http://iron9light.wordpress.com/2008/06/03/google-translate-api-for-net-01-release/ )  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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<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>

Open in new window

Question by:YYatin
  • 2
LVL 75

Accepted Solution

Michel Plungjan earned 2000 total points
ID: 26122239
Can't you treat it as xml and translate textnodes only

Author Comment

ID: 26122276
I can consider it in any way ...bt as per your instruction only...coz... i am completely unaware with  xml data reading...can you plz show me an example... thankx 4 the reply...
LVL 75

Expert Comment

by:Michel Plungjan
ID: 26122452

Featured Post

2017 Webroot Threat Report

MSPs: Get the facts you need to protect your clients.
The 2017 Webroot Threat Report provides a uniquely insightful global view into the analysis and discoveries made by the Webroot® Threat Intelligence Platform to provide insights on key trends and risks as seen by our users.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses
Course of the Month21 days, 3 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question