Extension tools: Use of sMenuText and setText? Translation context?

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Roy_043
Veteran
Posts: 8544
Joined: Thu Dec 27, 2018 12:28 pm

Re: Extension tools: Use of sMenuText and setText? Translation context?

Post by Roy_043 »

wmayer wrote: Wed Jan 26, 2022 1:42 pm It's perfectly allowed to translate transaction texts, too.
Note that in the Draft WB "draft", not "Command", is used as the context for these strings. And that seems to work fine.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Extension tools: Use of sMenuText and setText? Translation context?

Post by openBrain »

Roy_043 wrote: Wed Jan 26, 2022 2:02 pm
openBrain wrote: Wed Jan 26, 2022 1:57 pmIIRC
See: https://github.com/FreeCAD/FreeCAD/blob ... w.ts#L1175
Sorry, I misunderstood when reading. Indeed QObject::tr() should not be used "as is".
You should always call a simple "tr()" without preceding it with class name.

There is roughly 2 main cases :
* Your class inherits QObject. In this case, you add the "Q_OBJECT" macro in class prototype, and "tr()" is subclassed automatically doing so.
* Your class doesn't inherits QObject. In this case, you "activate" the translation by addin the "Q_DECLARE_TR_FUNCTIONS(ClassName)" in the class prototype, that will deal with declaring "tr()" appropriately.

Complete reading : https://doc.qt.io/qt-5/i18n-source-translation.html :)
Post Reply