Automatic change of a translation

This forum designated to discuss the TsiLang Components Suite.
Ioan
Posts: 22
Joined: Tue Mar 14, 2006 8:32 pm
Location: Canada
Contact:

Automatic change of a translation

Post by Ioan »

Hello again,

We are using siComponents for translating our apps for a half year and everything works fine.

Now we trying to get to another level: we want to allow customizing the interface (and not only) based on an equivalences table (database). That means, every occurence of a word (ex: "user") that have an equivalent ("author") into a specified table to be replaced with this "translation" on the GUI (at run time).

I'm thinking to use the siComponents for this, using the equivalences as a different "language". That would require an "on-the-fly" translation and a way to bring the equivalences into a sib file.

Is there any way to automatically fill a sib file? Something like looking for any occurence of the "user" word in the first column (language) and create the second column (language) string replacing "user" with "author". Then load the sib file at run time and switching to the second "language".

Is this feasible?
Is this the right way to do it?

Sorry for the many questions I have, but I try to find out if is there already a solution for this before I go further.

Thanks,
Ioan

Haron
Posts: 39
Joined: Thu Mar 11, 2004 6:29 am

Post by Haron »

Can you, please, explain original problem? I think it is not possible to create SIB at run-time, but we can try to find work around.

Ioan
Posts: 22
Joined: Tue Mar 14, 2006 8:32 pm
Location: Canada
Contact:

Post by Ioan »

I don't want to create the SIB at run time, just modify it.

I have a table where my client can customize some items names. Like the "user" to be called "author".
I want to be able to read this table (at run time) and replace in my SIB file any occurence of "user" with "author", and then load the modified SIB.
Or, not changing the column for "Language1", but editing another "Language3" in SIB with the new name ("author") and then switching to "Language3".

Haron
Posts: 39
Joined: Thu Mar 11, 2004 6:29 am

Post by Haron »

Modification of SIB file not possible. I think it is best to implement middle-tier which will provide translations from your (custom table) or load from SIB (if not found in custom translations).

Ioan
Posts: 22
Joined: Tue Mar 14, 2006 8:32 pm
Location: Canada
Contact:

Post by Ioan »

What about the ReplaceStringValue method? I just find it. It is not good to edit the SIB (SIL) file at run time?

Haron
Posts: 39
Joined: Thu Mar 11, 2004 6:29 am

Post by Haron »

Hm, this method not known to me...

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

Post by isiticov »

Hello,

Sorry for delay with reply.
ReplaceStringValue will replace the translation for specified language for defined value. So you will need to "know" the identifier of the string and language number.
I guess you don't need to modify a SIB but just translations internally stored in some TsiLang.
So you can use ReplaceStringValue method for this.
Please let me know if this helps.
Best regards,
Igor Sitikov.

Ioan
Posts: 22
Joined: Tue Mar 14, 2006 8:32 pm
Location: Canada
Contact:

Post by Ioan »

Thank you, Igor.
I will try this, but not right now, I'm going in vacation for the next weeks and I'm waiting for the boss to approuve my estimation.
I will let you know.
Ioan

Ioan
Posts: 22
Joined: Tue Mar 14, 2006 8:32 pm
Location: Canada
Contact:

Post by Ioan »

I start working on this issue. I coded a function where I scan all the TsiLang TStrings properties (Captions, Hints, Strings, etc) and look for the string I want to replace. Then I retrieve the string ID and I call the ReplaceStringValue.
This function gets as input parameter the siLangLinked component of the current form as TsiCustomLang ( procedure CustomizeFields(siLang: TsiCustomLang); ).

After some tests I found out that the function seems to work properly, and I get the Strings values replaced, but not the Captions and other design features (I have only Multilines and Collections). I call the function on OnCreate form event (I also tried on OnShow). I logged into a file all the new and old values of the modified items and all seems to be properly replaced, but nothing changed on screen.

So, I think I miss something, maybe a kind of "refresh". Any idea?

Thanks,
Ioan

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

Post by isiticov »

Just call ChangeLanguage method after finishing the replacing.
Best regards,
Igor Sitikov.

Ioan
Posts: 22
Joined: Tue Mar 14, 2006 8:32 pm
Location: Canada
Contact:

Post by Ioan »

It worked. Thanks.

STevo
Posts: 5
Joined: Tue Oct 27, 2020 1:03 pm
Location: Slovakia
Contact:

Re: Automatic change of a translation

Post by STevo »

Hello i tryed use ReplaceStringValue and ChangeLanguage in event OnCreate form event. OK It worked.

But in topic Change Font you wrote
isiticov wrote:
Thu Dec 14, 2006 8:27 am

"You can try to use OnLinkToDispatcher event..."


I tryed it - see my code - but this not worked:

Code: Select all

procedure TDM.siLangDispatcher1LinkToDispatcher(Sender: TObject;
  ASiLang: TsiCustomLang);
begin
  if ASiLang.Owner.Name='Form1' then
  begin
    ASiLang.ReplaceStringValue(ASiLang.Captions,'ReplaceStringValue in Dispatcher','lblSLD',1);
    ASiLang.ChangeLanguage;
  end;
end;
my version is 7.3.3

it looks simple, but something is wrong.
Can you help please?
Best regards
STevo

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

Re: Automatic change of a translation

Post by isiticov »

Hello,

Do you have dispatcher's FileName property set to some file? Because OnLinkToDispatcher is called first and then loading from the file is performed if FileName property of the dispatcher is set.
Best regards,
Igor Sitikov.

STevo
Posts: 5
Joined: Tue Oct 27, 2020 1:03 pm
Location: Slovakia
Contact:

Re: Automatic change of a translation

Post by STevo »

Yes
in DataModuleCreate i call
siLangDispatcher1.FileName := SibFile;
siLangDispatcher1.LoadAllFromFile(SibFile);
and after is call siLangDispatcher1LinkToDispatcher from Form1
Command ReplaceStringValue and ChangeLanguage was executed

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

Re: Automatic change of a translation

Post by isiticov »

As you have FileName property set then the sequence of actions/events is:
1. OnLinkToDispatcher event called.
2. Inside it you change translation.
3. LoadAllFromFile([Dispatcher's FileName]) called and your changes made on 2. are overwritten with values from file.

In short: if you have dispatcher's FileName property set changing translations in OnLinkToDispatcher won't work as they get overwritten with the values from the file.
Best regards,
Igor Sitikov.

Post Reply