Dictionaries
RadSpellChecker comes with one predefined dictionary which checks the English language. In case you need a dictionary for another language, you check the Dictionaries for RadSpellChecker article where our customers have provided their own implementation of dictionaries for the different languages. The following section demonstrates how you can load one of these dictionaries in your own project.
If you are experiencing any difficulties with downloading the dictionaries from the Code Library, feel free to download them from this forum post.
Loading a custom dictionary
To access the RadSpellChecker related types, you need to include the Telerik.WinControls.SpellChecker.Proofing namespace
Let's say that you have chosen one of the dictionary files provided in this article, for example, the German (Germany) (de-DE) dictionary.
Now let's load the dictionary file (*.TDF) in our project as a project resource.
Further, we should create a WordDictionary descendant. Let's call the descendant GermanDictionary. In this class we should override the EnsureDictionaryLoadedOverride method, create a MemoryStream based on the TDF resource and call the Load method of the WordDictionary class passing the MemoryStream as a parameter. The code looks as shown below:
Creating a custom WordDictionary
public class GermanDictionary : WordDictionary
{
protected override void EnsureDictionaryLoadedOverride()
{
using (MemoryStream ms = new MemoryStream(SamplesCS.Properties.Resources.de_DE))
{
this.Load(ms);
}
}
}
Public Class GermanDictionary
Inherits WordDictionary
Protected Overrides Sub EnsureDictionaryLoadedOverride()
Using ms As MemoryStream = New MemoryStream(My.Resources.de_DE)
Me.Load(ms)
End Using
End Sub
End Class
4. Next, we should add the custom dictionary to our RadSpellChecker. Please note, that dictionaries are added per control types basis using the GetControlSpellChecker method. This way, using just one RadSpellChecker instance you can add different dictionaries of one and the same language in the context of different controls that need to be spell checked. For example, here we are going to add a dictionary that will be used only for RadTextBox instances. In addition, we need to define a CultureInfo that will be stored together with the dictionary in the list of dictionaries. This culture will serve as a primary key for the respective dictionary in the dictionaries collection.
private static readonly CultureInfo GermanCulture = CultureInfo.GetCultureInfo("de-DE");
Friend Shared GermanCulture As CultureInfo = CultureInfo.GetCultureInfo("de-DE")
Adding a dictionary
IControlSpellChecker textBoxControlSpellChecker = this.radSpellChecker1.GetControlSpellChecker(typeof(RadTextBox));
DocumentSpellChecker documentSpellChecker = textBoxControlSpellChecker.SpellChecker as DocumentSpellChecker;
documentSpellChecker.AddDictionary(new GermanDictionary(), GermanCulture);
Dim textBoxControlSpellChecker As IControlSpellChecker = Me.radSpellChecker1.GetControlSpellChecker(GetType(RadTextBox))
Dim documentSpellChecker As DocumentSpellChecker = TryCast(textBoxControlSpellChecker.SpellChecker, DocumentSpellChecker)
documentSpellChecker.AddDictionary(New GermanDictionary(), GermanCulture)
5. Now, we have to set the SpellCheckingCulture property that will determine which of the available dictionaries will be used (in case dictionaries of different languages are added).
documentSpellChecker.SpellCheckingCulture = GermanCulture;
documentSpellChecker.SpellCheckingCulture = GermanCulture
If this property is not set, RadSpellChecker will try check if there is a dictionary whose culture is the CurrentUICulture of the application. If such a dictionary is found, RadSpellChecker will use that dictionary.