private async Task LoadSupportedLanguagesAsync() { try { SupportedLanguages supportedLanguages = await this.translatorTextService.GetSupportedLanguagesAsync(); this.alternativeTranslationDict = supportedLanguages.Dictionary.ToDictionary(l => l.Key, l => l.Value.Translations); List <Language> translationLanguageList = supportedLanguages.Translation .Select(v => { Language translationLang = v.Value; translationLang.Code = v.Key; return(translationLang); }) .OrderBy(v => v.Name).ToList(); InputLanguageCollection.AddRange(translationLanguageList); OutputLanguageCollection.AddRange(translationLanguageList); OutputLanguage = OutputLanguageCollection.FirstOrDefault(l => l.Code.Equals(DefaultLanguage.Code, StringComparison.OrdinalIgnoreCase)); } catch (Exception ex) { await Util.GenericApiCallExceptionHandler(ex, "Failure loading languages."); } }
private void UpdateOutputLanguageCombobox(LanguageDictionary inputLanguage) { if (inputLanguage != null && previousInputLanguage != inputLanguage) { // update output language combobox List <Language> outputLanguages = inputLanguage?.Translations?.OrderBy(v => v.Name).ToList() ?? new List <Language>(); OutputLanguageCollection.Clear(); OutputLanguageCollection.AddRange(outputLanguages); this.outputLanguageComboBox.SelectedValue = OutputLanguageCollection.FirstOrDefault(v => v.Name.Equals(outputLanguageName, StringComparison.OrdinalIgnoreCase)) ?? OutputLanguageCollection.FirstOrDefault(); } previousInputLanguage = inputLanguage; }
private void InputLanguageChanged() { if (InputLanguage != null) { // update output language combobox string outputLangCode = customOutputLanguage?.Code ?? OutputLanguage?.Code; OutputLanguageCollection.Clear(); OutputLanguageCollection.AddRange(InputLanguageCollection.Where(x => x.Code != InputLanguage.Code)); OutputLanguage = OutputLanguageCollection.FirstOrDefault(l => l.Code.Equals(outputLangCode ?? DefaultLanguage.Code, StringComparison.OrdinalIgnoreCase)) ?? OutputLanguageCollection.FirstOrDefault(); customOutputLanguage = null; // Pivot Image this.detectedLanguageTextBox.Text = $"Detected Language: {InputLanguage.Name}"; } }