Skip to main content

XtraReport.ApplyLocalization(String) Method

Applies values contained in the localized report for the specified locale.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v23.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public void ApplyLocalization(
    string culture
)

Parameters

Name Type Description
culture String

A culture name. Use a specific culture (e.g., en-US) to maintain currency, number and date format consistency.

Remarks

The method is used for localized reports and allows you to create a document in the locale that differs from the current thread culture.

Note

Use a specific culture (e.g., de-CH) as the method parameter. If you specify a neutral culture (a two-letter lowercase language code), the currency, date and number formats are also set for the neutral culture (which is not what you expect to see).

How to Use the Method

Call the method before the XtraReport.CreateDocument method to specify the language to be applied to the new document.

using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using System.Threading;
// ...
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
XtraReport localizedReport = new LocalizedReport1();

localizedReport.ApplyLocalization("de-DE");

localizedReport.CreateDocument();

// The document is in German

Note

If you call the ApplyLocalization method after the CreateDocument method, the document that was already created retains its language. In this case the ApplyLocalization method has no effect.

As an alternative, you may call the ApplyLocalization method in the BeforePrint handler to specify the language to be applied to the new document:

using DevExpress.XtraReports.UI;
using System.Threading;
// ...
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
XtraReport localizedReport = new LocalizedReport1();

localizedReport.BeforePrint += (s, e) =>
{
    localizedReport.ApplyLocalization("de-DE");
};

localizedReport.CreateDocument();

// The document is in German

Method Specifics

  • Report Parameters

    If you call the ApplyLocalization method in the BeforePrint event, the Parameter.Description property value changes, but the text displayed in the Parameters Panel does not. The Parameters Panel is initialized before the report’s events, so you should call the ApplyLocalization method before the XtraReport.CreateDocument method to change the Parameters Panel text.

  • Culture-Specific Format Strings

    Report controls use the TextFormatString property to display non-static content. The TextFormatString property is localizable and can be set to different strings for different report languages. However, certain format strings are culture-specific and the resulting text is determined by the current thread’s culture.

    The ApplyLocalization method changes the current thread’s culture. The CreateDocument method uses the current thread’s culture to resolve culture-sensitive formatting strings.

    The following code snippet demonstrates how the ApplyLocalization method changes the XRPageInfo control’s text.

    using DevExpress.XtraReports.UI;
    // ...
      Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
      XtraReport localizedReport = new LocalizedReport1();
      XRPageInfo pageInfoControl = localizedReport.AllControls<XRPageInfo>().FirstOrDefault();
      if (pageInfoControl != null)
      {
        pageInfoControl.PageInfo = DevExpress.XtraPrinting.PageInfo.DateTime;
        pageInfoControl.TextFormatString = "D";
      }
      localizedReport.CreateDocument();
      // Displays "Monday, April 20, 2020"
      localizedReport.ApplyLocalization("fr-FR");
      localizedReport.CreateDocument();
      // Displays "lundi 20 avril 2020"
    
See Also