public void AddCustomTranslations(ILanguage sourceLanguage, ILanguage destLanguage, IDictionary<string,string>customTranslations) { if (sourceLanguage == null) { throw new ArgumentNullException("soureLanguage"); } if (destLanguage == null) { throw new ArgumentNullException("destLanguage"); } if (customTranslations == null) { throw new ArgumentNullException("customTranslations"); } // TODO: This could be done Async IList<BingTranslatorService.Translation> translationList = new List<BingTranslatorService.Translation>(); foreach (string key in customTranslations.Keys) { if (!string.IsNullOrWhiteSpace(key)) { BingTranslatorService.Translation translation = new BingTranslatorService.Translation(); translation.OriginalText = key; translation.TranslatedText = customTranslations[key]; // make it less than 5 because that is the max value for machine translations translation.Rating = this.CustomTranslationRating; translation.RatingSpecified = true; translation.Sequence = 0; translation.SequenceSpecified = true; translationList.Add(translation); } } // TODO: We should batch these into 100 because according to http://msdn.microsoft.com/en-us/library/ff512409.aspx that is the limit using (BingTranslatorService.SoapService client = new BingTranslatorService.SoapService()) { client.AddTranslationArray(this.ApiKey, translationList.ToArray(), sourceLanguage.Language, destLanguage.Language, this.TranslateOptions); } }
public void AddCustomTranslations(ILanguage sourceLanguage, ILanguage destLanguage, IDictionary <string, string> customTranslations) { if (sourceLanguage == null) { throw new ArgumentNullException("soureLanguage"); } if (destLanguage == null) { throw new ArgumentNullException("destLanguage"); } if (customTranslations == null) { throw new ArgumentNullException("customTranslations"); } // TODO: This could be done Async IList <BingTranslatorService.Translation> translationList = new List <BingTranslatorService.Translation>(); foreach (string key in customTranslations.Keys) { if (!string.IsNullOrWhiteSpace(key)) { BingTranslatorService.Translation translation = new BingTranslatorService.Translation(); translation.OriginalText = key; translation.TranslatedText = customTranslations[key]; // make it less than 5 because that is the max value for machine translations translation.Rating = this.CustomTranslationRating; translation.RatingSpecified = true; translation.Sequence = 0; translation.SequenceSpecified = true; translationList.Add(translation); } } // TODO: We should batch these into 100 because according to http://msdn.microsoft.com/en-us/library/ff512409.aspx that is the limit using (BingTranslatorService.SoapService client = new BingTranslatorService.SoapService()) { client.AddTranslationArray(this.ApiKey, translationList.ToArray(), sourceLanguage.Language, destLanguage.Language, this.TranslateOptions); } }