Skip to main content

SpellCheckOptions.Dictionaries Property

Gets a list that contains all the added dictionaries.

Namespace: DevExpress.Blazor.RichEdit.SpellCheck

Assembly: DevExpress.Blazor.RichEdit.v23.2.dll

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public IList<DictionaryBase> Dictionaries { get; }

Property Value

Type Description
IList<DictionaryBase>

A list of added dictionaries.

Remarks

The built-in spell check service includes a default dictionary for the en-US culture. The Dictionaries property lists only the dictionaries that you added and does not allow you to access the default dictionary. The component disables the default dictionary after you add another dictionary for the same culture.

Note

Assign a file provider to the FileProvider property so that the service can access dictionary files. The FileNotFoundException error occurs if you do not set the file provider, but add a dictionary.

The Rich Text Editor allows you to add dictionaries of the following types:

Simple Dictionary

A simple dictionary consists of a dictionary and an alphabet file: the dictionary file lists all the words of a particular language, and the alphabet file is an optional file that contains a string with all the capital letters of a language. The Rich Text Editor uses these letters to speed up the construction of spelling suggestions.

You can use the AddToDictionaryAction property to allow users to add words to a dictionary. The example below demonstrates how to add a simple dictionary and use it as a storage for new words:

var DictionaryFiles = new Dictionary<string, string>() {
    { "de-DE", "de//de.dic" },
    // ...
};
var builder = WebApplication.CreateBuilder(args);
// ...
builder.Services.AddDevExpressBlazor().AddSpellCheck(opts => {
    opts.FileProvider = new PhysicalFileProvider(
        Path.Combine(Directory.GetCurrentDirectory(), "Data", "Dictionaries"));
    opts.Dictionaries.Add(new Dictionary {
        DictionaryPath = "de\\de.dic",
        AlphabetPath = "de\\alphabet.txt",
        Culture = "de-DE"
    });
    // ...
    opts.AddToDictionaryAction = (word, culture) => {
        string dictionaryFile = DictionaryFiles.GetValueOrDefault(culture.Name);
        if (dictionaryFile != default) {
            var filePath = opts.FileProvider.GetFileInfo(dictionaryFile).PhysicalPath;
            File.AppendAllText(filePath, "\n" + word);
        }
    };
    opts.MaxSuggestionCount = 7;
});

View Example: How to Customize the Built-in Spell Check Services

ISpell Dictionary

An ISpell dictionary includes a base words file and an affix file. The base words file lists root words with applicable flags. A flag defines which affixes (prefixes and suffixes) can be added to a root, and the affix file lists all flags and their meanings. The Rich Text Editor combines these files to create a complete list of words.

The following code demonstrates how to add an ISpell dictionary:

public void ConfigureServices(IServiceCollection services) {
    services.AddDevExpressBlazor().AddSpellCheck(opts => {
        opts.FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), "Data", "Dictionaries")
        );
        opts.Dictionaries.Add(new ISpellDictionary {
            DictionaryPath = "american.xlg",
            GrammarPath = "english.aff",
            Culture = "en-US"
        });
    });
}

Hunspell Dictionary

Hunspell dictionaries are an improved version of ISpell dictionaries, and have the same structure and settings. The base words file lists root words with applicable flags. A flag defines which affixes (prefixes and suffixes) can be added to a root, and the affix file lists all flags and their meanings. The Rich Text Editor combines these files to create a complete list of words.

The following code demonstrates how to add a Hunspell dictionary:

public void ConfigureServices(IServiceCollection services) {
    services.AddDevExpressBlazor().AddSpellCheck(opts => {
        opts.FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), "Data", "Dictionaries")
        );
        opts.Dictionaries.Add(new HunspellDictionary {
            DictionaryPath = "american.dic",
            GrammarPath = "english.aff",
            Culture = "en-US"
        });
    });
}
See Also