Resource Files (RC) in C++

All announcements, questions and issues related to the TsiLang Components Suite.
Post Reply
RMeneghini
Posts: 13
Joined: Mon Dec 21, 2020 5:04 pm

Resource Files (RC) in C++

Post by RMeneghini »

Hello,

Most of my projects (BPL and EXE) store strings in resource files (RC). When I use the TsiLang Expert, I cannot find the strings.
What is the correct procedure to import strings stored in an RC file?

Best regards,

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

Re: Resource Files (RC) in C++

Post by isiticov »

Hello,

If you use only Win32 as a target platform for your project then you can check the following FAQ entry: https://www.tsilang.com/tsilang-faq/#9 (just replace "AnsiString" in the code sample with "string" as this sample code was written in "non-Unicode" times).
In case you need to support others platforms as well then the only way would be to place these strings in the code of some module and translate them as hard-coded strings with TsiLang. So you move strings from RC to C++ and then use some function that will assign their initial values and then translate this function code with TsiLang Expert.
Best regards,
Igor Siticov.
RMeneghini
Posts: 13
Joined: Mon Dec 21, 2020 5:04 pm

Re: Resource Files (RC) in C++

Post by RMeneghini »

Hello Igor,

Thank you very much for your advice. Using TsiLang Resource Strings Import Wizard worked perfectly.
I still have some confusion on how to put everything together. It seems that I need to create a SIB project for each BPL and one of the main program EXE. Is there a way to combine/merge all into a single SIB? The reason I ask is that I only use one TsiLangDispatcher. If I understood correctly, it should be possible to update translation (even add new languages) just by sending a new SIB. No need to recompile projects.

Best regards,

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

Re: Resource Files (RC) in C++

Post by isiticov »

Hello Roberto,

Yes, you can save/export all projects into one single SIB file but you have to be sure that ALL forms in all projects have different names, so every form has a unique name in order to have them all inside one SIB file. And then dispatcher and TsiLang components will be able to distinguish and load only the translations that are related to the particular form.
You can check the following article about creating applications translated by users without recompiling:
https://www.tsilang.com/create-user-tra ... lications/
Hope this helps.
Best regards,
Igor Siticov.
RMeneghini
Posts: 13
Joined: Mon Dec 21, 2020 5:04 pm

Re: Resource Files (RC) in C++

Post by RMeneghini »

Hello,

I was able to follow your instructions and import resource strings (RC).
However, I'm still not able to make it work. I have checked the "HandleResourceString" option. I have tried using LoadStr(100) and LoadStr(HInstance, 100). 100 is the string ID in the original RC file. I noticed that the Resource Wizard adds "IDS_RES_" in front of each ResID. In the above example, 100 becomes IDS_RES_100.

If I use siLang1->GetTextOrDefault("IDS_RES_100"), then it works correctly.

I'm using C++ Builder 10.3 Build 3.

Regards,

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

Re: Resource Files (RC) in C++

Post by isiticov »

Hello,

If you need to use LoadStr() then you will need to follow steps described at https://www.tsilang.com/tsilang-faq/#9.
You need to create LoadStr2() and replace all calls of LoadStr() with LoadStr2(). Then TsiLang will be able to catch and handle in memory translation for resource strings.
Best regards,
Igor Siticov.
RMeneghini
Posts: 13
Joined: Mon Dec 21, 2020 5:04 pm

Re: Resource Files (RC) in C++

Post by RMeneghini »

Hello,

Unfortunately, I'm still not able to make the LoadStr2() solution work. Always returns an empty string. I have made sure that "HandleResorceStrings" is set to "True".

I'm able to use GetTextOrDefault(Tag) by creating my own tag (i.e. IDS_RES_%d). The problem with this solution is that it only searches strings for the form that calls GetTextOrDefault. In other words, if I have two (2) forms within the same executable, and strings were imported using the "Resource String Wizard Import Tool", GetTextOrDefault seems to be working only for the form that was used as a target by the Wizard. Do you have a suggestion?

On a related note, we have some packages (BPL) that do not have graphic interfaces (mostly algorithms used for calculations). Some of these packages need to return strings. How can we use the siComponents in this case? Do we need to add a DataModule? I have tried using a DataModule with the siLangLinked component. However, the software crashes when the DataModule is created in the constructor (siLangLinked raises exceptions).

Best regards,

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

Re: Resource Files (RC) in C++

Post by isiticov »

Hello,

Could you please create a sample not-localized project with the same functionality as you project and send it to us? Then we will try to localize it and send you a detailed steps, so you could apply them to your real project?
Best regards,
Igor Siticov.
RMeneghini
Posts: 13
Joined: Mon Dec 21, 2020 5:04 pm

Re: Resource Files (RC) in C++

Post by RMeneghini »

Thank you for taking the time to help me.

Attached please find the requested example.

The LoadStr2() always returns the original (English) string. The GetTextOrDefault works as expected. However, if the RC file is removed from the project, the LoadStr2 returns an empty string.

Sincerely,

Roberto
Attachments
TsiLang.zip
(10.12 KiB) Downloaded 157 times
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Re: Resource Files (RC) in C++

Post by isiticov »

Hello,

Thank you for the file. Just REMOVE TsiLang_XXr (TsiLang run-time package) from the "Run-time packages" list for the project and everything will work. At least this worked for us. TsiLang will handle resource strings inside its own executable but when you use TsiLang run-time packages its package itself becomes different executable and your main EXE is not affected. So just remove run-time package from the list and TsiLang code will be built into main EXE and strings will be handled.
And, I'm very sorry, but you even don't need LoadStr2(). TsiLang perfectly handles LoadStr() calls, so no need for the updated function.
Please let me know if this helped.
Best regards,
Igor Siticov.
RMeneghini
Posts: 13
Joined: Mon Dec 21, 2020 5:04 pm

Re: Resource Files (RC) in C++

Post by RMeneghini »

Thank you very much. I will try it as soon as possible.
RMeneghini
Posts: 13
Joined: Mon Dec 21, 2020 5:04 pm

Re: Resource Files (RC) in C++

Post by RMeneghini »

Hello,

Just to let you know that, after removing the runtime packages as suggested by you, LoadStr is working as expected. Thank you for the advice.

The only problem that I have left is how to deal with classes that do not have visual components. I have tried adding a Data Module with siLangLinked but when I run the program and call a procedure of the NON-VCL class, the following error message appears "Property Caption does not exist". Any suggestions?

Regards,

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

Re: Resource Files (RC) in C++

Post by isiticov »

Hello,

Just update to 7.8.5.1 (recently released). This should get fixed this problem.
Best regards,
Igor Siticov.
Post Reply