/// <summary> /// Get a dictionary for the specified writing system, or null if we don't know of one. /// We ideally want a dictionary that exactly matches the specified writing system, that is, /// dict.Information.Language == the SpellCheckDictionary of the writing system. /// If we can't find such a dictionary, for major languages (those that have non-trivial base dictionary files), /// we will return a dictionary that shares a prefix, for example, 'en' when looking for 'en_US' or vice versa. /// This is not allowed for minority languages (where the dictionary is one we created ourselves that is empty, /// and all the spelling information is in the overrides kept by Enchant); we return null if we can't find /// an exact match or an approximate match that is a 'major' language dictionary. /// Note: a similar algorithm is unfortunately implemented in VwRootBox::GetDictionary /// and in WritingSystemPropertiesDialog.PopulateSpellingDictionaryComboBox. /// </summary> public static Enchant.Dictionary GetDictionary(int ws, SIL.FieldWorks.Common.COMInterfaces.ILgWritingSystemFactory wsf) { string dictId = DictionaryId(ws, wsf); if (dictId == null) { return(null); } Dictionary dict = Enchant.Broker.Default.RequestDictionary(dictId); IWritingSystem engine = wsf.get_EngineOrNull(ws); if (engine == null) { return(dict); // should never happen? Can't verify ID so go ahead and return it. } if (dict.Information.Language == engine.SpellCheckDictionary) { return(dict); // exact match } if (IsPrivateDictionary(dict.Information.Language)) { return(null); // private dictionaries may only be returned when matching exactly. } return(dict); }
/// <summary> /// Ensure that the spelling dictionary (if any) for the specified ws will give the specified /// answer regarding the specified word. /// </summary> public static void SetSpellingStatus(string word, int ws, SIL.FieldWorks.Common.COMInterfaces.ILgWritingSystemFactory wsf, bool fCorrect) { using (Enchant.Dictionary dict = GetDictionary(ws, wsf)) { if (dict == null) { return; // no spelling dict to update. } SetSpellingStatus(word, fCorrect, dict); } }
/// <summary> /// Return the string which should be used to request a dictionary for the specified writing system, /// or null if none will work. /// </summary> /// <param name="ws"></param> /// <param name="wsf"></param> /// <returns></returns> private static string DictionaryId(int ws, SIL.FieldWorks.Common.COMInterfaces.ILgWritingSystemFactory wsf) { IWritingSystem wsEngine = wsf.get_EngineOrNull(ws); if (wsEngine == null) { return(null); } string wsId = wsEngine.SpellCheckDictionary; if (String.IsNullOrEmpty(wsId) || wsId == "<None>") { return(null); } if (Enchant.Broker.Default.DictionaryExists(wsId)) { return(wsId); } // If no dictionary exists which matches the language name exactly then // search for one. // // Enchant.Broker.Default.Dictionaries is a list of the dictionaries found in // C:\Documents and Settings\USERNAME\Application Data\enchant\myspell // followed by the dictionaries found in Open Office. // C:\Program Files\OpenOffice.org 2.4\share\dict\ooo // The Views code is also programmed to find the first match. foreach (Enchant.DictionaryInfo info in Enchant.Broker.Default.Dictionaries) { if (info.Language.StartsWith(wsId)) { return(info.Language); } } return(null); }
/// <summary> /// Returns true exactly if GetDictionary() with the same arguments will retrieve a dictionary (rather than null). /// </summary> /// <param name="ws"></param> /// <param name="wsf"></param> /// <returns></returns> public static bool DictionaryExists(int ws, SIL.FieldWorks.Common.COMInterfaces.ILgWritingSystemFactory wsf) { return(GetDictionary(ws, wsf) != null); }