Cogniza | Business-Intelligence Specialists

Jul/09

9

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

· ·

No comments yet.

Leave a Reply

<<

>>

Theme Design by devolux.nh2.me