Esempio n. 1
0
 public static object Deserialise(ValueNode node, Type expected = null, TranslateOptions tOpts = null)
 {
     if (tOpts == null) tOpts = TranslateOptions.Default;
     object obj;
     tOpts.Deserialise(expected, node, out obj);
     return obj;
 }
        public ConvertionResult ToKnockoutVm(string code, TranslateOptions options = null)
        {
            if(options == null)
            {
                options = TranslateOptions.Defaults;
            }

            _log.Debug("Converting code to Knockout VM. Options:\n{0}\nCode:\n{1}", options.ToFormattedJson(), code);

            Func<ConvertionResult, ConvertionResult> exit = r =>
            {
                _log.Debug("Returning Convertion Result: {0}", r.ToFormattedJson());
                return r;
            };

            var result = new ConvertionResult();

            if(code.IsNullOrEmpty())
            {
                result.Success = false;
                result.Message = "No code provided";
                return exit(result);
            }

            // do convertion
            code = code.AddDefaultUsings();
            var visitor = new NRefactoryVisitor(options);
            var textReader = new StringReader(code);
            var parser = new CSharpParser();
            var cu = parser.Parse(textReader, "dummy.cs");

            if(parser.HasErrors)
            {
                var errors = cu.GetErrors();
                var warnings = cu.GetErrors(ErrorType.Warning);
                result.Success = false;
                result.Message = "Error parsing code file.";
                result.Errors.AddRange(errors);
                result.Warnings.AddRange(warnings);
                return exit(result);
            }

            if(parser.HasWarnings)
            {
                var warnings = cu.GetErrors(ErrorType.Warning);
                result.Message = "Parsed code contains warnings!";
                result.Warnings.AddRange(warnings);
            }

            cu.AcceptVisitor(visitor);

            var writter = new KnockoutWritter();
            var convertedCode = writter.Write(visitor.Result, options);

            result.Success = true;
            result.Code = convertedCode;

            return exit(result);
        }
        public List<string> Translate(List<string> content, Language src_lang, Language dest_lang)
        {
            List<string> result = new List<string>();
            TranslateOptions options = new TranslateOptions();
            TranslateArrayResponse[] results = _client.TranslateArray(GetAppId(), content.ToArray(), src_lang.BaseLanguage, dest_lang.BaseLanguage, options);

            foreach(TranslateArrayResponse response in results)
            {
                result.Add(response.TranslatedText);
            }

            return result;
        }
Esempio n. 4
0
        public override ITypeItem TranslateRType(Type type, TranslateOptions options)
        {
            ITypeItem result;

            if (type.IsGenericParameter)
            {
                throw new Exception("generic parameters are not supported.");
            }

            if (!Types.TryGetItem(type.GetRName(), out result))
            {
                if (options.IsAdd())
                {
                    result = new NativeTypeRef(this, type);
                    result.SetExternal();
                }
                else
                {
                    if (type.IsGenericType)
                    {
                        var ge = new GenericInterfaceEnumerator(type);

                        foreach (var itf in ge.Interfaces)
                        {
                            if (Types.TryGetItem(itf.GetRName(), out result))
                            {
                                break;
                            }
                        }

                        if (null == result)
                        {
                            throw new UnresolvedTypeException("no mapping for generic type [" + type.GetRName() + "]");
                        }
                    }
                }
            }

            if (null == result && options == TranslateOptions.MustExist)
            {
                throw new UnresolvedTypeException("runtime type '" + type.GetRName() + "' could not be resolved.");
            }

            return result;
        }
Esempio n. 5
0
        public virtual ITypeItem TranslateRType(Type rtype, TranslateOptions options)
        {
            ITypeItem result;

            ValidateRType(rtype);

            // see if qualified type name is already in the list
            var qname = rtype.GetRName();
            if (!Types.TryGetItem(qname, out result))
            {
                // let subclass do its task
                result = BeforeTranslateRuntimeType(rtype);

                if (null == result)
                {
                    // default flow, let parent do ...
                    if (null != ParentTypes)
                    {
                        result = ParentTypes.TranslateRType(rtype, TranslateOptions.None);
                    }

                    if (null == result)
                    {
                        // type does not exist, add it
                        result = AddRuntimeType(rtype);
                    }
                }
            }

            if (null == result && options.IsMustExist())
            {
                throw new UnresolvedTypeException("runtime type '" + qname + "' could not be resolved.");
            }

            // Log.Trace("[{0}] TranslateRType({1}, {2}) => {3}", this, rtype.Name, options, result);

            return result;
        }
        public override async void Translate(ITranslationSession translationSession)
        {
            try
            {
                var authenticationKey = AuthenticationKey;

                if (string.IsNullOrEmpty(authenticationKey))
                {
                    translationSession.AddMessage("Azure Translator requires subscription secret.");
                    return;
                }

                var token = await AzureAuthentication.GetBearerAccessTokenAsync(authenticationKey);

                var binding         = new BasicHttpBinding();
                var endpointAddress = new EndpointAddress("http://api.microsofttranslator.com/V2/soap.svc");

                using (var client = new LanguageServiceClient(binding, endpointAddress))
                {
                    var innerChannel = client.InnerChannel;
                    // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                    if (innerChannel == null)
                    {
                        // ReSharper disable once HeuristicUnreachableCode
                        return;
                    }

                    using (new OperationContextScope(innerChannel))
                    {
                        var httpRequestProperty = new HttpRequestMessageProperty();
                        httpRequestProperty.Headers.Add("Authorization", token);
                        var operationContext = OperationContext.Current;
                        Contract.Assume(operationContext != null); // because we are inside OperationContextScope
                        operationContext.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;

                        foreach (var languageGroup in translationSession.Items.GroupBy(item => item.TargetCulture))
                        {
                            Contract.Assume(languageGroup != null);

                            var cultureKey = languageGroup.Key;
                            Contract.Assume(cultureKey != null);

                            var targetLanguage = cultureKey.Culture ?? translationSession.NeutralResourcesLanguage;

                            using (var itemsEnumerator = languageGroup.GetEnumerator())
                            {
                                while (true)
                                {
                                    var sourceItems   = itemsEnumerator.Take(10);
                                    var sourceStrings = sourceItems.Select(item => item.Source).ToArray();

                                    if (!sourceStrings.Any())
                                    {
                                        break;
                                    }

                                    var translateOptions = new TranslateOptions()
                                    {
                                        ContentType = "text/plain",
                                        IncludeMultipleMTAlternatives = true
                                    };

                                    var response = client.GetTranslationsArray("", sourceStrings, translationSession.SourceLanguage.IetfLanguageTag, targetLanguage.IetfLanguageTag, 5, translateOptions);
                                    if (response != null)
                                    {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed => just push out results, no need to wait.
                                        translationSession.Dispatcher.BeginInvoke(() => ReturnResults(sourceItems, response));
                                    }

                                    if (translationSession.IsCanceled)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                translationSession.AddMessage("Azure translator reported a problem: " + ex);
            }
        }
 public TranslateAnalyzer(TranslateOptions options)
 {
     _options = options;
 }
Esempio n. 8
0
 public ITypeItem TranslateRType(Type rtype, TranslateOptions options = TranslateOptions.None)
 {
     throw Failure();
 }
Esempio n. 9
0
        /// <summary>
        /// Translates an array of strings from the from langauge code to the to language code.
        /// From langauge code can stay empty, in that case the source language is auto-detected, across all elements of the array together.
        /// </summary>
        /// <param name="texts">Array of strings to translate</param>
        /// <param name="from">From language code. May be empty</param>
        /// <param name="to">To language code. Must be a valid language</param>
        /// <param name="contentType">Whether this is plain text or HTML</param>
        /// <returns></returns>
        private static string[] TranslateArrayV2(string[] texts, string from, string to, string contentType)
        {
            string headerValue = GetHeaderValue();
            var    bind        = new BasicHttpBinding
            {
                Name                   = "BasicHttpBinding_LanguageService",
                OpenTimeout            = TimeSpan.FromMinutes(5),
                CloseTimeout           = TimeSpan.FromMinutes(5),
                ReceiveTimeout         = TimeSpan.FromMinutes(5),
                MaxReceivedMessageSize = int.MaxValue,
                MaxBufferPoolSize      = int.MaxValue,
                MaxBufferSize          = int.MaxValue,
                Security               =
                    new BasicHttpSecurity {
                    Mode = BasicHttpSecurityMode.Transport
                }
            };

            var epa = new EndpointAddress(EndPointAddress + "/V2/soap.svc");
            LanguageServiceClient client = new LanguageServiceClient(bind, epa);

            if (String.IsNullOrEmpty(to))
            {
                to = "en";
            }

            TranslateOptions options = new TranslateOptions();

            options.Category    = _CategoryID;
            options.ContentType = contentType;

            try
            {
                var translatedTexts = client.TranslateArray(
                    headerValue,
                    texts,
                    from,
                    to,
                    options);
                string[] res = translatedTexts.Select(t => t.TranslatedText).ToArray();
                if (CreateTMXOnTranslate)
                {
                    WriteToTmx(texts, res, from, to, options.Category);
                }
                return(res);
            }
            catch   //try again forcing English as source language
            {
                var translatedTexts = client.TranslateArray(
                    headerValue,
                    texts,
                    "en",
                    to,
                    options);
                string[] res = translatedTexts.Select(t => t.TranslatedText).ToArray();
                if (CreateTMXOnTranslate)
                {
                    WriteToTmx(texts, res, from, to, options.Category);
                }
                return(res);
            }
        }
 public string TextByLanguage(string domainName, TranslateOptions options, string key, Language language, string defaultValue, params object[] parameters)
 {
     return Translate.TextByLanguage(domainName, options, key, language, defaultValue, parameters);
 }
Esempio n. 11
0
 public IAsyncResult BeginGetTranslations(string appId, string text, string from, string to, int maxTranslations, TranslateOptions options, AsyncCallback callback, object asyncState)
 {
     throw new NotImplementedException();
 }
 public Task AddTranslationArrayAsync(string appId, Translation[] translations, string from, string to, TranslateOptions options)
 {
     throw new NotImplementedException();
 }
 public Task<GetTranslationsResponse[]> GetTranslationsArrayAsync(string appId, string[] texts, string from, string to, int maxTranslations, TranslateOptions options)
 {
     throw new NotImplementedException();
 }
Esempio n. 14
0
 public string TextByDomain(string domain, TranslateOptions options, string key, params object[] parameters)
 {
     return(Translate.TextByDomain(domain, options, key, parameters));
 }
 public GetTranslationsResponse GetTranslations(string appId, string text, string from, string to, int maxTranslations, TranslateOptions options)
 {
     throw new NotImplementedException();
 }
Esempio n. 16
0
 public string TextByLanguage(string domainName, TranslateOptions options, string key, Language language, string defaultValue, params object[] parameters)
 {
     return(Translate.TextByLanguage(domainName, options, key, language, defaultValue, parameters));
 }
 public AmazonS3TranslationPersister(IAmazonS3 s3, IOptions <TranslateOptions> options, ILogger <AmazonS3TranslationPersister> logger)
 {
     _s3      = s3 ?? throw new ArgumentNullException(nameof(s3));
     _options = options?.Value ?? throw new ArgumentNullException(nameof(options));
     _logger  = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        /// <summary>
        /// Retrieve word alignments during translation
        /// </summary>
        /// <param name="texts">Array of text strings to translate</param>
        /// <param name="from">From language</param>
        /// <param name="to">To language</param>
        /// <param name="alignments">Call by reference: array of alignment strings in the form [[SourceTextStartIndex]:[SourceTextEndIndex]–[TgtTextStartIndex]:[TgtTextEndIndex]]</param>
        /// <returns>Translated array elements</returns>
        public static string[] GetAlignments(string[] texts, string from, string to, ref string[] alignments)
        {
            string fromCode = string.Empty;
            string toCode   = string.Empty;

            if (from.ToLower() == "Auto-Detect".ToLower() || from == string.Empty)
            {
                fromCode = string.Empty;
            }
            else
            {
                try { fromCode = AvailableLanguages.First(t => t.Value == from).Key; }
                catch { fromCode = from; }
            }

            toCode = LanguageNameToLanguageCode(to);

            Utils.ClientID     = _ClientID;
            Utils.ClientSecret = _ClientSecret;
            string headerValue = "Bearer " + Utils.GetAccesToken();
            var    bind        = new BasicHttpBinding
            {
                Name                   = "BasicHttpBinding_LanguageService",
                OpenTimeout            = TimeSpan.FromMinutes(5),
                CloseTimeout           = TimeSpan.FromMinutes(5),
                ReceiveTimeout         = TimeSpan.FromMinutes(5),
                MaxReceivedMessageSize = int.MaxValue,
                MaxBufferPoolSize      = int.MaxValue,
                MaxBufferSize          = int.MaxValue,
                Security               =
                    new BasicHttpSecurity {
                    Mode = BasicHttpSecurityMode.Transport
                }
            };

            var epa = new EndpointAddress("https://api.microsofttranslator.com/V2/soap.svc");
            LanguageServiceClient client = new LanguageServiceClient(bind, epa);

            if (String.IsNullOrEmpty(toCode))
            {
                toCode = "en";
            }

            TranslateOptions options = new TranslateOptions();

            options.Category = _CategoryID;

            try
            {
                var translatedTexts2 = client.TranslateArray2(
                    headerValue,
                    texts,
                    fromCode,
                    toCode,
                    options);
                string[] res = translatedTexts2.Select(t => t.TranslatedText).ToArray();
                alignments = translatedTexts2.Select(t => t.Alignment).ToArray();
                return(res);
            }
            catch   //try again forcing English as source language
            {
                var translatedTexts2 = client.TranslateArray2(
                    headerValue,
                    texts,
                    "en",
                    toCode,
                    options);
                string[] res = translatedTexts2.Select(t => t.TranslatedText).ToArray();
                alignments = translatedTexts2.Select(t => t.Alignment).ToArray();
                return(res);
            }
        }
        /// <summary>
        /// Translates an array of strings from the from langauge code to the to language code.
        /// From langauge code can stay empty, in that case the source language is auto-detected, across all elements of the array together.
        /// </summary>
        /// <param name="texts">Array of strings to translate</param>
        /// <param name="from">From language code. May be empty</param>
        /// <param name="to">To language code. Must be a valid language</param>
        /// <returns></returns>
        public static string[] TranslateArray(string[] texts, string from, string to)
        {
            string fromCode = string.Empty;
            string toCode = string.Empty;

            if (from.ToLower() == "Auto-Detect".ToLower() || from == string.Empty)
            {
                fromCode = string.Empty;
            }
            else
            {
                fromCode = AvailableLanguages.First(t => t.Value == from).Key;
            }

            toCode = LanguageNameToLanguageCode(to);

            Utils.ClientID = _ClientID;
            Utils.ClientSecret = _ClientSecret;
            string headerValue = "Bearer " + Utils.GetAccesToken();
            var bind = new BasicHttpBinding
                           {
                               Name = "BasicHttpBinding_LanguageService",
                               OpenTimeout = TimeSpan.FromMinutes(5),
                               CloseTimeout = TimeSpan.FromMinutes(5),
                               ReceiveTimeout = TimeSpan.FromMinutes(5),
                               MaxReceivedMessageSize = int.MaxValue,
                               MaxBufferPoolSize = int.MaxValue,
                               MaxBufferSize = int.MaxValue,
                               Security =
                                   new BasicHttpSecurity { Mode = BasicHttpSecurityMode.Transport }
                           };

            var epa = new EndpointAddress("https://api.microsofttranslator.com/V2/soap.svc");
            LanguageServiceClient client = new LanguageServiceClient(bind, epa);

            // Set Authorization header before sending the request
            HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty { Method = "POST" };

            httpRequestProperty.Headers.Add("Authorization", headerValue);

            // Creates a block within which an OperationContext object is in scope.
            using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] =
                    httpRequestProperty;

                if (String.IsNullOrEmpty(toCode))
                {
                    toCode = "en";
                }

                TranslateOptions options = new TranslateOptions();
                options.Category = _CategoryID;

                var translatedTexts = client.TranslateArray(
                    string.Empty,
                    texts,
                    fromCode,
                    toCode,
                    options);
                string[] res = translatedTexts.Select(t => t.TranslatedText).ToArray();
                return res;
            }
        }
 public TranslateArrayResponse[] TranslateArray(string appId, string[] texts, string from, string to, TranslateOptions options)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Translates an array of strings from the from langauge code to the to language code.
        /// From langauge code can stay empty, in that case the source language is auto-detected, across all elements of the array together.
        /// </summary>
        /// <param name="texts">Array of strings to translate</param>
        /// <param name="from">From language code. May be empty</param>
        /// <param name="to">To language code. Must be a valid language</param>
        /// <returns></returns>
        public static string[] TranslateArray(string[] texts, string from, string to)
        {
            string fromCode = string.Empty;
            string toCode = string.Empty;

            if (from.ToLower() == "Auto-Detect".ToLower() || from == string.Empty)
            {
                fromCode = string.Empty;
            }
            else
            {
                fromCode = AvailableLanguages.First(t => t.Value == from).Key;
            }

            toCode = LanguageNameToLanguageCode(to);

            Utils.ClientID = _ClientID;
            Utils.ClientSecret = _ClientSecret;
            string headerValue = "Bearer " + Utils.GetAccesToken();
            var bind = new BasicHttpBinding
                           {
                               Name = "BasicHttpBinding_LanguageService",
                               OpenTimeout = TimeSpan.FromMinutes(5),
                               CloseTimeout = TimeSpan.FromMinutes(5),
                               ReceiveTimeout = TimeSpan.FromMinutes(5),
                               MaxReceivedMessageSize = int.MaxValue,
                               MaxBufferPoolSize = int.MaxValue,
                               MaxBufferSize = int.MaxValue,
                               Security =
                                   new BasicHttpSecurity { Mode = BasicHttpSecurityMode.Transport }
                           };

            var epa = new EndpointAddress("https://api.microsofttranslator.com/V2/soap.svc");
            LanguageServiceClient client = new LanguageServiceClient(bind, epa);

            if (String.IsNullOrEmpty(toCode))
            {
                toCode = "en";
            }

            TranslateOptions options = new TranslateOptions();
            options.Category = _CategoryID;

            var translatedTexts = client.TranslateArray(
                headerValue,
                texts,
                fromCode,
                toCode,
                options);
            string[] res = translatedTexts.Select(t => t.TranslatedText).ToArray();
            return res;
        }
 public Task<TranslateArray2Response[]> TranslateArray2Async(string appId, string[] texts, string from, string to, TranslateOptions options)
 {
     throw new NotImplementedException();
 }
        public void Translate(IEnumerable<AutoTranslationItem> translationItems, string from, string to)
        {
            if (translationItems == null) throw new ArgumentNullException("translationItems");
            if (string.IsNullOrEmpty(from)) throw new ArgumentNullException("from");
            if (string.IsNullOrEmpty(to)) throw new ArgumentNullException("to");

            var translator = new LanguageServiceClient();
            var options = new TranslateOptions();

            foreach (var translationItemsChunk in translationItems.GetChunks(ChunkSize))
            {
                var texts = from p in translationItemsChunk select p.Text.Length <= 2000 ? p.Text : p.Text.Substring(0, 2000);   // 2000 is used because this is the current limit of ms translation services

                // send for translation
                var textsArray = texts.ToArray();
                TranslateArrayResponse[] microsoftTranslatorResponses = translator.TranslateArray(AppId, textsArray, from, to, options);

                // convert the response into our TranslationResult array
                var results = new List<AutoTranslationResult>();
                var tempCounter = 0;
                foreach (var translationItem in translationItemsChunk)
                {
                    var microsoftTranslatorResponse = microsoftTranslatorResponses[tempCounter];
                    var translationResult = new AutoTranslationResult
                                                {
                                                    Error = microsoftTranslatorResponse.Error,
                                                    Key = translationItem.Key,
                                                    Text = microsoftTranslatorResponse.TranslatedText,
                                                    OriginalText = translationItem.Text
                                                };
                    results.Add(translationResult);

                    tempCounter++;
                }

                // invoke event with the translation
                this.InvokeTranslationReceived(new TranslationReceivedEventArgs(results.ToArray()));

                if (this.stopRequested) break;
            }
        }
        /// <summary>
        /// Translates an array of strings from the from langauge code to the to language code.
        /// From langauge code can stay empty, in that case the source language is auto-detected, across all elements of the array together.
        /// </summary>
        /// <param name="texts">Array of strings to translate</param>
        /// <param name="from">From language code. May be empty</param>
        /// <param name="to">To language code. Must be a valid language</param>
        /// <param name="contentType">Whether this is plain text or HTML</param>
        /// <returns></returns>
        public static string[] TranslateArray(string[] texts, string from, string to, string contentType)
        {
            string fromCode = string.Empty;
            string toCode   = string.Empty;

            if (from.ToLower() == "Auto-Detect".ToLower() || from == string.Empty)
            {
                fromCode = string.Empty;
            }
            else
            {
                try { fromCode = AvailableLanguages.First(t => t.Value == from).Key; }
                catch { fromCode = from; }
            }

            toCode = LanguageNameToLanguageCode(to);

            string headerValue = GetHeaderValue();
            var    bind        = new BasicHttpBinding
            {
                Name                   = "BasicHttpBinding_LanguageService",
                OpenTimeout            = TimeSpan.FromMinutes(5),
                CloseTimeout           = TimeSpan.FromMinutes(5),
                ReceiveTimeout         = TimeSpan.FromMinutes(5),
                MaxReceivedMessageSize = int.MaxValue,
                MaxBufferPoolSize      = int.MaxValue,
                MaxBufferSize          = int.MaxValue,
                Security               =
                    new BasicHttpSecurity {
                    Mode = BasicHttpSecurityMode.Transport
                }
            };

            var epa = new EndpointAddress(_EndPointAddress + "/V2/soap.svc");
            LanguageServiceClient client = new LanguageServiceClient(bind, epa);

            if (String.IsNullOrEmpty(toCode))
            {
                toCode = "en";
            }

            TranslateOptions options = new TranslateOptions();

            options.Category    = _CategoryID;
            options.ContentType = contentType;

            try
            {
                var translatedTexts = client.TranslateArray(
                    headerValue,
                    texts,
                    fromCode,
                    toCode,
                    options);
                string[] res = translatedTexts.Select(t => t.TranslatedText).ToArray();
                if (_CreateTMXOnTranslate)
                {
                    WriteToTmx(texts, res, from, to);
                }
                return(res);
            }
            catch   //try again forcing English as source language
            {
                var translatedTexts = client.TranslateArray(
                    headerValue,
                    texts,
                    "en",
                    toCode,
                    options);
                string[] res = translatedTexts.Select(t => t.TranslatedText).ToArray();
                if (_CreateTMXOnTranslate)
                {
                    WriteToTmx(texts, res, from, to);
                }
                return(res);
            }
        }
Esempio n. 25
0
 public static void Populate(object obj, ValueNode node, TranslateOptions tOpts = null)
 {
     if (tOpts == null) tOpts = TranslateOptions.Default;
     tOpts.Populate(obj, node);
 }
 public NRefactoryVisitor(TranslateOptions options)
 {
     _options = options;
 }
 public string TextByDomain(string domain, TranslateOptions options, string key, params object[] parameters)
 {
     return Translate.TextByDomain(domain, options, key, parameters);
 }
Esempio n. 28
0
 public ITypeItem TranslateRType(Type rtype, TranslateOptions options)
 {
     return Parent.TranslateRType(rtype, options);
 }
Esempio n. 29
0
 /// <summary>
 /// Initialises a new instance of the ReflectionTranslator class
 /// </summary>
 /// <param name="opts"></param>
 public ReflectionTranslator(TranslateOptions opts)
 {
     translateOpts = opts;
 }
Esempio n. 30
0
        private AmazonS3TranslationPersister CreateSystemUnderTest(TranslateOptions options)
        {
            var wrappedOptions = new OptionsWrapper <TranslateOptions>(options);

            return(new AmazonS3TranslationPersister(_mockS3.Object, wrappedOptions, Mock.Of <ILogger <AmazonS3TranslationPersister> >()));
        }
Esempio n. 31
0
        public static string TranslateString(string src, string to)
        {
            string appID = Settings.Default.BingAppId;
            var svc = new LanguageServiceClient();
            string tolanguage = string.IsNullOrEmpty(to.Trim()) ? "" : (to.Trim() + "  ").Substring(0, 2);
            var translateOptions = new TranslateOptions();
            translateOptions.ContentType = "text/html";
            translateOptions.Category = "general";

            TranslateArrayResponse[] translatedTexts = svc.TranslateArray(appID, new[] { src }, Settings.Default.NeutralLanguageCode, tolanguage, translateOptions);

            return translatedTexts[0].TranslatedText;
        }
Esempio n. 32
0
 public IAsyncResult BeginTranslateArray(string appId, string[] texts, string from, string to, TranslateOptions options, AsyncCallback callback, object asyncState)
 {
     throw new NotImplementedException();
 }