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(); } } }
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)); } } }