Back to Devexpress

Localizer Objects

aspnet-12048-common-concepts-localization-localizer-objects.md

latest4.6 KB
Original Source

Localizer Objects

  • Feb 12, 2024
  • 4 minutes to read

DevExpress ASP.NET Web Forms controls use Localizer objects to obtain strings for UI elements. You can use the following technique to override these strings at runtime:

The table below list differences in this techniques.

XtraLocalizer TechniqueCustom Localizer Technique
Specify strings for different products in a single event.Create a custom localizer for every localized product.
Localize form elements.Form elements cannot be localized.
Get strings that require translation in your application.You cannot get untranslated strings.

Use XtraLocalizer to Localize DevExpress Controls

The XtraLocalizer class implements a localization-related API that allows you to translate DevExpress UI controls and forms into different languages and develop multicultural enterprise applications.

  • The QueryLocalizedString and QueryLocalizedStringContainerResource events allow you to localize resources for all DevExpress UI controls and their built-in data forms in your application. These events fire when a control or data form requests a resource string. Handle these events to translate or modify resource strings as needed.

  • The QueryLocalizedStringNonTranslated allows you to focus on the strings that require translation in your application. Handle this event to collect non-localized resource strings for translation.

  • C#

  • VB.NET

csharp
using DevExpress.Web.Localization;
using DevExpress.Utils.Localization.Internal;
using DevExpress.Utils.Localization;

protected void Page_Load(object sender, EventArgs e) {
    XtraLocalizer.QueryLocalizedString +=
    new EventHandler<XtraLocalizer.QueryLocalizedStringEventArgs>(XtraLocalizer_QueryLocalizedString);
}
static private void XtraLocalizer_QueryLocalizedString(object sender, XtraLocalizer.QueryLocalizedStringEventArgs e) {
    if (e.StringIDType == typeof(ASPxEditorsStringId)) {
        if ((ASPxEditorsStringId)e.StringID == ASPxEditorsStringId.Calendar_Today)
            e.Value = "Select Today";
        if ((ASPxEditorsStringId)e.StringID == ASPxEditorsStringId.Calendar_Clear)
            e.Value = "Clear Selection";
    }
}
vb
Imports DevExpress.Web.Localization
Imports DevExpress.Utils.Localization.Internal
Imports DevExpress.Utils.Localization

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    XtraLocalizer.QueryLocalizedString += New EventHandler(Of XtraLocalizer.QueryLocalizedStringEventArgs)(AddressOf XtraLocalizer_QueryLocalizedString)
End Sub

Shared Private Sub XtraLocalizer_QueryLocalizedString(ByVal sender As Object, ByVal e As XtraLocalizer.QueryLocalizedStringEventArgs)
    If e.StringIDType = GetType(ASPxEditorsStringId) Then
        If CType(e.StringID, ASPxEditorsStringId) = ASPxEditorsStringId.Calendar_Today Then e.Value = "Select Today"
        If CType(e.StringID, ASPxEditorsStringId) = ASPxEditorsStringId.Calendar_Clear Then e.Value = "Clear Selection"
    End If
End Sub

Implement a Custom Localizer

Follow the steps below to create a custom localizer:

  • Create a descendant of a Localizer class that corresponds to the control. See the table below for a lists of localizer classes.

  • Override the GetLocalizedString(T) method to return localized strings for specific resource identifiers.

  • Implement a method (Activate in the code sample below) that creates an instance of your custom localizer and a localizer provider. Set this provider as active for the localizer.

  • Call the implemented method in the Application_Start event handler in the Global.asax file.

Important

Form resources, such as the XtraReports Search dialog, cannot be translated via Localizer classes. Use XtraLocalizer class or satellite resource assemblies techniques to translate form resources.