TsiLang and Runtime Component Creation

This forum designated to discuss the TsiLang Components Suite.
Post Reply
vahid
Posts: 8
Joined: Sat Dec 14, 2019 11:57 am

TsiLang and Runtime Component Creation

Post by vahid »

Hi, is there any way to handle language change for components on a form that are being created Runtime and do not exist Designtime?

Thank you.

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

Post by isiticov »

Hello,

You can add code for updating the component's properties into OnChangeLanguage event and translate it. For example:

Code: Select all

procedure TForm1.siLang1ChangeLanguage(Sender: TObject);
begin
  LabelRunTime.Caption := siLang1.GetTextOrDefault('IDS_1');
end;
Something like that.
Best regards,
Igor Sitikov.

vahid
Posts: 8
Joined: Sat Dec 14, 2019 11:57 am

Post by vahid »

Hello,
Thank you for your reply;

the method you are suggesting requires all components to be handled in ChangeLanguage event of tsiLang component. what I am looking for is a way to add the component's caption to TsiLang component runtime. and then add translations for different Languages via code. Is there any way to achieve this ?

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

Post by isiticov »

Hello,

After adding/creating component at run-time you can call BuildList method to update translations and this will add a new entry(ies) for newly created components. And after that you can use ReplaceStringValue() method to add values for all languages.
But may be you can describe your situation a little bit more detailed and may be there is some more easier solution? As it looks like very rare and sophisticated case and I believe it could be resolved much easier.
Best regards,
Igor Sitikov.

vahid
Posts: 8
Joined: Sat Dec 14, 2019 11:57 am

Post by vahid »

Hi,
Thank you for your reply. :)

I need to create 2 different form's components runtime;
first, a form that changes based on users input on the previous form,
and second, a form that handles multiple forms of data entry.
my solution is to create components runtime and then use the methods you mentioned (BuildList and ReplaceStringValue) to achieve Language Change with just one line of code : siLang1.ActiveLanguage := 2;
I am open to better suggestions and thank you again. :D

vahid
Posts: 8
Joined: Sat Dec 14, 2019 11:57 am

Post by vahid »

another Question;
is there any way to use a repository for components Caption?
for example some components on a form can have the same caption, can we minimize the translated text's for that identical caption to 1?

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

Post by isiticov »

At run-time- no, there is no such functionality. But if you're worrying about size of stored translations then you can add in code something like this:

Code: Select all

Label1.Caption := 'File';
Label2.Caption :+ 'File
And then translate this code with TsiLang Expert. This will add only ONE entry for "File" item into Strings.

At design-time you can use Dictionary Manager to auto-translate items and add existing translations to dictionary.
Best regards,
Igor Sitikov.

Post Reply