public IList <SubtitleTools.Common.ISO639.Language> GetSupportedLanguages() { var translatorContainer = new TranslatorContainer(ServiceUri) { Credentials = new NetworkCredential(AccountKey, AccountKey) }; var languagesForTranslationList = translatorContainer.GetLanguagesForTranslation().Execute().ToList(); var iso639LanguagesCodes = new LanguagesCodes(); var supportedLanguages = new List <SubtitleTools.Common.ISO639.Language>(); foreach (var item in languagesForTranslationList) { var lang = iso639LanguagesCodes.FirstOrDefault(x => x.ISO639.Equals(item.Code, StringComparison.InvariantCultureIgnoreCase)); var languageName = lang == null ? item.Code : lang.LanguageName; supportedLanguages.Add(new SubtitleTools.Common.ISO639.Language { ISO639 = item.Code, LanguageName = languageName, IdSubLanguage = lang == null ? string.Empty : lang.IdSubLanguage, ISO6393166_1 = lang == null ? string.Empty : lang.ISO6393166_1 }); } return(supportedLanguages); }
/// <summary> /// Returna list of language codes /// </summary> public void GetLanguagesForTranslation() { Initalize(); try { var query = context.GetLanguagesForTranslation(); query.BeginExecute(OnGetLanguageQueryComplete, query); } catch (DataServiceQueryException ex) { Debug.WriteLine("An error occurred during query execution." + ex.ToString()); throw new Exception("An error occurred during query execution.", ex); } }
/// <summary> /// Asks the service represented by the TranslatorContainer for a list /// of all supported languages and then picks one at random. /// </summary> /// <param name="tc">The TranslatorContainer to use.</param> /// <returns>A randomly selected Language.</returns> private static Language PickRandomLanguage(TranslatorContainer tc) { // Used to generate a random index var random = new Random(); // Generate the query var languagesForTranslationQuery = tc.GetLanguagesForTranslation(); // Call the query to get the results as an Array var availableLanguages = languagesForTranslationQuery.Execute().ToArray(); // Generate a random index between 0 and the total number of items in the array var randomIndex = random.Next(availableLanguages.Count()); // Select the randomIndex'th value from the array var selectedLanguage = availableLanguages[10]; // selectedLanguage = "en"; return(selectedLanguage); }