Back to Devexpress

XtraLocalizer.QueryLocalizedStringContainerResource Event

corelibraries-devexpress-dot-utils-dot-localization-dot-xtralocalizer-642563ac.md

latest8.0 KB
Original Source

XtraLocalizer.QueryLocalizedStringContainerResource Event

Allows you to localize resources of data forms integrated in DevExpress UI controls.

Namespace : DevExpress.Utils.Localization

Assembly : DevExpress.Data.v25.2.dll

NuGet Package : DevExpress.Data

Declaration

csharp
public static event EventHandler<XtraLocalizer.QueryLocalizedStringEventArgs> QueryLocalizedStringContainerResource
vb
Public Shared Event QueryLocalizedStringContainerResource As EventHandler(Of XtraLocalizer.QueryLocalizedStringEventArgs)

Event Data

The QueryLocalizedStringContainerResource event's data class is XtraLocalizer.QueryLocalizedStringEventArgs. The following properties provide information specific to this event:

PropertyDescription
ContainerTypeGets the type of a localizer object or data form shipped as part of a DevExpress UI control.
CultureGets the culture name of ResourceStringID.
InvariantStringGets the culture-independent (invariant) resource string.
IsTranslatedGets whether the resource string is localized (translated) for the current locale (culture).
ResourceStringIDGets the value of the enumeration member in StringIDType that corresponds to the processed resource string, or the value that uniquely identifies the form’s UI element/control.
StringIDGets the enumeration member in StringIDType that corresponds to the processed resource string.
StringIDTypeGets the type of the resource string identifier for DevExpress UI controls.
ValueGets or sets the resource string.

The event data class exposes the following methods:

MethodDescription
ToString()Returns a string in the following format: {ResourceStringID}: “{Value}”/“{InvariantString”}.

Remarks

The QueryLocalizedStringContainerResource event fires when a data form that ships as part of a DevExpress UI control (for example, a BookmarkForm in the WinForms Rich Text Editor) requests a resource string for its UI element (input field, list, button, etc.). Handle the event to translate non-localized resource strings or modify existing resources of form elements.

Use the e.ContainerType event parameter to get the type of the data form. The e.ResourceStringID parameter uniquely identifies the form’s UI element/control that requested the resource string ({ContainerType}.{controlName}.{propertyPath}).

Example

The following example demonstrates how to localize the Location button’s caption into German. This button is displayed on the Bookmark Form that ships as part of the WinForms XtraRichEdit control.

csharp
using System;
using System.Windows.Forms;
using System.Globalization;
using System.Threading;
using DevExpress.Utils.Localization;

namespace DXApplication {
    internal static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            CultureInfo culture = CultureInfo.CreateSpecificCulture("de-DE");
            Thread.CurrentThread.CurrentUICulture = culture;
            Thread.CurrentThread.CurrentCulture = culture;
            // Sets the German culture as the default culture for all threads in the application. 
            CultureInfo.DefaultThreadCurrentCulture = culture;
            CultureInfo.DefaultThreadCurrentUICulture = culture;
            XtraLocalizer.QueryLocalizedStringContainerResource += XtraLocalizer_QueryLocalizedStringContainerResource;
            Application.Run(new Form1());
        }
        private static void XtraLocalizer_QueryLocalizedStringContainerResource(object sender, XtraLocalizer.QueryLocalizedStringEventArgs e) {
            if (e.ContainerType == typeof(DevExpress.XtraRichEdit.Forms.BookmarkForm)) {
                if (e.ResourceStringID == "DevExpress.XtraRichEdit.Forms.BookmarkForm.rgSortBy.Properties.Items3")
                    if (!e.IsTranslated && Thread.CurrentThread.CurrentCulture.Name == "de-DE")
                        e.Value = "&Standort";
            }
        }
    }
}
vb
Imports System
Imports System.Windows.Forms
Imports System.Globalization
Imports System.Threading
Imports DevExpress.Utils.Localization

Namespace DXApplication
    Friend Module Program
        ''' <summary>
        ''' The main entry point for the application.
        ''' </summary>
        <STAThread>
        Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
            Dim culture As CultureInfo = CultureInfo.CreateSpecificCulture("de-DE")
            Thread.CurrentThread.CurrentUICulture = culture
            Thread.CurrentThread.CurrentCulture = culture
            ' Sets the German culture as the default culture for all threads in the application. 
            CultureInfo.DefaultThreadCurrentCulture = culture
            CultureInfo.DefaultThreadCurrentUICulture = culture
            AddHandler XtraLocalizer.QueryLocalizedStringContainerResource, AddressOf XtraLocalizer_QueryLocalizedStringContainerResource
            Application.Run(New Form1())
        End Sub
        Private Shared Sub XtraLocalizer_QueryLocalizedStringContainerResource(ByVal sender As Object, ByVal e As XtraLocalizer.QueryLocalizedStringEventArgs)
            If e.ContainerType Is GetType(DevExpress.XtraRichEdit.Forms.BookmarkForm) Then
                If e.ResourceStringID = "DevExpress.XtraRichEdit.Forms.BookmarkForm.rgSortBy.Properties.Items3" Then
                    If Not e.IsTranslated AndAlso Thread.CurrentThread.CurrentCulture.Name = "de-DE" Then
                        e.Value = "&Standort"
                    End If
                End If
            End If
        End Sub
    End Module
End Namespace

See Also

XtraLocalizer Class

XtraLocalizer Members

DevExpress.Utils.Localization Namespace