Localization Support in Windows Forms GridGrouping (GridGroupingControl)

28 Apr 20217 minutes to read

Localization support allows you to set the content according to the language or culture of a specific country or region. Essential Grid provides localization support for all controls.

Use Case Scenarios

With this feature, you can localize the options in the grid to display the content according to the language or culture of a specific country or region.

To open sample project, navigate to the following sample location in your system:

<Install Location>\Syncfusion\EssentialStudio\[Version Number]\Windows\Grid.Grouping.Windows\Samples\Localization Samples\Localization Demo

Adding Localization Support to Grid Controls

To localize the content, create a class file and add ILocalizationProvider interface to the class. Assign the required content to be displayed to DynamicFilterResourceIdentifiers, GroupingResourceIdentifiers and GridResourceIdentifiers of GetLocalizedString method as illustrated in the following code.

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

   switch (name)
   {
      case DynamicFilterResourceIdentifiers.StartsWith:

        if (comparerList)
            return "empieza con";

        else
            return "StartsWith";                

      case GroupingResourceIdentifiers.RecordNavigatorOF:

        if (recordNavigBar)
            return "von";

        else
            return "Of";

//Drag group column.

      case GroupingResourceIdentifiers.DragColumnHeaderHereText:
            return "Ziehen Sie die Spaltenüberschrift";

      case DynamicFilterResourceIdentifiers.SortAtoZ:

        if (office2007Filter)
            return "&SortierenAbisZ";

        else
            return "&SortAtoZ";

      default:
            return string.Empty;
      }
  }
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

Case DynamicFilterResourceIdentifiers.StartsWith

If comparerList Then
Return "empieza con"

Else
Return "StartsWith"
End If

Case GroupingResourceIdentifiers.RecordNavigatorOF

If recordNavigBar Then
Return "von"

Else
Return "Of"
End If

Case DynamicFilterResourceIdentifiers.SortAtoZ

If office2007Filter Then
Return "&SortierenAbisZ"

Else
Return "&SortAtoZ"
End If

Case Else
Return String.Empty
End Select
End Function

Add the following table items to the above code example by substituting the identifiers and Enum values as in they correspond in the table.

DynamicFilterResourceIdentifiers ENUM
StartsWith CustomAutoFilterGreaterThan Office2007FilterOK
EndsWith SelectAll Office2007FilterCancel
Equals SortAtoZ CustomAutoFilter
GreaterThan SortZtoA CustomAutoFilterLessThan
GreaterThanOrEqualTo ClearFilterFrom Office2007FilterEquals
LessThan All CustomAutoFilterEqual
LessThanOrEqualTo Custom CustomAutoFilterNotEqual
Like Empty FieldDialogBox
Match ExpressionMATCH NotEquals
ResourceIdentifiers OK
GridResourceIdentifiers Cannot change part of a merged cell

This will generate the following output.

Localization-Support_img1

Localization Support for ComboBox Cell

Localization support allows you to set the content in a ComboBox cell according to the language or culture of a specific country or region. You can localize the content in the ComboBox cell using the ConvertToString method of Status class.

Use Case Scenarios

With this feature, you can localize the options in the ComboBox cell to display the content according to the language or culture of a specific country or region.

To get DataGrid samples from the dashboard:

  1. Open Syncfusion Dashboard.
  2. Select UI > Windows Forms.
  3. Click Run Samples.
  4. Select Data Grid.
  5. Expand Localization samples in the left panel of sample browser and click ComboBoxCellLocalization Demo.

Adding Localization Support to ComboBox Cell

The following code example illustrates how to add localization support to ComboBox cell using ConvertToString method of Status class.

public object ConvertToString(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{

    switch ((Status)value)

      {case Status.Divorced:
        return "geschieden"
        
      case Status.Married:
        return "verheiratet";

      case Status.Single:
        return "Einzel";

      case Status.Widow:
        return "Witwe";

      default:
        return string.Empty;
  }}
Private Overloads Function ConvertFromString(ByVal context As ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object

Select Case CStr(value)

Case "geschieden"
Return Status.Divorced

Case "verheiratet"
Return Status.Married

Case "Einzel"
Return Status.Single

Case "Witwe"
Return Status.Widow

Case Else
Return Nothing
End Select
End Function

Localization-Support_img2

Localization By Using Satellite Assemblies

A Satellite Assembly is a compiled library that contains resources that can be localized. You can use satellite assemblies to create a multilingual application. You can design and deploy your solution to multiple cultures, rather than using hard coding strings into your main application. Satellite assemblies are auto generated, and do not contain any code. Hence, they cannot be executed as the main assembly. Localization processes can be performed by using Satellite Assemblies without recompiling the main assembly. Localization can be applied to Grid, Grid Grouping, and Pivot Grid controls by using Satellite Assemblies.

Creating a Satellite Assembly

The following components are required for creating a Satellite Assembly:

  1. A text file, which holds different strings that has to be localized.
  2. A resource file, which is created by using the Text file. The resource file has the “.Resources” extension.

The following steps illustrate creating a Satellite Assembly:

  1. Open Visual Studio Command Prompt with Administrator privileges.
  2. Enter the following command for creating resource file from the text file:

    Resgen Text_file.txt Resource_File.resources

    Localization-Support_images3

  3. You can modify the resource file according to your requirements by using the Resource Editor.

Localization-Support_images4

  1. Create the satellite assembly from the resource file by using the following command:

    al /t:lib /culture:de-DE /out:\Syncfusion.GridHelperClasses.Windows.resources.dll /v:1.1.0.0 /delay+ /keyf::\\sf.publicsnk /embed:\Syncfusion. GridHelperClasses.Windows.Localization.SR.de-DE.Resources

  2. After creating the satellite assembly, you must have the assembly signed to access the resources in the assembly. The signing operation is done by using the following code:

    Sn –Vr \Syncfusion.GridHelperClasses.Windows.resources.dll

  3. Finally, the satellite assembly created is placed in a folder at the following path:

    <Location of Program>\bin\debug\de-DE (German Culture)

    NOTE

    The name of the subfolder in Debug folder differs based on the culture of the application. For example, fr-FR is used for the French Culture, and so on.

Similarly, you can create satellite assemblies for resource files of Windows Grid, Grid Grouping, and Pivot Grid controls. You can find the resource files for Windows Grid, Grid Grouping, and Pivot Grid controls at the following paths respectively:

  • Grid

    \Syncfusion\EssentialStudio\\Windows\Grid.Windows\Samples\ Localization Samples\Localization Demo\CS\Resources\SR.resources
  • Grid Grouping

    \Syncfusion\EssentialStudio\\Windows\Grid.Grouping.Windows\ Samples\Localization Samples\Localization Demo\CS\Resources\SR.resources
  • Pivot Grid

_\Syncfusion\EssentialStudio\\Windows\PivotGrid.Windows\_

Samples\Localization\ Localization using Satellite Assemblies\CS\Resources\SR.resources