Crystal Reports: Strategy to Localize a Report (labels)

Create a Crystal Report that dynamically recalculate its labels based on the Workstation’s localization settings.

ContentLocale

Crystal Reports XI introduced a keyword named ‘ContentLocale’. This keyword returns the machine’s locale setting (e.g. ‘en_US’ for English (US)).  This value is set in Windows’ Regional Settings Control Panel.

However, this keyword can only be used in formulae that are executed during the report’s Second Pass. The following Record Selection Formula, for example, will generate an error:

{my_table.localeName}=ContentLocale

Custom Functions

This keyword, however, can be used in combination with a Report Custom Function to dynamically and transparently apply localization settings when a report is viewed, even reports that have been saved with data or have been scheduled using Business Objects Enterprise.

//--------------------------------------------------------------------------------
// Return a localized string for a given Key and Language.
//--------------------------------------------------------------------------------
Function (Stringvar Key, Stringvar Language)

//define array of keys that are used by Formula fields
Stringvar Array Keys:=["COUNTRY","REGION","CITY"];

//define an array of localized strings for each required language; ensure localized strings are same position as the Key array (correlated arrays).

//determine which array to use
Stringvar Array Values;
Select Language
Case "en_US": Values:=["Country","State","City"]
Case "it_IT": Values:=["Paese","Dichiari","Citta"]
Case "fr_FR": Values:=["Pays","S","C"]
Default: Values:=["Country","State","City"]
;

//set value's default value to the Key; useful for debugging purposes.
Stringvar value:=Key;

//iterate through Key array...
Numbervar i;
for i := 1 To Ubound(Keys) do (
//if value in array matches the specified value, return the value from the localized array
if Keys[i] = Key then (
value:=Values[i];
exit for
)
);

//return value
value;

Formula Fields

Create a Formula Field that will act as a label for each desired Key.  Add it to the report’s canvas.

//{@Country}
getLocalizedString ("COUNTRY", ContentLocale)

//{@Region}
getLocalizedString ("REGION", ContentLocale)

//{@City}
getLocalizedString ("CITY", ContentLocale)

Advantages

  • Rapid development and deployment.
  • Executes during ‘view’ time.
  • Can be saved to Repository and shared with other reports.

Limitations

  • Crystal Reports is required to maintain the logic and publish changes to the Repository.
  • Array of Key/Values limited to 1000 items.

Summary

This approach should help ease the burden of localizing the labels contained in a Crystal Report.

Download

Sample report
Sample database

6 thoughts on “Crystal Reports: Strategy to Localize a Report (labels)

  1. TJoe

    It gives Crystal Report ActiveX Designer warning that says
    A number, currency amount, Boolean, date, time, date-time or string is expected here.
    What to do?

  2. xr280xr

    @Ravi, our approach to solving that is to create a translations table specifying the source table, row, column, and culture for a translated value. Then when we pull the report, we pass in the culture and get the translated value for the given culture.

  3. David

    Great,… but any idea if it possible to put the array into a database.

    i’d much prefer to have a database table with all of the text mappings.

    Thanks

  4. divya

    Hi,i implemented this approach this is working fine.
    but if i want to add another language labels without editing the source code is it possible ?
    I have an issue regarding this same approach.
    please solve this.
    For this localization i have 4 property files containing all the report labels and key values.
    like this en_US.properties
    fr_FR.properties
    ………
    i need to call those files based on language selection
    i am unable to call the files based on language.
    can any one tell how to that

Leave a Reply

Your email address will not be published. Required fields are marked *