private async Task <List <string> > TranslateStringsUsingGoogleAsync(string language, string apiKey, string appName, List <string> strings) { string from = MultiString.GetPrimaryLanguage(MultiString.DefaultLanguage); string to = MultiString.GetPrimaryLanguage(language); List <string> newStrings = new List <string>(); int total = strings.Count(); int skip = 0; while (total > 0) { TranslateService service = new TranslateService(new BaseClientService.Initializer() { ApiKey = apiKey, ApplicationName = appName, }); TranslationsListResponse resp = await service.Translations.List(strings.Skip(skip).Take(40).ToList(), to).ExecuteAsync(); List <string> returnedStrings = (from r in resp.Translations select r.TranslatedText).ToList(); returnedStrings = (from r in returnedStrings select Utility.HtmlDecode(r)).ToList(); newStrings.AddRange(returnedStrings); skip += returnedStrings.Count(); total -= returnedStrings.Count(); } return(newStrings); }
private async Task <List <string> > TranslateStringsUsingMicrosoftAsync(string language, string clientId, List <string> strings) { string from = MultiString.GetPrimaryLanguage(MultiString.DefaultLanguage); string to = MultiString.GetPrimaryLanguage(language); MSTranslate msTrans = new MSTranslate(clientId); int total = strings.Count(); int skip = 0; List <string> newStrings = new List <string>(); while (total > 0) { List <string> returnedStrings = await msTrans.TranslateAsync(from, to, strings.Skip(skip).Take(40).ToList()); newStrings.AddRange(returnedStrings); skip += returnedStrings.Count(); total -= returnedStrings.Count(); } return(newStrings); }