Localization in Windows Forms Form (SfForm)

2 Oct 20233 minutes to read

Localization is the process of translating the application resources into different language for the specific cultures. The SfForm can be localized by adding resource file. Application culture can be changed by setting CurrentUICulture before InitializeComponent method.

Localize at Sample Level

To localize the SfForm based on CurrentUICulture using resource files, follow the below steps.

  1. Create new folder and named as Resources in your application.

  2. Add the default resource file of SfForm into Resources folder. You can download the Syncfusion.Shared.Base.resx here.

Added default resource file of winforms sfform shown in solution explorer

  1. Right-click on the Resources folder, select Add and then NewItem.

  2. In Add New Item wizard, select the Resource File option and name the filename as Syncfusion.Shared.Base.<culture name>.resx. For example, have to give name as Syncfusion.Shared.Base.de-DE.resx for German culture.

Adding new resource file through Add New Item wizard

  1. The culture name that indicates the name of language and country.
  2. Now, select Add option to add the resource file in Resources folder.

Added resource file shown in solution explorer

  1. Add the Name/Value pair in Resource Designer of Syncfusion.Shared.Base.de-DE.resx file and change its corresponding value to corresponding culture.

Modifying the resources based on culture for localizing winforms sfform

  1. Now, set the CurrentCulture of the Application before the InitializeComponent method and Run the sample.

    public Form1()
    {
        System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
        System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE");
        InitializeComponent();
    }
    Public Sub New()
    	System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("de-DE")
    	System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("de-DE")
    	InitializeComponent()
    End Sub

Winforms sfform localized with modified resources

Editing Default Resource File

The default resource file can be edited by adding it to Resources folder of the application where SfForm reads the static texts from here. The default resource file can be download from here.

Added default resource file of winforms sfform shown in solution explorer

Now, change the Name/Value pair in Resource Designer of Syncfusion.Shared.Base.resx file.

Modifying default resource file of winforms sfform

Modifying default resource file of winforms sfform

Localize Resource File with Different Assembly or Namespace

If resource (.resx) files are added into different assembly other than start up application, call the SetResources method of LocalizationResource follows.

public Form1()
{
   System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE");
   LocalizationResourceBase.SetResources(typeof(ClassName).Assembly, "NameSpace");
   InitializeComponent();
}
public Form1()
{
    System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("de-DE")
    LocalizationResourceBase.SetResources(GetType(ClassName).Assembly, "NameSpace")
    InitializeComponent()
}