/// <summary> /// Loads a Slob dictionary. /// </summary> /// <param name="fileName">Name of the dictionary file. The dictionary must be in SLOB format.</param> /// <param name="collectKeys">If set to <c>true</c>, the keys of all dictionaries will be collected. When loading multiple dictionaries subsequently, you should set this parameter to true only for the last dictionary loaded.</param> public void LoadDictionary(string fileName, bool collectKeys = true) { var slobReader = new SlobReaderWriter(fileName); var dictionary = slobReader.Read(); dictionary.FileName = fileName; _dictionaries.Add(dictionary); if (collectKeys) { CollectAndSortKeys(); } }
/// <summary> /// Shows the file open dialog, and then imports a plain text file coming from the BEOLINGUS dictionary of TU Chemnitz (see <see href="https://dict.tu-chemnitz.de/doc/faq.de.html"/>. /// Then a file save dialog is presented to store the imported data in the Slob format. /// </summary> /// <param name="controller">The dictionary controller.</param> /// <param name="mainWindow">The main window.</param> public static void ImportTUChemnitzFile(DictionaryController controller, Window mainWindow) { var entryDir = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var dir = new System.IO.DirectoryInfo(entryDir + @"\Content\"); var dlg = new Microsoft.Win32.OpenFileDialog { Filter = "Text files|*.txt" + "|All Files|*.*", Multiselect = false, InitialDirectory = dir.FullName, Title = "Import from a text file" }; if (true == dlg.ShowDialog(mainWindow)) { var teiReader = new Text.TextReader(dlg.FileName); var dictionary = teiReader.Read(); var saveDlg = new Microsoft.Win32.SaveFileDialog { Filter = "SLOB files|*.slob" + "|All Files|*.*", InitialDirectory = dir.FullName, Title = "Save dictionary as .slob file" }; if (true == saveDlg.ShowDialog(mainWindow)) { var slobWriter = new SlobReaderWriter(saveDlg.FileName); slobWriter.Write(dictionary, "text/plain"); controller.LoadDictionary(saveDlg.FileName); } } }
/// <summary> /// Loads a Slob dictionary. /// </summary> /// <param name="fileName">Name of the dictionary file. The dictionary must be in SLOB format.</param> /// <param name="collectKeys">If set to <c>true</c>, the keys of all dictionaries will be collected. When loading multiple dictionaries subsequently, you should set this parameter to true only for the last dictionary loaded.</param> public void LoadDictionary(string fileName, bool collectKeys = true) { var extension = System.IO.Path.GetExtension(fileName).ToLowerInvariant(); IWordDictionary dictionary = null; switch (extension) { case ".ifo": { var starDict = new StarDict.StarDictionaryInMemory(); starDict.Open(fileName); dictionary = starDict; } break; case ".slob": { var slobReader = new SlobReaderWriter(fileName); dictionary = slobReader.Read(); dictionary.FileName = fileName; } break; } if (null != dictionary) { _dictionaries.Add(dictionary); if (collectKeys) { CollectAndSortKeys(); } } }