private async Task AddTranslationAsync(Models.TranslationResult translation) { CurrentTranslation = translation; TranslationsCardItems.Insert(1, translation); AllTranslations.Add(translation); UpdateSource(); ShowNewTranslationControl = false; // Save translation in the file await _roamingStorageService.SaveFileAsync(translation.Filename, translation); // Add the new translation in the summaries list var translationSummaries = _roamingStorageService.Read <List <Models.TranslationSummary> >(StorageConstants.TranslationSummaries); if (translationSummaries == null) { translationSummaries = new List <Models.TranslationSummary>(); } translationSummaries.Add(new Models.TranslationSummary { SearchedDate = DateTime.Now, Filename = translation.Filename }); _roamingStorageService.Save(StorageConstants.TranslationSummaries, translationSummaries); // Remove translations if it exceed size of the card list while (TranslationsCardItems.Count - 1 > AppConstants.MaxSavedTranslations) { TranslationsCardItems.RemoveAt(TranslationsCardItems.Count - 1); } }
private async Task CreateTranslationCardsAsync() { // Remove all cards TranslationsCardItems.Clear(); // Add the card "new translation" TranslationsCardItems.Add("New Translation"); // Retrieve list of translation summaries var translationSummaries = _roamingStorageService.Read <List <Models.TranslationSummary> >(StorageConstants.TranslationSummaries); if (translationSummaries != null) { var lastTranslations = translationSummaries .Where(ts => !ts.Removed) .OrderByDescending(ts => ts.SearchedDate) .Take(AppConstants.MaxSavedTranslations) .Reverse(); foreach (var translationSummary in lastTranslations) { var translation = await _roamingStorageService.ReadFileAsync <Models.TranslationResult>(translationSummary.Filename); AllTranslations.Add(translation); TranslationsCardItems.Insert(1, translation); } if (CurrentTranslation == null || AllTranslations.Last().Filename != CurrentTranslation.Filename) { CurrentTranslation = AllTranslations.Last(); UpdateSource(); } } }
protected override bool ApplyEditionToDatabase() { foreach (TranslationViewModel translation in AllTranslations.Where(t => t.Modified)) { MagicDatabase.UpdateTranslate(Selected, translation.Language, translation.Translation); } return(true); }
private void UcSearch_NavigationRequested(object?sender, NavigationRequestedEventArgs e) { string match = AllTranslations.FirstOrDefault(s => s.StartsWith(e.PathFragment, StringComparison.OrdinalIgnoreCase)); if (match != null) { _lbTranslations.ScrollIntoView(match); _lbTranslations.SelectedItem = match; _ucSearch.SetComboBoxItem(e.PathFragment); } }
private void AddOrSetTranslation(string key, int languageIndex, string text) { // Grab a dictionary of translations from the argument, "key" LanguageTextMap translationsForKey; if (AllTranslations.TryGetValue(key, out translationsForKey) == false) { // Add a new dictionary for this key translationsForKey = AllTranslations.Add(key); } // Set the text translationsForKey[languageIndex] = text; }
private void BuildAllTranslations() { AllTranslations.Clear(); DefaultTranslation = null; if (Selected == null) { return; } //English DefaultTranslation = new TranslationViewModel(_notUpdatableLanguages[1], Selected.ToString()); foreach (ILanguage language in _allLanguages) { string translation = Selected.ToString(language.Id); if (!string.IsNullOrEmpty(translation)) { AllTranslations.Add(new TranslationViewModel(language, translation)); } } }
public bool HasKey(string key) { return(AllTranslations.ContainsKey(key)); }
protected override bool ValidateCurrent() { return(base.ValidateCurrent() && AllTranslations.Any(t => t.Modified) && AllTranslations.All(t => !string.IsNullOrWhiteSpace(t.Translation))); }