Localization in Reporting for React
- 4 minutes to read
This topic describes how to localize the Document Viewer and End-User Report Designer UI in a React application.
Use JSON Files
In the React application you can import the localized JSON resources and use the CustomizeLocalization
callback to call the LoadMessages method that loads localized strings. You can also use the UpdateLocalization method to substitute particular strings.
Obtain JSON Files from the Localization Service
Log into the DevExpress website.
Open the DevExpress Localization Service.
Select your target language, modify translations, and click the Download button. Refer to the following help topic for detailed information: Localization Service.
Unpack the downloaded executable file to get the satellite assemblies and json resources directory. This directory contains the following JSON files required to localize the reporting controls (where xx is a culture name):
File Name | Localization Strings |
---|---|
dx-analytics-core.xx.json | Shared Components: Query Builder, Data Source Wizard, Filter Editor, Expression Editor |
dx-reporting.xx.json | Web Document Viewer, End-User Report Designer and other reporting-specific components |
Tip
The component’s UI is built on DevExtreme widgets, so to localize the editors you should also use one of the approaches described in the following topic: DevExtreme - Localization. Specify web server’s thread culture to apply culture-specific formats to numbers and dates.
Localize the Application
Copy the dx-analytics-core.xx.json and dx-reporting.xx.json (where xx is the culture ID) files obtained in the previous section to the application root folder.
Open the component file and add the code that handles the
CustomizeLocalization
callback. The following code substitutes localizable strings used in Reporting UI with their German equivalents:'use client'; import React from 'react'; import ReportViewer, { RequestOptions, Callbacks } from 'devexpress-reporting-react/dx-report-viewer'; import 'devextreme/dist/css/dx.light.css'; import '@devexpress/analytics-core/dist/css/dx-analytics.common.css'; import '@devexpress/analytics-core/dist/css/dx-analytics.light.css'; import 'devexpress-reporting/dist/css/dx-webdocumentviewer.css'; import deCore from './dx-analytics-core.de.json'; import deRep from './dx-reporting.de.json'; const App = () => { const onCustomizeLocalization = (event: any): void => { event.args.LoadMessages(deCore); event.args.LoadMessages(deRep); event.sender.UpdateLocalization({ 'Search': 'Suche', 'Search result': 'Suchergebnisse', 'Next Page': 'Nächste Seite', 'Export Options': 'Exportoptionen', 'The document does not contain any pages.': 'Keine Daten' }); }; return ( <ReportViewer reportUrl="TestReport"> <RequestOptions host="http://localhost:5000/" invokeAction="DXXRDV" /> <Callbacks CustomizeLocalization={onCustomizeLocalization} /> </ReportViewer> ); }; export default App;
Recompile the project and open the application in the browser (default URL is http://localhost:3000/).
Use UI Localization Client
Note
The UI Localization Client requires localization recourses to be loaded from the server to work properly in a React application.
The UI Localization Client is a cross-platform utility that allows you to quickly identify non-translated strings of DevExpress UI controls and translate them during a debug session. The utility automatically generates a RESX file(s) with translated resources and adds it to the project. Note that the UI Localization Client loads all Web Reporting resource strings once the controls are rendered, without reflecting your interaction with the UI.
To use the UI Localization Client in you application:
- Make sure that the application gets the localization from the server. For instance, you can use getLocalizationAction for Designer or getLocalizationAction for Viewer.
- Make sure you do not use the
CustomizeLocalization
event to localize your application.
For more information refer to the following topic: UI Localization Client.
The resource strings for the Web Reporting Controls (Web Document Viewer and Web Report Designer) are located in the following localization containers in the UI Localization Client window:
- DevExpress.XtraReports.Web.Localization.LocalizationContainer
- Contains localization strings specific only to the Web Reporting Controls.
- DevExpress.Utils.Localization.CoreLibraryResources
- Contains cross-platform localization strings used in the Web Reporting Controls.
- DevExpress.Web.Resources.Localization.LocalizationContainer
- Contains localization strings common to DevExpress Web Components used in the Web Reporting Controls.
Troubleshooting
- If you followed the instructions in the UI Localization Client topic and the translated resources do not appear on your web page, try clearing browser cache.
- If you use an ASP.NET Core backend and after following the instructions in the UI Localization Client topic the resource strings do not appear in the UI Localization Client window, call the HandleRequestsFromAllThreads() method at application startup to use localizer objects across all application threads.
Identify Non-Translated Strings
- Use our UI Localization Client tool shipped as part of your DevExpress subscription. This tool streamlines the entire localization process. You can quickly find non-translated strings and translate them during a debug session.
- Handle the XtraLocalizer.QueryLocalizedStringNonTranslated event to collect non-localized resource strings for further translation. The event allows you to focus on strings that require translation in your application.