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
Automatic change of a translation
Re: Automatic change of a translation
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:
In this case you will have translations loaded from the file and then updated to the needed value.
Hope this helps.
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.
Igor Siticov.
Re: Automatic change of a translation
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

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 715 times
Re: Automatic change of a translation
These are changes to your sample that make it work (they are marked with // !!!! ):
Sorry, for my incorrect sample in previous post. Because as you set FileName property to dispatcher the content gets loaded from the file.
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;
Best regards,
Igor Siticov.
Igor Siticov.
Re: Automatic change of a translation
now everything is as it should be
Great, It Works.
Thanks
Berst Regards
STevo
Great, It Works.
Thanks
Berst Regards
STevo