Loading from binary file

All announcements, questions and issues related to the TsiLang Components Suite.
Post Reply
primarypower
Posts: 34
Joined: Thu Jul 30, 2009 2:37 pm

Loading from binary file

Post by primarypower »

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.
primarypower
Posts: 34
Joined: Thu Jul 30, 2009 2:37 pm

Post by primarypower »

Please, I need a help
I´m stuck in the development and I can´t deliver my product!!! I hate depending on third party...
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Hello,

You can use OnLinkToDispatcher event to load stream content to the TsiLang.
Best regards,
Igor Siticov.
primarypower
Posts: 34
Joined: Thu Jul 30, 2009 2:37 pm

Post by primarypower »

Dear Igor

I tried that... but the library gives me an exception, maybe I´m using an old version of the library?
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

What kind of exception do you get?
Best regards,
Igor Siticov.
primarypower
Posts: 34
Joined: Thu Jul 30, 2009 2:37 pm

Post by primarypower »

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?
primarypower
Posts: 34
Joined: Thu Jul 30, 2009 2:37 pm

Post by primarypower »

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

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;
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...
primarypower
Posts: 34
Joined: Thu Jul 30, 2009 2:37 pm

Post by primarypower »

Well, didn´t work out as I expected!!!

Loading the translations this way does not merge translation of ancestral classes

Please help me!
primarypower
Posts: 34
Joined: Thu Jul 30, 2009 2:37 pm

Post by primarypower »

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!
primarypower
Posts: 34
Joined: Thu Jul 30, 2009 2:37 pm

Post by primarypower »

The version that I´m using here is 6.5.0.1
I have to pay to get the latest version, so I will only upgrade if this is solved
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

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.
Best regards,
Igor Siticov.
primarypower
Posts: 34
Joined: Thu Jul 30, 2009 2:37 pm

Post by primarypower »

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
Post Reply