How to: Localize the Web Dashboard Viewer UI using Localizers

Important

This documentation applies to v16.2. Starting with v17.1, the ASPxDashboardViewer control is in maintenance mode. In v19.1, the new Web Dashboard Control replaces the old Web Dashboard Viewer. This means that the Web Dashboard Viewer will not be included in our installation packages. See our blog post for more information.

Refer to the following KB articles to learn how to migrate to ASPxDashboard / ASP.NET MVC Dashboard:

DevExpress ASP.NET products allow you to programmatically specify localization resource values at runtime. This approach can be useful when a resource value is not known at design time or you wish to set a resource value based on a runtime condition.

This topic describes how to localize the ASPxDashboardViewer control's UI.

Note

The ASPxDashboard control's UI can be localized using only Satellite Resource Assemblies. To learn more, see Localizing ASP.NET Controls via Satellite Resource Assemblies.

To localize the Web Dashboard Viewer's UI at runtime, two specific types of Localizer objects are provided.

To localize cross-platform strings, use the DashboardLocalizer and DashboardsResLocalizer classes.

Follow the steps below.

  1. Create a descendant of the product localizer.

    public class MyDashboardWebLocalizer : DevExpress.DashboardWeb.Localization.DashboardWebLocalizer {
    }
    public class MyDashboardCoreLocalizer : DevExpress.DashboardCommon.Localization.DashboardLocalizer {
    }
    
  2. Override the localizer's GetLocalizedString method. This method is called for each localized string and returns the string's value. By default, it returns values that are contained within the DashboardWebStringId (in the DashboardWebLocalizer class) or DashboardStringId (in the DashboardLocalizer class) resource string enumeration. Override the GetLocalizedString method to return your custom string values.

    public class MyDashboardWebLocalizer : DevExpress.DashboardWeb.Localization.DashboardWebLocalizer {
         public override string GetLocalizedString(DashboardWebStringId id) {
              string ret = "";
              switch(id) {
                 // ...
                 case DashboardWebStringId.IncompatibleBrowser : return "Visor de Consola: " + 
                    "El versión del navegador actual no está soportado. Actualmente, hay soporte para los" + 
                    " siguientes navegadores: Internet Explorer 9, Chrome, Safari, FireFox, Opera, Android 3+."; 
                 case DashboardWebStringId.InvalidXmlFile : return "El fichero de Consola no es válido."; 
                 case DashboardWebStringId.InvalidXmlFilePath : return "No se ha indicado un fichero para" + 
                    " la consola o el fichero no se encuentra."; 
                 // ...
                 default:
                    ret = base.GetLocalizedString(id);
                    break;
              }
         return ret;
         }
    }
    
    public class MyDashboardCoreLocalizer : DevExpress.DashboardCommon.Localization.DashboardLocalizer {
         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;
         }
    }
    
  3. Write a method that creates an instance of your custom localizer and a localizer provider for the localizer, and makes the provider active.

    using DevExpress.DashboardWeb.Localization;
    using DevExpress.DashboardCommon.Localization;
    using DevExpress.Utils.Localization.Internal;
    ...
    public class MyDashboardWebLocalizer : DashboardWebLocalizer {
         public static void Activate() {
              MyDashboardWebLocalizer localizer = new MyDashboardWebLocalizer();
              DefaultActiveLocalizerProvider<DashboardWebStringId> provider = 
                   new DefaultActiveLocalizerProvider<DashboardWebStringId>(localizer);
              MyDashboardWebLocalizer.SetActiveLocalizerProvider(provider);
         }
         public override string GetLocalizedString(DashboardWebStringId id) {...}
    }
    public class MyDashboardCoreLocalizer : DashboardLocalizer {
         public static void Activate() {
              MyDashboardCoreLocalizer localizer = new MyDashboardCoreLocalizer();
              DefaultActiveLocalizerProvider<DashboardStringId> provider = 
                   new DefaultActiveLocalizerProvider<DashboardStringId>(localizer);
              MyDashboardCoreLocalizer.SetActiveLocalizerProvider(provider);
         }
         public override string GetLocalizedString(DashboardStringId id) {...}
    }
    
  4. Call the method that was written in the Session_Start event above, within the Global.asax file.

    protected void Session_Start(object sender, EventArgs e) {
         MyDashboardWebLocalizer.Activate();
         MyDashboardCoreLocalizer.Activate();
    }
    
Note

Important: Not all strings can be translated via Localizer classes. Some components contain form resources (e.g., the XtraReports Search dialog), and the only way to translate them is to create satellite assemblies. Thus, localization via resources is the preferable solution.

See Also