Page 1 of 1

[Sketcher] Translating constraint messages

Posted: Tue Jun 21, 2022 5:31 pm
by chennes
Right now the constraint messages are being set in a non-GUI part of the code, in SketchObject.cpp -- because it's non-GUI, right now it doesn't include any Qt headers. I'd like to add #include <QCoreApplication> to SketchObject.h so that we can use the Q_DECLARE_TR_FUNCTIONS macro (and therefore the tr() function). Does anyone foresee any problems with this? The only alternative to translating those messages is a fairly complicated refactoring where we basically define the messages twice, once for the GUI and once for non-GUI use.

ETA: Here's an example of the sort of string I'm talking about: https://github.com/FreeCAD/FreeCAD/blob ... t.cpp#L202

Re: [Sketcher] Translating constraint messages

Posted: Tue Jun 21, 2022 6:00 pm
by openBrain
If you don't need an immediate translation, you can just mark the strings with QT_TRANSLATE_NOOP, so it will later be translate by the function that exposes the string to user. ;)

Re: [Sketcher] Translating constraint messages

Posted: Tue Jun 21, 2022 6:04 pm
by chennes
The function that displays the string to the user doesn't (and can't, in this case) do the translation. Those strings are immediately catenated together, so a NOOP version of the translation code won't work (and that macro still requires a Qt include).

Re: [Sketcher] Translating constraint messages

Posted: Tue Jun 21, 2022 6:23 pm
by openBrain
You can't avoid a Qt include to use the Qt translator for sure. :lol:

Your OP solution will work without any problem, but if messages are really concatenated, I see a risk that if some strings are translated and other not, you can get a strange language mixup at the end. :)

Re: [Sketcher] Translating constraint messages

Posted: Tue Jun 21, 2022 6:47 pm
by chennes
The catenation is that it takes a string like "Sketch with conflicting constraints" and adds the name of the constraint at the end, or other similar operations. It could be refactored, but that's a fair bit of work just to avoid a Qt include in the non-GUI code. We already do include QCoreApplication in some other non-GUI code, so there is precedent for it.

Re: [Sketcher] Translating constraint messages

Posted: Tue Jun 21, 2022 7:05 pm
by openBrain
Yep, your OP solution is totally correct IMO. When FC runs in CLI mode, this actually is a QCoreApplication, so no real problem with this.