Telerik 自托管服务 (.trdx) 中的报告本地化
Report localization in Telerik self hosted service (.trdx)
我有 telerik REST web API(ASP.NET ),它工作正常。现在我需要对报告进行本地化(报告的扩展名为 .trdx)。
从 telerik 的文档中,我找到了我的 BaseTelerikReportsController
中的代码,但这也不起作用,甚至没有显示任何错误。
Telerik Localization Documentation
public class BaseTelerikReportsController : ReportsControllerBase
{
static readonly Telerik.Reporting.Services.ReportServiceConfiguration ConfigurationInstance;
static BaseTelerikReportsController()
{
var resolver = new CustomReportResolver();
//Create new CultureInfo
var cultureInfo = new System.Globalization.CultureInfo("aa-iq"); //<-- Line 1
// Set the language for static text (i.e. column headings, titles)
System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo; //<-- Line 2
var reportsPath = HttpContext.Current.Server.MapPath("~/Reports");
ConfigurationInstance = new Telerik.Reporting.Services.ReportServiceConfiguration
{
HostAppId = "TBReportApp",
ReportResolver = resolver,
// ReportResolver = new ReportFileResolver(reportsPath),
Storage = new Telerik.Reporting.Cache.File.FileStorage(),
};
}
public BaseTelerikReportsController()
{
ReportServiceConfiguration = ConfigurationInstance;
}
}
备注
有一个类似的问题,但不要指导我任何正确的方向Here
更新 1
我在 Global.asax.cs
中添加了以下功能。
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
//Create new CultureInfo
var cultureInfo = new System.Globalization.CultureInfo("ar");
// Set the language for static text (i.e. column headings, titles)
System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo;
// Set the language for dynamic text (i.e. date, time, money)
System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo;
}
在红色标记下的上一行(见图)数据已本地化,但我需要本地化黄色标记(即标题)
我想出了如何本地化报告 header。以下是一些总结步骤。
从 'HTML5 Viewer' 发送语言属性。
var viewer = $("#report-viewer").data("telerik_ReportViewer");
var model = {
//other attributes
Language: this.selectedLanguage //Here value may be ,en Or ar
};
viewer.reportSource({
report: reportSettings,
parameters: model
});
在服务器端根据该属性相应地更改标签。
private static void Localization(ref Report reportInstance)
{
ResourceManager currentResource = null;
switch (_language)
{
case "en":
currentResource = new ResourceManager("Resources.en", System.Reflection.Assembly.Load("App_GlobalResources"));
break;
case "ar":
currentResource = new ResourceManager("Resources.ar", System.Reflection.Assembly.Load("App_GlobalResources"));
break;
}
// var MyResourceClass = new ResourceManager("Resources.ar", System.Reflection.Assembly.Load("App_GlobalResources"));
ResourceSet resourceSet = currentResource.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
foreach (DictionaryEntry entry in resourceSet)
{
string key = entry.Key.ToString();
string value = entry.Value.ToString();
var items = reportInstance.Items.Find(key,true);
foreach (var singleItem in items)
{
var singleItemType = singleItem.GetType();
//if (singleItem.GetType().FullName == "") ;
if (singleItemType.FullName == "Telerik.Reporting.TextBox")
{
var castItem = (Telerik.Reporting.TextBox) singleItem;
castItem.Value = value;
}
}
}
}
在 Telerik 独立报表设计器上
更改您的报告 (.trdx) Textbox
与您的 .resx
名称值对匹配的值。
资源文件值
我有 telerik REST web API(ASP.NET ),它工作正常。现在我需要对报告进行本地化(报告的扩展名为 .trdx)。
从 telerik 的文档中,我找到了我的 BaseTelerikReportsController
中的代码,但这也不起作用,甚至没有显示任何错误。
Telerik Localization Documentation
public class BaseTelerikReportsController : ReportsControllerBase
{
static readonly Telerik.Reporting.Services.ReportServiceConfiguration ConfigurationInstance;
static BaseTelerikReportsController()
{
var resolver = new CustomReportResolver();
//Create new CultureInfo
var cultureInfo = new System.Globalization.CultureInfo("aa-iq"); //<-- Line 1
// Set the language for static text (i.e. column headings, titles)
System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo; //<-- Line 2
var reportsPath = HttpContext.Current.Server.MapPath("~/Reports");
ConfigurationInstance = new Telerik.Reporting.Services.ReportServiceConfiguration
{
HostAppId = "TBReportApp",
ReportResolver = resolver,
// ReportResolver = new ReportFileResolver(reportsPath),
Storage = new Telerik.Reporting.Cache.File.FileStorage(),
};
}
public BaseTelerikReportsController()
{
ReportServiceConfiguration = ConfigurationInstance;
}
}
备注 有一个类似的问题,但不要指导我任何正确的方向Here
更新 1
我在 Global.asax.cs
中添加了以下功能。
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
//Create new CultureInfo
var cultureInfo = new System.Globalization.CultureInfo("ar");
// Set the language for static text (i.e. column headings, titles)
System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo;
// Set the language for dynamic text (i.e. date, time, money)
System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo;
}
在红色标记下的上一行(见图)数据已本地化,但我需要本地化黄色标记(即标题)
我想出了如何本地化报告 header。以下是一些总结步骤。
从 'HTML5 Viewer' 发送语言属性。
var viewer = $("#report-viewer").data("telerik_ReportViewer"); var model = { //other attributes Language: this.selectedLanguage //Here value may be ,en Or ar }; viewer.reportSource({ report: reportSettings, parameters: model });
在服务器端根据该属性相应地更改标签。
private static void Localization(ref Report reportInstance) { ResourceManager currentResource = null; switch (_language) { case "en": currentResource = new ResourceManager("Resources.en", System.Reflection.Assembly.Load("App_GlobalResources")); break; case "ar": currentResource = new ResourceManager("Resources.ar", System.Reflection.Assembly.Load("App_GlobalResources")); break; } // var MyResourceClass = new ResourceManager("Resources.ar", System.Reflection.Assembly.Load("App_GlobalResources")); ResourceSet resourceSet = currentResource.GetResourceSet(CultureInfo.CurrentUICulture, true, true); foreach (DictionaryEntry entry in resourceSet) { string key = entry.Key.ToString(); string value = entry.Value.ToString(); var items = reportInstance.Items.Find(key,true); foreach (var singleItem in items) { var singleItemType = singleItem.GetType(); //if (singleItem.GetType().FullName == "") ; if (singleItemType.FullName == "Telerik.Reporting.TextBox") { var castItem = (Telerik.Reporting.TextBox) singleItem; castItem.Value = value; } } } }
在 Telerik 独立报表设计器上
更改您的报告 (.trdx) Textbox
与您的 .resx
名称值对匹配的值。
资源文件值