在Telerik自托管服务(.trdx)中报告本地化

时间:2018-01-12 06:39:24

标签: asp.net localization telerik-reporting

我有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;


        }

在上面的行(见图)之后,红色标记下的数据是本地化的,但是我需要定位黄色的数据(即标题)

Update 1

1 个答案:

答案 0 :(得分:0)

我弄清楚如何本地化报告标题。以下是一些总结的步骤。

  1. 相应地添加App_GlobalResources文件夹和.resx语言(参见图1-1)。 Figure 1-1

  2. 从“HTML5查看器”发送语言属性。

          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
      });
    
  3. 在服务器端,相应地根据该属性更改标签。

           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;
                    }
                }
    
    
    
            }
    
    
        }
    
  4. 在Telerik独立报表设计器上

    更改与您的Textbox名称值对匹配的报告(.trdx).resx值。

    enter image description here

    资源文件值

    enter image description here