Ejemplo n.º 1
0
		/// <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;
		}
Ejemplo n.º 2
0
		/// <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;
		}