Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

ISpellCheckService.Culture Property

Returns the culture of an open document.

Namespace: DevExpress.Blazor.RichEdit

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
CultureInfo Culture { get; set; }

#Property Value

Type Description
CultureInfo

An open document’s culture.

#Remarks

The Rich Text Editor’s DocumentCulture property specifies an open document’s culture and allows you to change it at runtime. Inside a custom spell check service’s code, use the Culture property to get the current document culture. Depending on this culture, you can change the behavior of your service.

The following code snippet implements an ISpellCheckService interface and check spelling only for documents in English:

C#
using DevExpress.Blazor.RichEdit;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

public class MySpellCheckService : ISpellCheckService {
    public CultureInfo Culture { get; set; }
    public bool AddToDictionaryEnabled { get; }
    public int MaxSuggestionCount { get; }
    string PathToDictionary { get;}
    List<string> CorrectWords { get;}

    public MySpellCheckService(string path) {
        PathToDictionary = path;
        Culture = CultureInfo.InvariantCulture;
        AddToDictionaryEnabled = true;
        MaxSuggestionCount = 7;
        CorrectWords = File.ReadLines(PathToDictionary).ToList();
        CorrectWords.Sort();
    }

    public void AddToDictionary(string word) {
        if (Culture.TwoLetterISOLanguageName == "en") {
            word = word.ToLower();
            int placeToInsert = CorrectWords.BinarySearch(word);
            CorrectWords.Insert(placeToInsert, word);
            File.AppendAllText(PathToDictionary, word + '\n');
        }
    }

    public bool CheckWordSpelling(string word) {
        if (Culture.TwoLetterISOLanguageName == "en") {
            int index = CorrectWords.BinarySearch(word.ToLower());
            return (index >= 0);
        }
        return false;
    } 

    public string[] GetSpellingSuggestions(string word) {
        List<string> suggestions = new List<string>();
        // Generate suggestions and add them to the list
        return suggestions.ToArray();
    }
}

Refer to the following topic for more information about the built-in spell check service: Spell Check.

See Also