/// <summary> /// Asks the service represented by the TranslatorContainer for a list /// of all supported languages. /// </summary> /// <returns>All supported Languages.</returns> public static Language[] GetSupportedLanguages(String accountKey) { // Call a InitializeTranslatorContainer to get a TranslatorContainer // that is configured to use your account. TranslatorContainer tc = InitializeTranslatorContainer(accountKey); // Generate the query var languagesForTranslationQuery = tc.GetLanguagesForTranslation(); // Call the query to get the results as an Array var availableLanguages = languagesForTranslationQuery.Execute().ToArray(); // Return list of supported languages return(availableLanguages); }
/// <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[randomIndex]; return(selectedLanguage); }