Genbox / GoogleTranslateNet

A full implementation of the Google Translate 2.0 API
MIT License
35 stars 17 forks source link

unit tests failing #1

Closed josephflu closed 11 years ago

josephflu commented 11 years ago

Great library, thanks! Note that this unit test is failing:

TranslateTest()

Here is the corrected unit test:

    [TestMethod]
    public void TranslateTest()
    {
        GoogleTranslate google = new GoogleTranslate(_key);
        google.PrettyPrint = false;
        List<Translation> results = google.Translate(Language.Automatic, Language.German, "Hello there", "What are you doing?");

        Assert.AreEqual("Hallo es", results[0].TranslatedText);
        Assert.AreEqual(Language.English.GetStringValue(), results[0].DetectedSourceLanguage);

        Assert.AreEqual("Was machst du?", results[1].TranslatedText);
        Assert.AreEqual(Language.English.GetStringValue(), results[1].DetectedSourceLanguage);
    }
Genbox commented 11 years ago

Thanks for the bug report. I've committed the fix along with what seemed to be a missing namespace.

josephflu commented 11 years ago

awesome. thx. that was quick. One question, if I pass in a "&" to translate, google gives me back a "&", how do I convert that back to an "&". Is there a utility function in .NET that will do that for me? Right now I have this function which doesn't seem very robust:

    private static string DecodeUrlString(string url)
    {
        string newUrl = url;

        newUrl = newUrl.Replace("&#39;", "'").Replace("&quot;", "'")
            .Replace("&amp;", "&").Replace("&gt;", ">").Replace("&lt;",

"<"); //TODO: make sure this is comprehensive return newUrl; }

On Tue, Aug 13, 2013 at 12:42 PM, Ian Qvist notifications@github.comwrote:

Thanks for the bug report. I've committed the fix along with what seemed to be a missing namespace.

— Reply to this email directly or view it on GitHubhttps://github.com/Genbox/GoogleTranslate.NET/issues/1#issuecomment-22583441 .

Genbox commented 11 years ago

There sure is. Take a look at System.Web.HttpUtility. It has HtmlDecode(), which is what you need.

josephflu commented 11 years ago

Perfect, thanks.

On Tue, Aug 13, 2013 at 1:42 PM, Ian Qvist notifications@github.com wrote:

There sure is. Take a look at System.Web.HttpUtility. It has HtmlDecode(), which is what you need.

— Reply to this email directly or view it on GitHubhttps://github.com/Genbox/GoogleTranslate.NET/issues/1#issuecomment-22587637 .