Page 1 of 1

Dynamic export to SIL file

Posted: Fri Dec 15, 2023 12:02 pm
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').

Re: Dynamic export to SIL file

Posted: Fri Dec 15, 2023 12:11 pm
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.

Re: Dynamic export to SIL file

Posted: Fri Dec 15, 2023 2:33 pm
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:	

Re: Dynamic export to SIL file

Posted: Sat Dec 16, 2023 2:09 am
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.

Re: Dynamic export to SIL file

Posted: Sat Dec 16, 2023 11:55 am
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

Re: Dynamic export to SIL file

Posted: Sat Dec 16, 2023 3:13 pm
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;


Re: Dynamic export to SIL file

Posted: Sun Dec 17, 2023 12:52 pm
by isiticov
Glad to see you've figured out this problem.