[Sketcher] Translating constraint messages

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
Post Reply
User avatar
chennes
Veteran
Posts: 2240
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

[Sketcher] Translating constraint messages

Post 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
Chris Hennes
Pioneer Library System
openBrain
Veteran
Posts: 7993
Joined: Fri Nov 09, 2018 5:38 pm

Re: [Sketcher] Translating constraint messages

Post 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. ;)
User avatar
chennes
Veteran
Posts: 2240
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: [Sketcher] Translating constraint messages

Post 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).
Chris Hennes
Pioneer Library System
openBrain
Veteran
Posts: 7993
Joined: Fri Nov 09, 2018 5:38 pm

Re: [Sketcher] Translating constraint messages

Post 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. :)
User avatar
chennes
Veteran
Posts: 2240
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: [Sketcher] Translating constraint messages

Post 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.
Chris Hennes
Pioneer Library System
openBrain
Veteran
Posts: 7993
Joined: Fri Nov 09, 2018 5:38 pm

Re: [Sketcher] Translating constraint messages

Post 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.
Post Reply