PlanetSquires Forums

Support Forums => General Board => Topic started by: Martin Francom on February 20, 2010, 04:32:45 AM

Title: Language Translation
Post by: Martin Francom on February 20, 2010, 04:32:45 AM
Microsoft has a language translator that can be accessed via the internet to translate a sentence from one language to another.  The example program provided is in C and does not make much sense to me.
Can some one here translate the C# code and help me make a FF/PB example program that can utilize Microsoft's internet translation service?


Return Value
The text translated into the desired language.

Example
C#
    string translateUri = "http://api.microsofttranslator.com/V1/Http.svc/Translate?appId=myAppId&from=en&to=es";
    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(translateUri);
    // Request must be HTTP POST to include translation text
    httpWebRequest.Method = "POST";
    httpWebRequest.ContentType = "text/plain";
    byte[] bytes = Encoding.ASCII.GetBytes("Translate this text");
    Stream os = null;

    try
    {
        // Text is inserted into the body of the request
        httpWebRequest.ContentLength = bytes.Length;
        os = httpWebRequest.GetRequestStream();
        os.Write(bytes, 0, bytes.Length);
    }
    finally
    {
        // Close stream if successful
        if (os != null)
        {
            os.Close();
        }
    }
   
    string output;
    try
    {
        WebResponse response = httpWebRequest.GetResponse();
        Stream stream = response.GetResponseStream();
        StreamReader reader = new StreamReader(stream);
        output = reader.ReadToEnd();
    }
    catch (Exception ex)
    {
        // An error may be thrown if the request body is not recognisable as text
        // An error may be thrown if the from and to parameters are the same
        output = "Error - " + ex.Message;
    }
   
    Console.WriteLine("Result: " + output);                                             
           

Here's a link to what I am taking about:

http://msdn.microsoft.com/en-us/library/dd576286.aspx

and

http://www.microsofttranslator.com/tools/

I would like to eventually be able to add the ability to translate the information in a textbox or RichEditbox by simply clicking a button.
Title: Re: Language Translation
Post by: Martin Francom on February 21, 2010, 09:35:01 PM
With some help from the PB forum I have a FF3 example project ready.  If you are fluent in a foreign language, please try out the translator program and let me know how accurate it is.  It is currently set to translate English to Spanish  but if you can change the "to" and "from" language in the program code. 

To compile you will need to get your own "Bing App ID"  the link is included in the file.  The ID is free.    Here's a couple other links that may be useful:

http://msdn.microsoft.com/en-us/library/dd576286.aspx
http://blogs.msdn.com/translation/archive/2008/12/17/a-metal-can-can-t-it-guest-blog.aspx
http://blogs.msdn.com/translation/archive/2008/11/10/linking-to-a-foreign-language-web-page-with-microsoft-translator.aspx
 
Paul,  Does FF automatically support UTF-8 Unicode language character sets?   If not, how do I set it up?
Title: Re: Language Translation
Post by: Elias Montoya on February 22, 2010, 04:53:39 PM

Enter text to translate.

>>

¿Escriba el texto a traducir.

The result is not a question. Even if it was, it would require the closing ? charater.

HOWEVER:
Comparing with Google translate and others, the translation is remarkable. In a block of
around 300 words, i only found 1 (ONE!!!) mistake and it was not that bad!!!!

Awesome. Simply awesome. This will have lots of implementations! Thanx for sharing Marty!
Title: Re: Language Translation
Post by: Martin Francom on February 24, 2010, 10:11:07 PM
Elias,   Thanks for responding.  If you can make an inprovements to the example program, I would much appreciate it.  One area is the UTF8 language characters.  How should this be handled so that the characters are displayed correctly?

One thing I have noticed is that the Bing Translator that Win7 Language Gadget uses will return (what seems to me) to be better translation.  The traslation routines that this example is calling may not be the prodution routines that the Bing translator uses for production prtograms such as the Win-7 Translator Gadget or by going to Bing Translator web site.

I would very much like to see a good FF3 example Translator project developed any here has suggestions for improvements I would be very grateful for your imput.
Title: Re: Language Translation
Post by: Elias Montoya on February 27, 2010, 10:23:18 PM

I will try to do the UTF8 thig as soon as i have some spare time,
Its worth a shot to look at this. Definately.

Title: Re: Language Translation
Post by: Roger Garstang on March 02, 2010, 07:08:36 PM
Google Wave does translation on the fly as you type.
Title: Re: Language Translation
Post by: Martin Francom on March 05, 2010, 03:52:05 AM
Quote from: Roger Garstang on March 02, 2010, 07:08:36 PM
Google Wave does translation on the fly as you type.

Roger, my ultamate goal is to be able to intigrate sometype of translation routine into my program.  I need only to translate short statements.  maybe a line or two.  like to be able to integrate it rather that have to go out to the web, use a translation program,  copy athe then paste the translated text into the TextBox in my program.    I would like to be able to enter some text (english) then click a button and the text would be translated to (say) spanish.  Nice an simple, no having to open the browser and no going to GoogleTanslate or YahooBabbelfish.   Just click a button an its done.

Understand?
Title: Re: Language Translation
Post by: Roger Garstang on March 12, 2010, 10:50:57 AM
Yeah, I get what you are doing, just commenting on what Google was capable of. The World is going to be an interesting place if Google and Microsoft keep coming up with this stuff in a race to have the next big thing.  With this being web based you could make one version of your app and have it translate on the fly for other languages at runtime. Could be useful in PHP and other web development too without being tied to .NET/COM/etc.