Hopsan / hopsan

Hopsan is a free multi-domain system simulation tool developed at the division of Fluid and mechatronic systems at Linköping university.
Apache License 2.0
146 stars 41 forks source link

Multi-Language Support #2179

Open jkb-dfki opened 11 months ago

jkb-dfki commented 11 months ago

Description

For supporting educational scenarios (e.g. automation trainees in Germany), language customization in the Hopsan GUI is desired.

Proposed Solution

As indicated by the QT docs, the usage of qsTrId in combination with a respective XML file could in principle do the job.

Background

As we are currently investigating the feasibility of using Hopsan in our projects, we consider adding a multi-language support feature and providing a German language translation.

Additional Information Required

peterNordin commented 11 months ago

Hi Being able to translate into other langues would be a nice addition to Hopsan.

I looked at the link you supplied, but I dont believe that we can use that approach as it is intended for qml which we do not use. However similar functionality exists in C++ Qt already. Strings need to be wrapped in the tr("string") function, and we have already used it it some limited places. https://doc.qt.io/qt-5/i18n-source-translation.html

Then I tool can be used to do the actual translation, https://doc.qt.io/qt-5/linguist-translators.html I have not had time to read through the qt linguistics manual yet, so I do not know exactly how we generate the translation files, but I do not think it will be difficult.

While this approach would work for the GUI elements, there are also messages sent be the "HopsanCore" library (most of the messages that show up in the message widget). This library does not use Qt, so we can not translate those messages using this method. Exactly how to do that will require some research because we try to keep the simulation core "minimal" so a translation library in "plain C++" with no external dependencies would be required. It must also be possible to integrate such a library in a way so that it is possible to compile the Core without it (then defaulting to English).

But trying to activate the translation for the GUI could be a start I think. And then see if the Qt lingustics tools are easy to work with. Then many strings in the GUI code needs to be replaced with tr("string") or one of its versions.

jkb-dfki commented 11 months ago

Well i think most important is to use one method in a uniform way. I am just a little afraid if the tr() method really works on the supplied string only (regardless of context).

In my PoV, the translation of the GUI itself should address the majority of needs at least for our case. As soon as engine messages have to be understood by the user, requiring English may be more appropriate (i.e. its sufficient to translate the GUI to include more people as potential users).

Plus as soon as the GUI translation is working, translating (at least the most common) info messages from the engine is quite simple to accomplish if we could apply the tr() method to the console. I definitely see why you don't want to this is the engine.

So should i create a new branch or fork the project?

peterNordin commented 11 months ago

Fork and create a new branch in your fork, that is how we work ourselves. Then we can make pull requests ourselves to your branch in your fork if we have time to help out, if you need help with something. For instance build-system integration which may be a bit tricky. I recommend that you try to use the new CMake based build system, the old one should still work, but I intend to remove it (whenever I can find the time).

peterNordin commented 10 months ago

just an update, I have started trying to figure out how to generate the "ts" translation files from the source code, using CMake and Qt5. I have not figured it out yet though, the instructions are for Qt6 and do not work in Qt5 for some reason, I will try to find a way trigger it manually

jkb-dfki commented 10 months ago

Thank you very much! We really appreciate the time you invest (as we also appreciate Hospan itself). So if you have a fork we can join, please let us know.

peterNordin commented 10 months ago

I made some progress, but nothing usable yet, I have a WIP branch here https://github.com/peterNordin/hopsan/tree/issue-2179_translation_support

Now cmake build will re-generate/update the example "ts" files whenever I build, next step is figuring out how to translate them using one of the Qt linguistics tools, and how to get the generated "qm" files into the actual program.

peterNordin commented 10 months ago

Some more progress. I cleaned up my commits and for-pushed the branch. The code will now.

If you want to try and translate some of the strings you need to install the Qt5 Linguist tool, and open/edit the relevant .ts file in the source code tree in my branch. Then we need to add a lot more tr() to the code and update the .ts files with the new strings. Most strings should be easy, just to wrap the string in tr("string") but there are some complex strings and even multi-line ones that my be more complicated, so I will need to think about those a bit.

peterNordin commented 10 months ago

I added a bunch of tr() in the MainWindow code but I realized that there will be a risk for "git conflict" if you start translating and I keep adding tr() to the code and update the translation files. So I think that I should avoid checking in changes to the hopsangui_du_DE.ts file and let you do the updating manually instead.

That way you can focus on the translation and I can focus on the code. (Eventually you may need to help with code as well). To manually update the translation file from code, you can go into the HopsanGUI source code sub directory and run the following command lupdate -recursive . -ts translations/hopsangui_de_DE.ts to update the translation from any code changes. Ofcourse you need the Qt5 translation tools in the "PATH" to do it and how to do that depends on what OS your are running.

Then use the Qt5 Linguist tool to open that file and translate.

I will see if I can figure out how to give you push access directly to my branch, otherwise you will need to create pull-requests to my branch. But I think it will be easier if you can push directly.