Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Changing Language having SubReports

edited November 2010 in General
Hello every one!

I need to change the language of the Report Builder Designer depending on
the language that custumer has installed.
I read how to do it, and I'm able to change the language according to a
setting stored in an INI configuration file.

As I read in this news, I'm setting the ppReport.Language via
ppReport.Template.OnLoadEnd and it's working fine for reports without
subreports.
When I try to change the language for a report which contains several
subreports, at the end the language value is set to default, and this is the
language showed in the report designer.

Has anybody found the same situation?

While waiting for an answer I've patched ppReport.pas to avoid subsequent
calls to LanguageChanged.

With this patch it's working fine and I can control the language for simple
reports and for reports with subreports too.

The patch is based on stopping the call to LanguageChanged in
TppReport.SetLanguage and TppReport.SetLanguageID depending on the value in
the Tag property which must be set to the desired language code.

Code on event handler for ppReport.Template.OnLoadEnd

procedure TSampleReportForm.ReportLoaded(Sender: TObject);
var
langId : Integer;
begin
If Sender is TppReport then begin
// Gets the desired language code from INI config file. Values from 0 to
13
langId := GetRptDesignerLang;
TppReport(Sender).Tag := langId;
TppReport(Sender).Language := TppLanguageType(langId);
end;
end;

Patch in ppReport starting in line 1730:
{------------------------------------------------------------------------------}
{ TppReport.SetLanguage }

procedure TppReport.SetLanguage(aLanguageType: TppLanguageType);
var
lbLanguageChanged: Boolean;
begin

{optimize}
lbLanguageChanged := (Language <> aLanguageType);

inherited SetLanguage(aLanguageType);

if (csReading in ComponentState) or (csLoading in ComponentState) then
Exit;

// PATCHED
if lbLanguageChanged and (Tag <> 0) and (Tag <> Integer(aLanguageType))
then
LanguageChanged;

end; {procedure, SetLanguage}

{------------------------------------------------------------------------------}
{ TppReport.SetLanguageID }

// PATCHED
// Conversion from Language String Identifier to proper enumerated value
function GetLangId(aLanguageId : string) : Integer;
begin
if aLanguageId = 'Danish (Denmark)' then
Result := Integer(lgDanish)
else if aLanguageId = 'Dutch (Netherlands)' then
Result := Integer(lgDutch)
else if aLanguageId = 'English (United States)' then
Result := Integer(lgEnglish)
else if aLanguageId = 'French (France)' then
Result := Integer(lgFrench)
else if aLanguageId = 'German (Germany)' then
Result := Integer(lgGerman)
else if aLanguageId = 'Italian (Italy)' then
Result := Integer(lgItalian)
else if aLanguageId = 'Portuguese (Brazil)' then
Result := Integer(lgPortugueseBrazil)
else if aLanguageId = 'Portuguese (Portugal)' then
Result := Integer(lgPortuguese)
else if aLanguageId = 'Spanish (Mexico)' then
Result := Integer(lgSpanishMexico)
else if aLanguageId = 'Spanish (Spain)' then
Result := Integer(lgSpanish)
else if aLanguageId = 'Norwegian (Norway)' then
Result := Integer(lgNorwegian)
else if aLanguageId = 'Swedish (Sweden)' then
Result := Integer(lgSwedish)
else if aLanguageId = 'Default' then
Result := Integer(lgDefault)
else if aLanguageId = 'Custom' then
Result := Integer(lgCustom)
else Result := Integer(lgDefault);
end;

procedure TppReport.SetLanguageID(aLanguageID: String);
var
lbLanguageChanged: Boolean;
// PATCHED
langValue : Integer;
begin
{optimize}
lbLanguageChanged := (LanguageID <> aLanguageID);

inherited SetLanguageID(aLanguageID);

if (csReading in ComponentState) or (csLoading in ComponentState) then
Exit;

// PATCHED
langValue := GetLangId(aLanguageID);
if lbLanguageChanged and (Tag <> 0) and (Tag <> langValue) then
LanguageChanged;


end; {procedure, SetLanguageID}

Thanks in advance.

Comments

  • edited November 2010
    Hi Jordi,

    I'm sorry but I am unable to recreate this behavior with a simple example
    similar to your example below. If possible, please create a simple example
    that demonstrates this issue and send it in .zip format to
    support@digital-metaphors.com. Note however that the Language property of
    the TppReport is deprecated. The LanguageID property has replaced it giving
    a much more user friendly description of the language used.


    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.