Dynamic export to SIL file

All announcements, questions and issues related to the TsiLang Components Suite.
Post Reply
CPS
Posts: 19
Joined: Fri Sep 17, 2021 1:48 pm

Dynamic export to SIL file

Post by CPS »

I have an old program that loads translation in weird way by chunks so it's impossible to extract text from its binary file.

Image

Therefore, the translation is available during runtime only and cannot be exported from IDE by using TsiLang component Translation Editor.

It would be wonderful, if some TSiLang method allow to save current properties (translation) to *.sil file during runtime.
Something like siLang.SaveToFile('MyForm.sil').
Last edited by CPS on Fri Dec 15, 2023 12:37 pm, edited 2 times in total.
isiticov
Site Admin
Posts: 2385
Joined: Thu Nov 21, 2002 3:17 pm

Re: Dynamic export to SIL file

Post by isiticov »

Just call BuilList method and then SaveAllToFile() methods of TsiLang to update the translations and save them into the SIL file. SaveAllToBinaryFile() will save to the SIB file.
Best regards,
Igor Siticov.
CPS
Posts: 19
Joined: Fri Sep 17, 2021 1:48 pm

Re: Dynamic export to SIL file

Post by CPS »

For some reason it saves only a hardcoded language (English), not that actually displayed during runtime.
It is ignores the current values and exports only those created in form designer.

Design time
Image

Runtime
Image

Saved to file
Image

It looks like TSiLang does not see what current text values are and retrives them from the form file.

I've found a solution, though.

Code: Select all

 L:= TStringList.Create();
 L.Add('labEnterDate='+ labEnterDate.Caption);
 L.SaveToFile(fn);
 L.Free();
The above code exports the text data correctly and gives this line

Code: Select all

labEnterDate=Ilerletilmis Harita Tarihini Girin:	
isiticov
Site Admin
Posts: 2385
Joined: Thu Nov 21, 2002 3:17 pm

Re: Dynamic export to SIL file

Post by isiticov »

CPS wrote: Fri Dec 15, 2023 2:33 pm For some reason it saves only a hardcoded language (English), not that actually displayed during runtime.
It is ignores the current values and exports only those created in form designer.
The following might help:
1. BEFORE loading Turkish values switch TsiLang's active language to Turkish.
2. Load language values into controls.
3. Call BuildList and SaveAllToFile methods of TsiLang.
Best regards,
Igor Siticov.
CPS
Posts: 19
Joined: Fri Sep 17, 2021 1:48 pm

Re: Dynamic export to SIL file

Post by CPS »

Unfortunately, setting active language to Turkish in first line of FormCreate() doesn't help.
Even if I remove a second language from TsiLang at all it saves English only and ignores the current values.

Image

Image
Last edited by CPS on Sat Dec 16, 2023 12:07 pm, edited 1 time in total.
CPS
Posts: 19
Joined: Fri Sep 17, 2021 1:48 pm

Re: Dynamic export to SIL file

Post by CPS »

I have found a solution.
=====================
1) Select English as program interface language.
2) By using a code below export all components into a ENG.SIL file
3) Select in program a Turkish language.
4) Export all components into a TUR.SIL file
5) Open ENG.SIL in TsiLang Files Editor
6) Merge TUR.SIL to opened ENG.SIL file
7) Save a resulting ENG file. Now it contains both languages.

Code: Select all

procedure ExportFormText(frm: TForm; Lng: string; fn: string);
  var L, L2, L3: TStrings; i, n, c: integer; S, nam, SCaptions, SHints, SItems, SCharSets, pfx1, pfx2: string;
 PPL: PPropList; PL: TPropList;
begin
 L:= TStringList.Create();  L2:= TStringList.Create();

 Lng:= LeftStr(UpperCase(Lng), 3);

 fn:= fn+ '_'+ Lng+ '.sil';

 if Lng= 'ENG' then begin
   pfx1:= '='; pfx2:= '~~';
 end else begin // Turkish
   pfx1:= '=~'; pfx2:= '~';
 end;

 SCaptions:= ''; SHints:= ''; SItems:= ''; SCharSets:= '';
 with frm do begin
 for i:= 0 to ComponentCount-1 do begin
   nam:= Components[i].Name;

   if IsPublishedProp((Components[i] as TObject), 'Font') then
//      SCharSets:= SCharSets+ frm.Name+ '.'+ nam+ '=~TURKISH_CHARSET~'+ #10;
      SCharSets:= SCharSets+ frm.Name+ '.'+ nam+ pfx1+ 'DEFAULT_CHARSET'+ pfx2+ #10;

   if IsPublishedProp((Components[i] as TObject), 'Caption') then begin
      S:= GetStrProp(Components[i], 'Caption');
      if S<> '' then
         SCaptions:= SCaptions+ frm.Name+ '.'+ nam+ pfx1+ S+ pfx2+ #10;
   end;

   if IsPublishedProp((Components[i] as TObject), 'Hint') then begin
      S:= GetStrProp(Components[i], 'Hint');
      if S<> '' then
         SHints:= SHints+ frm.Name+ '.'+ nam+ pfx1+ S+ pfx2+ #10;
   end;

   if IsPublishedProp((Components[i] as TObject), 'Items') then begin // multilines
      L2.Clear();
      L2:=  GetDynArrayProp(Components[i], 'Items');
      if L2.Text<> '' then begin
         n:= L2.Count;
         for n:= 0 to L2.Count - 1 do
            S:= S+ '"'+ L2[n]+ '",';
         if S<> '' then begin
            S:= LeftStr(S, Length(S)-1); // remove trailing comma
            SItems:= SItems+ frm.Name+ '.'+ nam+ pfx1+ S+ pfx2+ #10;
         end;
      end;
   end;
 end;
 end;

 L.Add('[Captions]'); L.Add(SCaptions);
 L.Add('');
 L.Add('[CharSets]'); L.Add(SCharSets);
 L.Add('');
 L.Add('[Language names - for internal use only!]');
 L.Add('Language_1=English');
 L.Add('Language_2=Turkish');
 L.Add('');
 L.Add('[Multilines]'); L.Add(SItems);


 if SHints<> '' then begin L.Add('[Hints]'); L.Add(SHints); end;

 L.Add('[OPTIONS]');
 L.Add('Delimiter=~');
 L.Add('IsUTF8File=0');
 L.Add('');

 L.SaveToFile(fn);

 L.Free(); L2.Free();
end;

isiticov
Site Admin
Posts: 2385
Joined: Thu Nov 21, 2002 3:17 pm

Re: Dynamic export to SIL file

Post by isiticov »

Glad to see you've figured out this problem.
Best regards,
Igor Siticov.
Post Reply