Back to Devexpress

XtraLocalizer.QueryLocalizedString Event

corelibraries-devexpress-dot-utils-dot-localization-dot-xtralocalizer-15208591.md

latest7.5 KB
Original Source

XtraLocalizer.QueryLocalizedString Event

Allows you to localize resources for all DevExpress UI controls in your application.

Namespace : DevExpress.Utils.Localization

Assembly : DevExpress.Data.v25.2.dll

NuGet Package : DevExpress.Data

Declaration

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

Event Data

The QueryLocalizedString 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 QueryLocalizedString event fires when the control requests a resource string and allows you to translate or modify it as needed.

The e.StringID gets the resource string requested by the control. The e.StringIDType parameter allows you to obtain the type of the control that is requesting the resource string. Use the e.Value parameter to specify the resource string (translated or modified) requested by the control.

csharp
using System;
using System.Windows.Forms;
using DevExpress.Utils.Localization;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid.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);
            XtraLocalizer.QueryLocalizedString += XtraLocalizer_QueryLocalizedString;
            Application.Run(new Form1());
        }
        static private void XtraLocalizer_QueryLocalizedString(object sender, XtraLocalizer.QueryLocalizedStringEventArgs e) {
            if (e.StringIDType == typeof(GridStringId)) {
                if ((GridStringId)e.StringID == GridStringId.GridGroupPanelText)
                    e.Value = "Gruppenregion";
            }
            if (e.StringIDType == typeof(StringId)) {
                if ((StringId)e.StringID == StringId.PictureEditMenuCut)
                    e.Value = "Ausschneiden";
                if ((StringId)e.StringID == StringId.PictureEditMenuCopy)
                    e.Value = "Kopieren";
                if ((StringId)e.StringID == StringId.PictureEditMenuPaste)
                    e.Value = "Einfugen";
            }
        }
    }
}
vb
Imports System
Imports System.Windows.Forms
Imports DevExpress.Utils.Localization
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraGrid.Localization

Namespace DXApplication
    Friend Module Program
        ''' <summary>
        ''' The main entry point for the application.
        ''' </summary>
        <STAThread>
        Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
            AddHandler XtraLocalizer.QueryLocalizedString, AddressOf XtraLocalizer_QueryLocalizedString
            Application.Run(New Form1())
        End Sub
        Private Sub XtraLocalizer_QueryLocalizedString(ByVal sender As Object, ByVal e As XtraLocalizer.QueryLocalizedStringEventArgs)
            If e.StringIDType Is GetType(GridStringId) Then
                If CType(e.StringID, GridStringId) Is GridStringId.GridGroupPanelText Then
                    e.Value = "Gruppenregion"
                End If
            End If
            If e.StringIDType Is GetType(StringId) Then
                If CType(e.StringID, StringId) Is StringId.PictureEditMenuCut Then
                    e.Value = "Ausschneiden"
                End If
                If CType(e.StringID, StringId) Is StringId.PictureEditMenuCopy Then
                    e.Value = "Kopieren"
                End If
                If CType(e.StringID, StringId) Is StringId.PictureEditMenuPaste Then
                    e.Value = "Einfugen"
                End If
            End If
        End Sub
    End Module
End Namespace

Note

The QueryLocalizedString event is a weak event. You should implement the event handler as a method. Otherwise, the garbage collector can collect a reference to your delegate.

See Also

XtraLocalizer Class

XtraLocalizer Members

DevExpress.Utils.Localization Namespace