Back to Devexpress

DashboardLocalizer Class

dashboard-devexpress-dot-dashboardcommon-dot-localization.md

latest8.8 KB
Original Source

DashboardLocalizer Class

Provides localized strings for the dashboard user interface elements.

Namespace : DevExpress.DashboardCommon.Localization

Assembly : DevExpress.Dashboard.v25.2.Core.dll

NuGet Package : DevExpress.Dashboard.Core

Declaration

csharp
public class DashboardLocalizer :
    XtraLocalizer<DashboardStringId>,
    ILocalizeCustomFunctionDescription
vb
Public Class DashboardLocalizer
    Inherits XtraLocalizer(Of DashboardStringId)
    Implements ILocalizeCustomFunctionDescription

Remarks

DevExpress products allow you to specify localization resource values at runtime. This approach can be useful when a resource value is not known at design time, or if you need to set the resource value based on a runtime condition.

Use the following localizer objects to translate resources:

Important

Not all strings can be translated with Localizers. We recommend that you use the Localizer classes to override the localization of specific strings only. Use resources to localize the UI because some components contain form resources (for example, the “Export to PDF” dialog) that should be translated with satellite assemblies.

Follow the steps below to localize your application with this approach:

  1. Create a descendant of the localizer class.

  2. Override the descendant’s GetLocalizedString method. This method is called for each localized string and returns the string’s value, and returns values that are contained within the DashboardWinStringId (in the DashboardWinLocalizer class) or the DashboardStringId (in the DashboardLocalizer class) resource string enumeration by default. Override the GetLocalizedString method to return your custom string values.

  3. Assign an instance of your class to the static Active property of the localizer class from which it was derived to use this localizer.

The following example demonstrates how to localize the UI of the Dashboard Designer into Spanish:

csharp
public class SpanishDashboardWinLocalizer : DashboardWinLocalizer {
   public override string Language { get { return "Español"; }}
   public override string GetLocalizedString(DashboardWinStringId id) {
      string ret = "";
      switch(id) {
         // ...
         case DashboardWinStringId.CommandNewDashboardCaption : return "Nuevo"; 
         case DashboardWinStringId.CommandOpenDashboardCaption : return "Abrir"; 
         case DashboardWinStringId.CommandSaveDashboardCaption : return "Guardar"; 
         case DashboardWinStringId.CommandSaveAsDashboardCaption : return "Guardar como"; 
         case DashboardWinStringId.CommandUndoCaption : return "Deshacer"; 
         case DashboardWinStringId.CommandRedoCaption : return "Rehacer"; 
         case DashboardWinStringId.CommandNewDataSourceCaption : return "Nueva Fuente de Datos"; 
         case DashboardWinStringId.CommandEditDataSourceCaption : return "Editar"; 
         case DashboardWinStringId.CommandDeleteDataSourceCaption : return "Eliminar";
         // ...
         default:
            ret = base.GetLocalizedString(id);
            break;
      }
      return ret;
   }
}
public class SpanishDashboardCoreLocalizer : DashboardLocalizer {
   public override string Language { get { return "Español"; }}
   public override string GetLocalizedString(DashboardStringId id) {
      string ret = "";
      switch(id) {
         // ...
         case DashboardStringId.DateTimeGroupIntervalYear : return "Año"; 
         case DashboardStringId.SummaryTypeSum : return "Suma"; 
         case DashboardStringId.DescriptionItemArgument : return "Argumento"; 
         case DashboardStringId.DescriptionArguments : return "Argumentos"; 
         case DashboardStringId.DescriptionItemValue : return "Valor"; 
         case DashboardStringId.DescriptionValues : return "Valores"; 
         // ...
         default:
            ret = base.GetLocalizedString(id);
            break;
      }
      return ret;
   }
}
vb
Public Class SpanishDashboardWinLocalizer 
   Inherits DashboardWinLocalizer 
   Public Overrides ReadOnly Property Language() As String
      Get
         Return "Español"
      End Get
   End Property

   Public Overrides Function GetLocalizedString(ByVal id As DashboardWinStringId) As String
      Dim ret As String = ""
      Select Case id
         ' ...
         Case DashboardWinStringId.CommandNewDashboardCaption : Return "Nuevo" 
         Case DashboardWinStringId.CommandOpenDashboardCaption : Return "Abrir"
         Case DashboardWinStringId.CommandSaveDashboardCaption : Return "Guardar" 
         Case DashboardWinStringId.CommandSaveAsDashboardCaption : Return "Guardar como" 
         Case DashboardWinStringId.CommandUndoCaption : Return "Deshacer" 
         Case DashboardWinStringId.CommandRedoCaption : Return "Rehacer" 
         Case DashboardWinStringId.CommandNewDataSourceCaption : Return "Nueva Fuente de Datos" 
         Case DashboardWinStringId.CommandEditDataSourceCaption : Return "Editar" 
         Case DashboardWinStringId.CommandDeleteDataSourceCaption : Return "Eliminar"
         ' ...
         Case Else
            ret = MyBase.GetLocalizedString(id)
      End Select
      Return ret
   End Function
End Class

Public Class SpanishDashboardCoreLocalizer 
   Inherits DashboardLocalizer 
   Public Overrides ReadOnly Property Language() As String
      Get
         Return "Español"
      End Get
   End Property

   Public Overrides Function GetLocalizedString(ByVal id As DashboardStringId) As String
      Dim ret As String = ""
      Select Case id
         ' ...
         Case DashboardStringId.DateTimeGroupIntervalYear : Return "Año" 
         Case DashboardStringId.SummaryTypeSum : Return "Suma" 
         Case DashboardStringId.DescriptionItemArgument : Return "Argumento" 
         Case DashboardStringId.DescriptionArguments : Return "Argumentos" 
         Case DashboardStringId.DescriptionItemValue : Return "Valor" 
         Case DashboardStringId.DescriptionValues : Return "Valores"
         ' ...
         Case Else
            ret = MyBase.GetLocalizedString(id)
      End Select
      Return ret
   End Function
End Class

After this, these localizers are instantiated and assigned to the Active property of their base class.

csharp
public Form1()
{
    DashboardWinLocalizer.Active = new SpanishDashboardWinLocalizer();
    DashboardLocalizer.Active = new SpanishDashboardCoreLocalizer();
    InitializeComponent();  
}
vb
Public Sub New()
    DashboardWinLocalizer.Active = New SpanishDashboardWinLocalizer()
    DashboardLocalizer.Active = New SpanishDashboardCoreLocalizer()
    InitializeComponent()
End Sub

The result of localizing the Dashboard Designer interface is shown below.

You can use the following example to determine the correct name of the localized string ID enumeration member:

View Example: Localized String ID Visualizer

Inheritance

Object XtraLocalizer XtraLocalizer<DashboardStringId> DashboardLocalizer

See Also

DashboardLocalizer Members

DevExpress.DashboardCommon.Localization Namespace