SIL.CoreImpl.SpellingHelper.EnsureDictionary C# (CSharp) Method

EnsureDictionary() public static method

Make sure that a dictionary exists for the specified writing system. Currently this will NOT do so if its spelling ID is set to None (in angle brackets). Callers may want to include code like this: var wsObj = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem; if (wsObj.SpellCheckingId == "None") // add angle brackets around None wsObj.SpellCheckingId = wsObj.Id.Replace('-', '_'); Enhance JohnT: maybe code like that should be part of this method? But it is meant to just make sure the dictionary exists, once the right SpellCheckingId has been established.
public static EnsureDictionary ( int ws, ILgWritingSystemFactory wsf ) : ISpellEngine
ws int
wsf ILgWritingSystemFactory
return ISpellEngine
		public static ISpellEngine EnsureDictionary(int ws, ILgWritingSystemFactory wsf)
		{
			string dictId = RawDictionaryId(ws, wsf);
			if (dictId == null)
				return null; // No Dictionary ID set. Caller has probably messed up, but we can't fix it here.
			EnsureDictionary(dictId);
			// Now it should exist!
			return GetSpellChecker(dictId);
		}

Same methods

SpellingHelper::EnsureDictionary ( string dictId ) : void

Usage Example

Ejemplo n.º 1
0
        public void EnsureDictionaryDoesNotOverwriteNonVernacularDictionary()
        {
            const string dictId   = "nonvern";
            const string testWord = "testWord";

            Directory.CreateDirectory(SpellingHelper.GetSpellingDirectoryPath());
            var filePath = SpellingHelper.GetDicPath(SpellingHelper.GetSpellingDirectoryPath(), dictId);

            // Wipe out any files related to our fake test dictionary
            File.Delete(SpellingHelper.GetExceptionFileName(filePath));
            File.Delete(filePath);
            File.Delete(Path.ChangeExtension(filePath, ".aff"));

            //build new fake test dictionary that is not vernacular
            var nonverndict = @"10" + Environment.NewLine + testWord + Environment.NewLine;
            var nonvernaff  = @"SET UTF-8" + Environment.NewLine + "KEEPCASE C" + Environment.NewLine;

            File.WriteAllText(filePath, nonverndict);
            File.WriteAllText(Path.ChangeExtension(filePath, ".aff"), nonvernaff);
            //SUT
            SpellingHelper.EnsureDictionary(dictId);
            //read back the hopefully unaffected dictionary
            var contents = File.ReadAllText(filePath);

            Assert.That(contents, Is.Not.StringContaining(SpellingHelper.PrototypeWord));
            Assert.That(contents, Contains.Substring(testWord));
        }
All Usage Examples Of SIL.CoreImpl.SpellingHelper::EnsureDictionary