New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATH] Fix bug with translated UI #5242
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some comments below: some of them are clearly "future work", but this seemed like a good opportunity to add them to the radar.
@@ -1,4 +1,4 @@ | |||
# -*- coding: utf-8 -*- | |||
# -*- cmding: utf-8 -*- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mistake?
@@ -74,7 +80,9 @@ def getForm(self): | |||
form.Tolerance.setTickInterval(1) | |||
form.Tolerance.setValue(10) | |||
form.Tolerance.setTickPosition(QtGui.QSlider.TicksBelow) | |||
form.Tolerance.setToolTip("Influences calculation performance vs stability and accuracy.") | |||
form.Tolerance.setToolTip( | |||
"Influences calculation performance vs stability and accuracy." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tooltips should get translated too.
formLayout.addRow(QtGui.QLabel("Stock to Leave"), form.StockToLeave) | ||
|
||
# Force inside out | ||
form.ForceInsideOut = QtGui.QCheckBox() | ||
form.ForceInsideOut.setChecked(True) | ||
formLayout.addRow(QtGui.QLabel("Force Clearing Inside-Out"), form.ForceInsideOut) | ||
formLayout.addRow( | ||
QtGui.QLabel("Force Clearing Inside-Out"), form.ForceInsideOut |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Translate
@@ -147,7 +175,10 @@ def setupFromExisting(): | |||
elif PathJobGui.StockFromExistingEdit.IsStock(self.obj): | |||
setupFromExisting() | |||
else: | |||
PathLog.error(translate('PathJob', "Unsupported stock object %s") % self.obj.Stock.Label) | |||
PathLog.error( | |||
translate("PathJob", "Unsupported stock object %s") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily for this PR, but long-term -- from a translation point of view, it's best if you can separate the string that must be translated from the part that translators shouldn't edit. So in this case I suggest something like
translate("PathJob","Unsupported stock object") + " %s" % self.obj.Stock.Label
or
translate("PathJob","Unsupported stock object") + f" {self.obj.Stock.Label}"
This prevents a translator from accidentally removing the "%s", extra spaces, punctuation, etc. from the string.
form.Side.addItem("Inside") | ||
form.Side.addItem("Outside") | ||
form.side.addItem( | ||
QtCore.QT_TRANSLATE_NOOP("Path", "Inside"), "Inside" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this PR (obviously!) but someday it might be nice to make these Enums instead of strings so that a linter/typechecker can catch mistakes.
if not FeatureFacing & self.pocketFeatures(): | ||
form.facingWidget.hide() | ||
form.clearEdges.hide() | ||
|
||
if FeaturePocket & self.pocketFeatures(): | ||
form.extraOffset_label.setText(translate("PathPocket", "Pass Extension")) | ||
form.extraOffset.setToolTip(translate("PathPocket", "The distance the facing operation will extend beyond the boundary shape.")) | ||
form.extraOffset.setToolTip( | ||
translate( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If in this codebase this is a synonym for QtCore.QT_TRANSLATE_NOOP
I suggest standardizing on one or the other. You'd probably save yourself some vertical space if you used the shorter one, if you're using Black.
path, | ||
"job_*.json")[0] | ||
foo = QtGui.QFileDialog.getOpenFileName( | ||
QtGui.QApplication.activeWindow(), "Path - Job Template", path, "job_*.json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these window titles need a translate()
(here and below)
@@ -190,37 +254,37 @@ def updateVisibility(self, sentObj=None): | |||
if hideFeatures: | |||
# reset values | |||
self.CATS = [None, None] | |||
self.selectInComboBox('Start to End', self.form.pathOrientation) | |||
self.selectInComboBox("Start to End", self.form.pathOrientation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not looked at how self.selectInComboBox()
works, but you might need to audit your usage of it to ensure that it's going to work with the new user data.
form.boundBoxSelect.clear() | ||
form.boundBoxSelect.addItem(QtCore.QT_TRANSLATE_NOOP("Path", "Stock"), "Stock") | ||
form.boundBoxSelect.addItem( | ||
QtCore.QT_TRANSLATE_NOOP("Path", "BaseBoundBox"), "BaseBoundBox" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I may, I suggest a little different approach to this type of solution. Ideally, translations would be available in the CL version of FreeCAD also. Making the proposed changes does not allow for this.
I suggest modifying the enumerations lists, or the parent method containing them, to contain these translate commands. I am referring to https://github.com/sliptonic/FreeCAD/blob/ed945419d416ac6f2d98317aef76ec385d6371f6/src/Mod/Path/PathScripts/PathSurface.py#L202-L215 for this particular operation. The opPropertyEnumerations()
referenced with the link returns a list of enumerations so CL users can query the class and identify the options available. Having these translations there makes sense, as the tooltips for the parent properties are available in the tuples stored in the opPropertyDefinitions()
method, and those tooltips are translated there. Ideally, I think some of these methods should be @classmethod type methods.
Putting these proposed translation commands of the enumeration elements within the base module, rather than the GUI module, and then automating the addItem()
population task for each combobox item makes the translations readily available across the operation, GUI or CL. As the proposed method stands, the enumeration element translations are only available via the GUI, whereas moving these to the appropriate methods in the base operation module will make for a more robust and manageable set of code, and shorter code since we could replace all the addItem()
calls with for e in enumerationProps:
iteration handler for a list of tuples that identify combobox items and their respective enumeration properties.
Not all ops make use of the database-style methods, opPropertyEnumerations()
and similar opPropertyDefinitions()
, that I put in place when editing Slot, Profile, Surface, and Waterline. These methods make certain other actions possible for users.
Hope this makes sense. Just my thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved the PR to draft. It looks like we have a constellation of translation related issues. We need to figure out exactly what to use before deploying the full-scale copy-paste that I tried in this PR.
Russ, I think I understand what you're getting at. Can you take one module and do a concrete implementation so we can see it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to do that tonight, though I need to do some lesson plans for my Algebra 1 class now! Haha.
Refer to sliptonic#20.
ed94541
to
2bfbbb9
Compare
https://forum.freecadweb.org/viewtopic.php?f=15&t=64336
Many files were touched in this PR.
All the Black reformatting was consolidated to a single commit.
Many of the .UI files have had certain comboboxes marked not translatable to avoid wasted effort. All these changes are in a single commit.
The remaining commits each fix a single module with the currentText/currentData bug.
Thank you for creating a pull request to contribute to FreeCAD! To ease integration, we ask you to conform to the following items. Pull requests which don't satisfy all the items below might be rejected. If you are in doubt with any of the items below, don't hesitate to ask for help in the FreeCAD forum!
App
,Base
,Gui
or one of theMod
subfolders. If you need to make changes in several locations, make several pull requests and wait for the first one to be merged before submitting the next onesgit pull --rebase upstream master
./bin/FreeCAD --run-test 0
Fixes typo in Draft Move command text
Draft: Fixed typos
issue #<id>
orfixes #<id>
where<id>
is the FreeCAD bug tracker issue number in case a particular commit solves or is related to an existing issue on the tracker. Ex:Draft: fix typos - fixes #0004805
And please remember to update the Wiki with the features added or changed once this PR is merged.
Note: If you don't have wiki access, then please mention your contribution on the 0.20 Changelog Forum Thread.