Blazor Viewer supports English, Japanese, and Chinese localizations for which the localized files are already available. This article discusses setting a Blazor Viewer UI language from the supported localizations and adding custom localization for the languages that are not explicitly supported.
To set the UI language of Blazor Viewer, specify the Locale API while initializing the component. The supported values are 'en-US' (for English), 'ja-JP' (for Japanese), and 'zh-CN' (for simplified Chinese).
Index.razor |
Copy Code
|
---|---|
<div id="viewerContainer"> <ReportViewer @ref="_viewer" ReportName="@_currentReport" Locale="ja-JP" /> </div> |
The localization file for Blazor Viewer is ar-blazor-viewer-locale.json. The file is added to the project in the grapecity.activereports.blazor.viewer\content\ folder when you install the MESCIUS.ActiveReports.Blazor.Viewer NuGet package, which is required when using Blazor Viewer. By default, the 'ar-blazor-viewer-locale.json' file contains all the strings in English that are required to localize the viewer.
To add custom localization to the Blazor Viewer UI,
Sample ar-blazor-viewer-fr-locale .json |
Copy Code
|
---|---|
{ "viewer": { "toolbar": { "refresh": "Rafraîchir", "cancel": "Annuler" }, "search": { "start-search-btn": "Recherche", "paneltitle": "Recherche" } } } |
Index.razor |
Copy Code
|
---|---|
@page "/" @using BlazorViewerServer.Data @inject ReportsService ReportsService <div class="main"> <ReportList ReportsList="@reportsList" CurrentReport="@_currentReport" OnClickCallback="OnClick"></ReportList> <div id="viewerContainer"> <ReportViewer @ref="_viewer" ReportName="@_currentReport" LocaleUri="./ar-blazor-viewer-fr-locale.json" /> </div> </div> @code{ private ReportViewer _viewer; private List<string> reportsList; private string _currentReport = null; protected override void OnInitialized() { reportsList = ReportsService.GetReports().ToList(); _currentReport = reportsList.FirstOrDefault(); } private async void OnClick(string res) { _currentReport = res; await _viewer.OpenReport(_currentReport); } } |
An alternate approach is to use the LocaleData API to directly assign the localized JSON to the viewer, as shown.
Index.razor |
Copy Code
|
---|---|
@page "/" @using BlazorViewerServer.Data @inject ReportsService ReportsService <div class="main"> <ReportList ReportsList="@reportsList" CurrentReport="@_currentReport" OnClickCallback="OnClick"></ReportList> <div id="viewerContainer"> <ReportViewer @ref="_viewer" ReportName="@_currentReport" LocaleData="@_localeData" /> </div> </div> @code{ private ReportViewer _viewer; private List<string> reportsList; private string _currentReport = null; string _localeData = "{\"viewer\":{\"toolbar\":{\"refresh\":\"Rafraîchir\",\"cancel\":\"Annuler\"},\"search\":{\"start-search-btn\":\"Recherche\",\"paneltitle\":\"Recherche\"} } }"; protected override void OnInitialized() { reportsList = ReportsService.GetReports().ToList(); _currentReport = reportsList.FirstOrDefault(); } private async void OnClick(string res) { _currentReport = res; await _viewer.OpenReport(_currentReport); } } |