TranslateGoogle() public method

Translates a string into another language using Google's translate API JSON calls. Class TranslationServices
public TranslateGoogle ( string text, string fromCulture, string toCulture, string googleApiKey = null ) : string
text string
fromCulture string
toCulture string
googleApiKey string Google Api key - if not specified it's read from the configuration
return string
Esempio n. 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;
    }
        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;
        }