Page 1 of 1
TsiLang and Runtime Component Creation
Posted: Sun Dec 15, 2019 6:25 am
Hi, is there any way to handle language change for components on a form that are being created Runtime and do not exist Designtime?
Posted: Sun Dec 15, 2019 7:21 am
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);
LabelRunTime.Caption := siLang1.GetTextOrDefault('IDS_1');
Something like that.
Posted: Sun Dec 15, 2019 10:09 am
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 ?
Posted: Sun Dec 15, 2019 11:36 am
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.
Posted: Tue Dec 17, 2019 6:43 am
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.
Posted: Tue Dec 17, 2019 7:00 am
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?
Posted: Tue Dec 17, 2019 7:59 am
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.