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: 8450
Joined: Thu Dec 27, 2018 12:28 pm

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

Post by Roy_043 »

In CommandExtensionPack.cpp I notice that there are two ways that menu texts are set: with sMenuText and setText. Why is that? And shouldn't the texts be identical for a given command?

https://github.com/FreeCAD/FreeCAD/blob ... k.cpp#L245

Code: Select all

    sMenuText       = QT_TR_NOOP("Draw circle center lines");
https://github.com/FreeCAD/FreeCAD/blob ... k.cpp#L346

Code: Select all

    arc1->setText(QApplication::translate("TechDraw_Extension", "Add Centerlines to Circles"));
There is also perhaps an issue with the translation context:
The first string (automatically I think) uses the command name "CmdTechDrawExtensionCircleCenterLines" as the context, the second "TechDraw_Extension".
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

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

Post by wandererfan »

Roy_043 wrote: Tue Jan 18, 2022 7:07 pm In CommandExtensionPack.cpp I notice that there are two ways that menu texts are set: with sMenuText and setText. Why is that? And shouldn't the texts be identical for a given command?
sMenuText is for the TechDraw menu in the main tool bar (File, Edit, ...). setText is for the drop down buttons in the extension toolbar.

Yes, the text should be the same.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

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

Post by Roy_043 »

Thanks. I'll try to create a PR to improve things.

AFAICT you should use the command name ("CmdTechDrawExtensionCircleCenterLines" in the example) as the context for setText and also for setToolTip.

But here two different contexts are used for these functions:
https://github.com/FreeCAD/FreeCAD/blob ... #L647-L668
Is there is special reason for this?
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

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

Post by wandererfan »

Roy_043 wrote: Tue Jan 18, 2022 9:22 pm But here two different contexts are used for these functions:
https://github.com/FreeCAD/FreeCAD/blob ... #L647-L668
Is there is special reason for this?
I can't think of one. Probably just blind cut, paste and edit.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

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

Post by Roy_043 »

Two other contexts that are perhaps questionable: "Command" and "QObject" are not very specific:

Code: Select all

Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Cosmetic Arc"));

Code: Select all

QObject::tr("TechDraw Hole Circle")
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

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

Post by wmayer »

Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Cosmetic Arc"));
This must not be changed because the context "Command" is used by the undo/redo dialogs. In order to have the transaction text translated a specific and fix context string is mandatory and the choice was "Command" as it's not too long.
QObject::tr("TechDraw Hole Circle")
This could be changed.
User avatar
Roy_043
Veteran
Posts: 8450
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 10:09 am used by the undo/redo dialogs
This is then not correct I assume?:
https://wiki.freecadweb.org/Translating_an_external_workbench wrote:Do not translate the text of document transactions made with Document.openTransaction()
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

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

Post by wmayer »

This is then not correct I assume?:
No. It's perfectly allowed to translate transaction texts, too. However, it wasn't supported in the past.
openBrain
Veteran
Posts: 9034
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 9:57 am Two other contexts that are perhaps questionable: "Command" and "QObject" are not very specific:

Code: Select all

Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Cosmetic Arc"));

Code: Select all

QObject::tr("TechDraw Hole Circle")
IIRC, when using QObject::tr(), the context is automatically added as being the class name. ;)
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

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

Post by Roy_043 »

Post Reply