Search code examples
asp.netlocalizationtelerik-reporting

Report localization in Telerik self hosted service (.trdx)


I have telerik REST web API(ASP.NET ) which is working fine. Now I need to localize the reports (report are in .trdx extension).

From documentation of telerik I found the code which have place in my BaseTelerikReportsController but this also not working, and even not show any error.

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;
        }


    }

Note There is a similar question but don't guide me to any right direction Here

Update 1

I have added below function in 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;


        }

After above line (see image) data under red mark is localize but i need to localize yellow one(i.e heading)

Update 1


Solution

  • I figure out how to localize the report header. Following are the some summarized steps.

    1. Add App_GlobalResources folder and .resx accordingly your languages (See the figure 1-1). Figure 1-1

    2. Send language attribute from '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
        });
      
    3. On server side based on that attribute change label accordingly.

             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;
                      }
                  }
      
      
      
              }
      
      
          }
      

    On Telerik Standalone Report Designer

    Change your report(.trdx) Textbox value which matches your .resxname value pair.

    enter image description here

    Resource file values

    enter image description here