Localization in Windows Forms MessageBox (MessageBoxAdv)

15 Jun 20212 minutes to read

Localization is the process of translating the application resources into different language for the specific cultures. MessageBoxAdv control can be localized in any Languages, based on application requirement by following below steps.

The following steps helps to localize the text in MessageBoxAdv:

Step 1: Include the required namespaces at the beginning of the file.

using Syncfusion.Windows.Forms;
Imports Syncfusion.Windows.Forms

Step 2: Need to initialize the LocalizationProvider class, inherited from the ILocalizationProvider interface, before the InitializeComponent call in the constructor of an application.

LocalizationProvider.Provider = new Localizer();
LocalizationProvider.Provider = New Localizer()

Step 3: Add the GetLocalizedString function in the LocalizationProvider class in which provide the Localization content, for the required components used in MessageBoxAdv.

For example:
Here, MessageBoxAdv is localized in German Language.

MessageBoxAdv.Show(this, "Änderungen speichern?", "Datei geändert", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

// localizer inherits the interface ILocationProvider
public class Localizer : ILocalizationProvider
{

public string GetLocalizedString(System.Globalization.CultureInfo culture, string name,object obj)
{

switch (name)
{

// Yes Button in German Language
case ResourceIdentifiers.Yes:
return "Ja";

// No Button in German Language
case ResourceIdentifiers.No:
return "Nein";

// default
default:
return string.Empty;

}

}

}
'MessageBox show
MessageBoxAdv.Show(Me, "Änderungen speichern?", "Datei geändert", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

'localizer inherits the interface of ILocationProvider
Public Class Localizer

Implements ILocalizationProvider

'MessageBoxAdv Localization

Public Function GetLocalizedString(ByVal culture As System.Globalization.CultureInfo, ByVal name As String, ByVal obj As Object) As String Implements ILocalizationProvider.GetLocalizedString

Select Case name

' Yes Button in German Language
Case ResourceIdentifiers.Yes
Return "Ja"

' No Button in German Language
Case ResourceIdentifiers.No
Return "Nein"

' default
Case Else
Return String.Empty

End Select

End Function

End Class

Apply Localization in Windows Forms MessageBox