예제 #1
0
    public string Translate(string Text, string From, string To, string Service)
    {
        Service = Service.ToLower();

        TranslationServices Translate = new TranslationServices();

        Translate.TimeoutSeconds = 10;

        string Result = null;

        if (Service == "google")
        {
            Result = Translate.TranslateGoogle(Text, From, To);
        }
        else if (Service == "babelfish")
        {
            Result = Translate.TranslateBabelFish(Text, From, To);
        }

        if (Result == null)
        {
            Result = Translate.ErrorMessage;
        }

        return(Result);
    }
예제 #2
0
        public void BingTest()
        {
            TranslationServices service = new TranslationServices();

            // use app.config clientid and clientsecret
            string token = service.GetBingAuthToken();

            Assert.IsNotNull(token);

            string result = service.TranslateBing("Life is one big wave with a giant bottom turn!", "en",
                                                  "de", token);

            Console.WriteLine(result);

            string result2 = service.TranslateBing(result, "de", "en", token);

            Console.WriteLine(result2);

            string result3 = service.TranslateBing("Here's some text \"in quotes\" that needs to encode properly", "en",
                                                   "de", token);

            Console.WriteLine(result3);

            string ttext =
                "Here's some text \"in quotes\" that needs to encode properly Really, where do I go, what do I do, how do I do it and when can it be done, who said it, where is it and whatever happened to Jim, what happened to Helmut when he came home I thought he might have been dead";

            Console.WriteLine(ttext);
            string result4 = service.TranslateBing(ttext, "en", "de", token);

            Console.WriteLine(result4);
        }
        public void TranslateGoogleTest()
        {
            TranslationServices service = new TranslationServices();

            string result = service.TranslateGoogle("Life is great and one is spoiled when it goes on and on and on", "en", "de");

            Console.WriteLine(result);
            Console.WriteLine(service.ErrorMessage);


            string result2 = service.TranslateGoogle(result, "de", "en");

            Console.WriteLine(result2);

            string result3 = service.TranslateGoogle("Here's some text \"in quotes\" that needs to encode properly", "en", "de");

            Console.WriteLine(result3);

            string ttext = "Here's some text \"in quotes\" that needs to encode properly Really, where do I go, what do I do, how do I do it and when can it be done, who said it, where is it and whatever happened to Jim, what happened to Helmut when he came home I thought he might have been dead";

            Console.WriteLine(ttext);

            string result4 = service.TranslateGoogle(ttext, "en", "de");

            Console.WriteLine(result4);
        }
        public string Translate(string text, string from, string to, string service)
        {
            service = service.ToLower();

            var translate = new TranslationServices(configuration);

            translate.TimeoutSeconds = 10;

            string result = null;

            if (service == "google")
            {
                result = translate.TranslateGoogle(text, from, to);
            }
            else if (service == "bing")
            {
                if (string.IsNullOrEmpty(configuration.BingClientId))
                {
                    result = ""; // don't do anything -  just return blank
                }
                else
                {
                    result = translate.TranslateBing(text, from, to);
                }
            }

            if (result == null)
            {
                result = translate.ErrorMessage;
            }

            return(result);
        }
예제 #5
0
        public string Translate(string Text, string From, string To, string Service)
        {
            Service = Service.ToLower();

            var translate = new TranslationServices();

            translate.TimeoutSeconds = 10;

            string result = null;

            if (Service == "google")
            {
                result = translate.TranslateGoogle(Text, From, To);
            }
            else if (Service == "bing")
            {
                if (string.IsNullOrEmpty(DbResourceConfiguration.Current.BingClientId))
                {
                    result = ""; // don't do anything -  just return blank
                }
                else
                {
                    result = translate.TranslateBing(Text, From, To);
                }
            }

            if (result == null)
            {
                result = translate.ErrorMessage;
            }

            return(result);
        }
        public string Translate([FromBody] dynamic parm)
        {
            string text = parm.text;
            string from = parm.from;
            string to = parm.to;
            string service = parm.service;

            service = service.ToLower();

            var translate = new TranslationServices();
            translate.TimeoutSeconds = 10;

            string result = null;
            if (service == "google")
                result = translate.TranslateGoogle(text, @from, to);
            else if (service == "bing")
            {
                if (string.IsNullOrEmpty(DbResourceConfiguration.Current.BingClientId))
                    result = ""; // don't do anything -  just return blank 
                else
                    result = translate.TranslateBing(text, from, to);
            }
            else if (service == "deepl")
            {
                result = translate.TranslateDeepL(text, from, to);
            }
            
            if (result == null)
                result = translate.ErrorMessage;

            return result;
        }
        public void BingTest()
        {
            TranslationServices service = new TranslationServices();

            // use app.config clientid and clientsecret
            string token = service.GetBingAuthToken();
            Assert.IsNotNull(token);

            string result = service.TranslateBing("Life is great and one is spoiled when it goes on and on and on", "en",
                "de", token);
            Console.WriteLine(result);

            string result2 = service.TranslateBing(result, "de", "en", token);
            Console.WriteLine(result2);

            string result3 = service.TranslateBing("Here's some text \"in quotes\" that needs to encode properly", "en",
                "de", token);
            Console.WriteLine(result3);

            string ttext =
                "Here's some text \"in quotes\" that needs to encode properly Really, where do I go, what do I do, how do I do it and when can it be done, who said it, where is it and whatever happened to Jim, what happened to Helmut when he came home I thought he might have been dead";
            Console.WriteLine(ttext);
            string result4 = service.TranslateBing(ttext, "en", "de", token);

            Console.WriteLine(result4);
        }
예제 #8
0
        public void TranslateGoogleTest()
        {
            TranslationServices service = new TranslationServices();

            string q = null;

            q = "Where are you?";
            string result = service.TranslateGoogle(q, "en", "de");

            Console.WriteLine(q);
            Console.WriteLine(result);
            Console.WriteLine();

            Assert.IsFalse(string.IsNullOrEmpty(result), service.ErrorMessage);


            string result2 = service.TranslateGoogle(result, "de", "en");

            Console.WriteLine(result);
            Console.WriteLine(result2);

            Assert.IsFalse(string.IsNullOrEmpty(result2), service.ErrorMessage);


            q = "Here's some text \"in quotes\" that needs to encode properly";
            string result3 = service.TranslateGoogle(q, "en", "de");

            Console.WriteLine(q);
            Console.WriteLine(result3);

            Assert.IsFalse(string.IsNullOrEmpty(result3), service.ErrorMessage);


            q =
                "Here's some text \"in quotes\" that needs to encode properly Really, where do I go, what do I do, how do I do it and when can it be done, who said it, where is it and whatever happened to Jim, what happened to Helmut when he came home I thought he might have been dead";

            string result4 = service.TranslateGoogle(q, "en", "de");

            Console.WriteLine(q);
            Console.WriteLine(result4);

            Assert.IsFalse(string.IsNullOrEmpty(result4), service.ErrorMessage);
        }
        public void TranslateGoogleTest()
        {
            TranslationServices service = new TranslationServices();

            string result = service.TranslateGoogle("Life is great and one is spoiled when it goes on and on and on", "en", "de");
            Console.WriteLine(result);

            string result2 = service.TranslateGoogle(result, "de", "en");
            Console.WriteLine(result2);

            string result3 = service.TranslateGoogle("Here's some text \"in quotes\" that needs to encode properly", "en", "de");
            Console.WriteLine(result3);

            string ttext = "Here's some text \"in quotes\" that needs to encode properly Really, where do I go, what do I do, how do I do it and when can it be done, who said it, where is it and whatever happened to Jim, what happened to Helmut when he came home I thought he might have been dead";
            Console.WriteLine(ttext);

            string result4 = service.TranslateGoogle(ttext, "en", "de");
            Console.WriteLine(result4);
        }
        public void TranslateGoogleTest()
        {
            TranslationServices service = new TranslationServices();

            string q = null;

            q = "Where are you?";
            string result = service.TranslateGoogle(q, "en", "de");
            Console.WriteLine(q);
            Console.WriteLine(result);
            Console.WriteLine();

            Assert.IsFalse(string.IsNullOrEmpty(result), service.ErrorMessage);


            string result2 = service.TranslateGoogle(result, "de", "en");
            Console.WriteLine(result);
            Console.WriteLine(result2);

            Assert.IsFalse(string.IsNullOrEmpty(result2), service.ErrorMessage);


            q = "Here's some text \"in quotes\" that needs to encode properly";
            string result3 = service.TranslateGoogle(q, "en", "de");
            Console.WriteLine(q);
            Console.WriteLine(result3);

            Assert.IsFalse(string.IsNullOrEmpty(result3), service.ErrorMessage);


            q =
                "Here's some text \"in quotes\" that needs to encode properly Really, where do I go, what do I do, how do I do it and when can it be done, who said it, where is it and whatever happened to Jim, what happened to Helmut when he came home I thought he might have been dead";

            string result4 = service.TranslateGoogle(q, "en", "de");
            Console.WriteLine(q);
            Console.WriteLine(result4);

            Assert.IsFalse(string.IsNullOrEmpty(result4), service.ErrorMessage);

        }
        public string Translate(dynamic parm)
        {
            string text = parm.text;
            string from = parm.from;
            string to = parm.to;
            string service = parm.service;

            service = service.ToLower();

            var translate = new TranslationServices();
            translate.TimeoutSeconds = 10;

            string result = null;
            if (service == "google")
                result = translate.TranslateGoogle(text, @from, to);
            else if (service == "bing")
            {
                if (string.IsNullOrEmpty(DbResourceConfiguration.Current.BingClientId))
                    result = ""; // don't do anything -  just return blank 
                else
                    result = translate.TranslateBing(text, @from, to);
            }

            if (result == null)
                result = translate.ErrorMessage;

            return result;
        }