private void ProcessResults(List <Dictionary <string, string> > results) { // Report initial progress currentStatus.Value = ImportState.ConvertToTranslations; progressReport.SetTotalSteps(results.Count); // Check if we want to overwrite the translations if (Resolution == ConflictResolution.Overwrite) { // If so, completely clear the translations DictionaryToEdit.AllTranslations.Clear(); } // Go through each row of the results string key; TranslationDictionary.LanguageTextMap translations; foreach (Dictionary <string, string> row in results) { // First, search for the key column if ((row != null) && (row.TryGetValue(KeysColumnName, out key) == true)) { // Check if this key introduces a conflict translations = null; if (DictionaryToEdit.AllTranslations.ContainsKey(key) == false) { // If no conflicts, add a new translations dictionary translations = DictionaryToEdit.AllTranslations.Add(key); } else if (Resolution == ConflictResolution.AppendIgnore) { // If we're ignoring conflicts, skip this row. continue; } else { // Otherwise, overwrite the key with a new translations dictionary translations = DictionaryToEdit.AllTranslations.Add(key); } // Go through each cell in each row foreach (KeyValuePair <string, string> cell in row) { // Make sure the language list is supported if (DictionaryToEdit.SupportedLanguages.Contains(cell.Key) == true) { // If so, add it and its text into the translations dictionary translations[cell.Key] = cell.Value; } } } // Indicate progress progressReport.IncrementCurrentStep(); } // Apply the changes currentStatus.Value = ImportState.Serializing; DictionaryToEdit.UpdateSerializedTranslations(progressReport); }
public List <TranslationCollection> UpdateSerializedTranslations(ProgressReport report = null) { // Check if we need to report our progress if (report != null) { // Set the number of steps involved in serialization report.SetTotalSteps(AllTranslations.Count); } // Grab a soft-copy of all translations KeyLanguageTextMap translationCopy = AllTranslations; // Clear the translations list (this needs to happen AFTER calling AllTranslations' getter) translations.Clear(); // Go through all the keys TranslationCollection collectionToAdd; LanguageTextPair pairToAdd; foreach (KeyValuePair <string, LanguageTextMap> collection in translationCopy) { // Create a new collection of translations collectionToAdd = new TranslationCollection(collection.Key); // Go through all translations foreach (KeyValuePair <int, string> pair in collection.Value) { // Create a new pair pairToAdd = new LanguageTextPair(pair.Key, pair.Value); // Add the pair to the collection collectionToAdd.AllTranslations.Add(pairToAdd); } // Add new collection to the list translations.Add(collectionToAdd); // Check if we need to report our progress if (report != null) { // Increment report.IncrementCurrentStep(); } } // Indicate the dictionary matches the serialization IsAllTranslationsSerialized = true; // Return the updated translations list return(translations); }