Back to Devexpress

How to: Switch Between Languages

windowsforms-3159-controls-and-libraries-spell-checker-examples-how-to-switch-between-languages.md

latest2.5 KB
Original Source

How to: Switch Between Languages

  • Apr 28, 2023
  • 2 minutes to read

When the dictionary is created and added to the spell checker dictionaries collection, its language is indicated by the DictionaryBase.Culture property. When you need to change the language to be checked, you should change the SpellChecker.Culture property.

For example, when you have to spell check a section of French text, you may use the following code to switch the languages.

csharp
using DevExpress.XtraSpellChecker;
using System.Globalization;
//...

public partial class Form1 : RibbonForm
{
    Boolean hasDictionary = false;
    CultureInfo culture_info;

    public Form1() {
        // First we create a CultureInfo object corresponding to the selected language
        culture_info = new CultureInfo("fr-FR");

        // Make sure that the spell checker component has a dictionary of the specified culture
        foreach (SpellCheckerDictionaryBase dict in spellChecker1.Dictionaries)
        {
            if (dict.Culture.Equals(culture_info)) hasDictionary = true;
        }
    }

    private void switchCultureBtn_ItemClick(object sender, ItemClickEventArgs e)
    {
        // If the dictionary exists we can safely change the XtraSpellChecker culture
        if (hasDictionary) spellChecker1.Culture = culture_info;
    }
}
vb
Imports DevExpress.XtraSpellChecker
Imports System.Globalization
'...

Partial Public Class Form1
    Inherits RibbonForm

    Private hasDictionary As Boolean = False
    Private culture_info As CultureInfo

    Public Sub New()
        ' First we create a CultureInfo object corresponding to the selected language
        culture_info = New CultureInfo("fr-FR")

        ' Make sure that the spell checker component has a dictionary of the specified culture
        For Each dict As SpellCheckerDictionaryBase In spellChecker1.Dictionaries
            If dict.Culture.Equals(culture_info) Then
                hasDictionary = True
            End If
        Next dict
    End Sub

    Private Sub switchCultureBtn_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
        ' If the dictionary exists we can safely change the XtraSpellChecker culture
        If hasDictionary Then
            spellChecker1.Culture = culture_info
        End If
    End Sub
End Class