Page 2 of 2

Re: Automatic change of a translation

Posted: Tue Oct 27, 2020 2:45 pm
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

Re: Automatic change of a translation

Posted: Tue Oct 27, 2020 2:54 pm
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.

Re: Automatic change of a translation

Posted: Wed Oct 28, 2020 8:03 am
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

Re: Automatic change of a translation

Posted: Wed Oct 28, 2020 2:52 pm
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.

Re: Automatic change of a translation

Posted: Thu Oct 29, 2020 8:57 am
by STevo
now everything is as it should be
Great, It Works.
Thanks

Berst Regards
STevo