About Me

My photo
Software Developer and ideas man!

Tuesday, June 24, 2014

Localizing Crystal Reports in C# - I demonstrate one way of doing it despite the hurdles!

How hard should it be to localize a Crystal Report in Visual Studio. You should be able to specify the "localize" property on the control, change language to what you are localizing to, build the solution and hey presto! have a new localized resource and satellite assembly ready for deploying.

Well, this is not the case for the Crystal Reports controls including the almost "black box" charts as I soon discovered.

So, I thought I'd setup a test app. to demonstrate what hurdles you have to overcome to localize a report.

Some users duplicate reports and create localized versions but I thought my way would be more self contained and hopefully there would be less ongoing maintenance required.

First off, I created a sample app, that reads share prices for a given stock from an Oracle database and prints a chart of the Highs and Lows over the trading lifetime of the stock. It also prints some basic summary stats below the chart.

The localization goal is to translate the wording of the titles, chart objects to Simplified Chinese.


Secondly,  I updated the locale in my code to "zn-CN" or Simplified Chinese - straight off the bat, Crystal picks this up and changes the Crystal Reports Viewer elements, such as tab name and status bar info to localized versions.



Thirdly, to change report headings such as "Average Volume", the report title etc., I had to resort to the code and directly reference each object in the reportdefinition - this is an arduous process especially if you have many languages that you have to cater for.


Note: normally, these would be constants and the strings would be in a string resource file



Now, the tricky bit is in updating the Chart elements.  This cannot be done directly and I have raised an"Idea" with SAP to expose more properties in their charts.  PLEASE, visit the link below and vote up the idea so the CR product manager has a case for implementing it!


Because the chart elements cannot be directly referenced, the idea here is to turn off the titles for the chart and superimpose a text object on the Chart which can be directly referenced in code. 




Finished Product


So what I've covered here is the localizing of the main elements of a Crystal Report.  You will have noticed that numeric values and dates will be formatted according to the CultureInfo set by the program or OS. I'll cover changing the legends another time.

If you have any comments, feel free to provide them in the box below and please vote up my idea :).

SAP Idea Place - Expose more properties of ChartObject in Crystal Reports for Visual Studio 2010/2012 .Net


For a copy of the code click on the link below.  I have included an excel spreadsheet of the share values that can be used as the datasource.  Let me know if you need a hand with this.

Crystal Report Localization Sample code developed in Visual Studio 2010 - C#

2 comments:

  1. i had download smple from Crystal Report Localization Sample code developed in Visual Studio 2010 - C#
    this zipfile protected by password ?

    ReplyDelete
  2. Sorry about that - must have been overly security conscious about my code. Try now. You may need to update the paths to reflect your own environment to run.

    ReplyDelete