Loading from binary file
-
- Posts: 34
- Joined: Thu Jul 30, 2009 2:37 pm
Loading from binary file
Hi
I have a problem using the TsiLang components and I need a help.
I need to load the translation files from SIB data but I will not leave the files on disk, instead I will do an architecture where I will store the translation files in a DLL as a resource and load it from stream later in the software
My problem is loading this for all the forms. If I use LoadAllFromStream in the dispatcher, it will only load the language file for the current created forms, but I need to load for future forms as well. I saw that to achieve that I need to set property Filename in dispatcher, but I won´t send the .SIB files with my software, I want all SIB files to be inside a DLL file.
What can I do?
I don´t want to manually call LoadAllFromBinaryStream for all TsiLangLinked component in all forms that I have, that will break all the concept of the Dispatcher...
I think that when I call LoadAllFromStream in the dispatcher, it should store the stream somewhere and when the TsiLangLinked components are actually linked to the dispatcher (By AddReference routine) it should load the stream.
I have a problem using the TsiLang components and I need a help.
I need to load the translation files from SIB data but I will not leave the files on disk, instead I will do an architecture where I will store the translation files in a DLL as a resource and load it from stream later in the software
My problem is loading this for all the forms. If I use LoadAllFromStream in the dispatcher, it will only load the language file for the current created forms, but I need to load for future forms as well. I saw that to achieve that I need to set property Filename in dispatcher, but I won´t send the .SIB files with my software, I want all SIB files to be inside a DLL file.
What can I do?
I don´t want to manually call LoadAllFromBinaryStream for all TsiLangLinked component in all forms that I have, that will break all the concept of the Dispatcher...
I think that when I call LoadAllFromStream in the dispatcher, it should store the stream somewhere and when the TsiLangLinked components are actually linked to the dispatcher (By AddReference routine) it should load the stream.
-
- Posts: 34
- Joined: Thu Jul 30, 2009 2:37 pm
-
- Posts: 34
- Joined: Thu Jul 30, 2009 2:37 pm
-
- Posts: 34
- Joined: Thu Jul 30, 2009 2:37 pm
Hi Igor
I actually got it working, but now I have another issue... I have some derived classes where the TsiLang control is placed on the first base form class, and I have translations in all layers (Base, 1º derivate and 2º derivate), the problem is that now when I load it from the stream (WHen linking to the dispatcher, it will not load the translations of the base and 1º derivate, just from the last derivate because the component is linked just once.
How can I automatically load the translations for the base and 1º derivate?
I actually got it working, but now I have another issue... I have some derived classes where the TsiLang control is placed on the first base form class, and I have translations in all layers (Base, 1º derivate and 2º derivate), the problem is that now when I load it from the stream (WHen linking to the dispatcher, it will not load the translations of the base and 1º derivate, just from the last derivate because the component is linked just once.
How can I automatically load the translations for the base and 1º derivate?
-
- Posts: 34
- Joined: Thu Jul 30, 2009 2:37 pm
Igor,
Since when the TsiLang component is linked to the dispatcher, the owner of the component is always the last derivative, I made the following code in order to load the translation of the 1 and base classes, check and please comment if it is safe to work this way
I´m basically doing what your LoadAllFromBinaryStream does, but I´m loading all translations from derivate classes and it actually worked... So, can I work this way or do you think that it is not safe...
Since when the TsiLang component is linked to the dispatcher, the owner of the component is always the last derivative, I made the following code in order to load the translation of the 1 and base classes, check and please comment if it is safe to work this way
Code: Select all
procedure TD_RecursosCM.tsiDispatcherLinkToDispatcher(Sender: TObject;
ASiLang: TsiCustomLang);
var
ParentClass: TClass;
begin
// Check ownership
if not Assigned(ASiLang.Owner) then
Exit;
// Get the owner class
ParentClass := ASiLang.Owner.ClassType;
// Load the translation for all parent classes
while (Assigned(ParentClass)) and
(ParentClass <> TForm) and
(ParentClass <> TFrame) do
begin
// Load translation
with TSIBFileManager.Create do
try
LoadFromStream(ASiLang, ParentClass.ClassName, FLocalizationData);
finally
Free;
end;
// Next parent
ParentClass := ParentClass.ClassParent;
end;
// Update language
ASiLang.UpdateStrCollections;
ASiLang.ChangeLanguage;
end;
-
- Posts: 34
- Joined: Thu Jul 30, 2009 2:37 pm
-
- Posts: 34
- Joined: Thu Jul 30, 2009 2:37 pm
I did a test, and I found that even if I use the external .sib file with my software by using:
Dispatcher.LoadAllFromFile and Dispatcher.FileName property
The same behaviour occur!
The translation component becomes useless when it comes to derived forms, all translation will be loaded only for the last descendant form, translation strings for ancestral forms won´t be loaded so, what should I do?? I really really need this, I have many derived forms and the translation is not working and you take too much time to anwer my questions and my customers are really pushing me over here and I cannot deliver it!
Dispatcher.LoadAllFromFile and Dispatcher.FileName property
The same behaviour occur!
The translation component becomes useless when it comes to derived forms, all translation will be loaded only for the last descendant form, translation strings for ancestral forms won´t be loaded so, what should I do?? I really really need this, I have many derived forms and the translation is not working and you take too much time to anwer my questions and my customers are really pushing me over here and I cannot deliver it!
-
- Posts: 34
- Joined: Thu Jul 30, 2009 2:37 pm
Do you have IsInheritedOwner property set to True? When you open Translations Editor do you see ALL the translations in derived forms? That also should include translations from the base form. If you see all the translations then when you save to SIL/SIB file the file will contain all of them as well. As result when loading this file all the translations will be loaded.
You can always try this with the latest version. The trial version available on our web-site is fully functional and you can test all the functionality.
Please let us know if this helped.
You can always try this with the latest version. The trial version available on our web-site is fully functional and you can test all the functionality.
Please let us know if this helped.
Best regards,
Igor Siticov.
Igor Siticov.
-
- Posts: 34
- Joined: Thu Jul 30, 2009 2:37 pm
Hi Igor
I see your point.
The IsInheritedOwner is set to true, but no, I can´t see translations of base forms
I remember deleting translation from base forms in derived forms, because when I change something in base form it was not changing in derived forms, and the strings were being stored twice, one for base form and anoher for derived form.
But anyway, I overcame this issue by creating a "hack" around the library. Basically I temporary load the translations of all base classes in temporary TsiLang components and manually merge the TStrings that holds the translations. It is working fine now... the only thing is that if you change this storing technique in the future I will have to change my code, but anyway, if we don´t see an updated version that supports firemonkey in the future we will have to switch to another localization library, so, no problem
I see your point.
The IsInheritedOwner is set to true, but no, I can´t see translations of base forms
I remember deleting translation from base forms in derived forms, because when I change something in base form it was not changing in derived forms, and the strings were being stored twice, one for base form and anoher for derived form.
But anyway, I overcame this issue by creating a "hack" around the library. Basically I temporary load the translations of all base classes in temporary TsiLang components and manually merge the TStrings that holds the translations. It is working fine now... the only thing is that if you change this storing technique in the future I will have to change my code, but anyway, if we don´t see an updated version that supports firemonkey in the future we will have to switch to another localization library, so, no problem