Automatic change of a translation

All announcements, questions and issues related to the TsiLang Components Suite.
STevo
Posts: 5
Joined: Tue Oct 27, 2020 1:03 pm
Location: Slovakia
Contact:

Re: Automatic change of a translation

Post by STevo »

if i not assign value for FileName, it is call only LoadAllFromFile, then
ReplaceStringValue not work in OnCreateForm, but work in OnLinkToDispatcher .
it is fine solution for me
Thanks

Best Regards
STevo
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Re: Automatic change of a translation

Post by isiticov »

But in this case your TsiLang on "Form1" won't be loaded from the file. So you may update your code a little:
1. In OnLinkToDispatcher event load ASiLang from Dispatcher's FileName
2. And then update the translation using ReplaceStringValue.
Something like this:

Code: Select all

procedure TDM.siLangDispatcher1LinkToDispatcher(Sender: TObject;
  ASiLang: TsiCustomLang);
begin
  if FileExists(siLangDispatcher1.FileName) then
    ASiLang.LoadAllFromSIBFile(siLangDispatcher1.FileName);
  if ASiLang.Owner.Name='Form1' then
  begin
    ASiLang.ReplaceStringValue(ASiLang.Captions,'ReplaceStringValue in Dispatcher','lblSLD',1);
    ASiLang.ChangeLanguage;
  end;
end;

In this case you will have translations loaded from the file and then updated to the needed value.

Hope this helps.
Best regards,
Igor Siticov.
STevo
Posts: 5
Joined: Tue Oct 27, 2020 1:03 pm
Location: Slovakia
Contact:

Re: Automatic change of a translation

Post by STevo »

It is true in my case is SIB file not loaded :-(
I tryed your code but it dont work. I attach small test project. I can not find good way for using OnLinkToDispatcher
Attachments
SilangTest3.zip
smal test project
(64.59 KiB) Downloaded 126 times
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Re: Automatic change of a translation

Post by isiticov »

These are changes to your sample that make it work (they are marked with // !!!! ):

Code: Select all

// !!!! move this here
var
  SibFile: string;


procedure TDM.DataModuleCreate(Sender: TObject);
var
  FL: string;

begin
  FL := Application.ExeName;
  SibFile := ChangeFileExt(FL, '.sib');
  if FileExists(SibFile) then
  begin
  // !!!! This is not needed
//    siLangDispatcher1.FileName := SibFile;
//    siLangDispatcher1.LoadAllFromFile(SibFile);
  end;
end;

procedure TDM.siLangDispatcher1LinkToDispatcher(Sender: TObject;
  ASiLang: TsiCustomLang);
begin
// !!!! Use global SIB File
  if FileExists(SibFile) then
  // !!!! Use LoadAllFromBinaryFile method to load SIB
    ASiLang.LoadAllFromBinaryFile(SibFile);

  if ASiLang.Owner.ClassName='TFhlavfrm' then
  begin
    ASiLang.ReplaceStringValue(ASiLang.Captions,'OK in DISP','btn1',1);
    ASiLang.ReplaceStringValue(ASiLang.Captions,'ReplaceStringValue in DISP','lblSLD',1);
    ASiLang.ChangeLanguage;
  end;
  if ASiLang.Owner.Name='FChild' then
  begin
    ASiLang.ReplaceStringValue(ASiLang.Captions,'Text from DISP LBL1','lbl1',1);
    ASiLang.ReplaceStringValue(ASiLang.Captions,'Text from DISP LBL2','lbl2',1);
    ASiLang.ReplaceStringValue(ASiLang.Captions,'OK in DISP','btn1',1);
    ASiLang.ChangeLanguage;
  end;
end;
Sorry, for my incorrect sample in previous post. Because as you set FileName property to dispatcher the content gets loaded from the file.
Best regards,
Igor Siticov.
STevo
Posts: 5
Joined: Tue Oct 27, 2020 1:03 pm
Location: Slovakia
Contact:

Re: Automatic change of a translation

Post by STevo »

now everything is as it should be
Great, It Works.
Thanks

Berst Regards
STevo
Post Reply