Path OPs don't work with translated UI

Here's the place for discussion related to CAM/CNC and the development of the Path module.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
chennes
Veteran
Posts: 3908
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Path OPs don't work with translated UI

Post by chennes »

I recently changed the translation extraction code, it's possible those strings were not being made available for translation before due to a mistake in the old way of determining whether to extract C++ or Python translation strings.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
chennes
Veteran
Posts: 3908
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Path OPs don't work with translated UI

Post by chennes »

Russ4262 wrote: Wed Dec 08, 2021 12:34 am Currently, most enumerations are hard coded in UI files.
Can you link a specific example so I can see what you mean? We've avoided the issue elsewhere by strictly separating UI lists from their corresponding program logic. This is often accomplished by relying on, for example, the index of the item rather than its text, but often a better approach is to attach "user data" to each UI element. That's almost always my approach in C++, but I haven't really tried it in Python.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
herbk
Veteran
Posts: 2660
Joined: Mon Nov 03, 2014 3:45 pm
Location: Windsbach, Bavarya (Germany)

Re: Path OPs don't work with translated UI

Post by herbk »

sliptonic wrote: Wed Dec 08, 2021 1:39 am That sounds correct but why was this never a problem before?
In my mind 2 possible reasons:
1. The enumerations were not in crowdin
2. If they were, no one translated it...
Gruß Herbert
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Path OPs don't work with translated UI

Post by onekk »

But in 0.19 and initial 0.20 code if you assign a .Name property not starting with "Job” some actions were not triggered.

Maybe this behaviour is different now, but in the past when I was scripting Path I have noted this.

Sorry if it is not related.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
chennes
Veteran
Posts: 3908
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Path OPs don't work with translated UI

Post by chennes »

OK, I took a closer look at this particular example. First, I'm relatively certain that the answer to "why was this never a problem before?" is because there used to be a bug in the translation extraction code that was causing these UI files to be skipped. That's been fixed, and they are now translatable, as all UI files should be by default. That recent translation merge was done just after the change to the extraction script, so the new translations aren't due to overzealous translators: they are doing exactly what they should be doing, translating all user interface strings.

So, the problem is that fundamentally this line:

Code: Select all

obj.Side = str(self.form.cutSide.currentText())
is not a good practice. It's depending on the exact user interface text meaning something programmatically, which is generally inadvisable (in part for exactly this reason). In my opinion the best solution is to attach extra data to each UI element, and instead of using "currentText" (the user-visible string) use "currentData" (the invisible value that the program requires internally). You could also use the index directly, if you know that the order of the elements is stable, but I personally have found that to be more code in the long run, if you have to do this in more than one place.

In this particular case you would have something along the lines of:

Code: Select all

def getForm(self):
        '''getForm() ... returns UI customized according to profileFeatures()'''
        form = FreeCADGui.PySideUic.loadUi(":/panels/PageOpProfileFullEdit.ui")
        form.cutSide.setItemData(0, "Outside") # Does NOT change the displayed text
        form.cutSide.setItemData(1, "Inside")
        return form
        
        ...
        
 def getFields(self, obj):
        '''getFields(obj) ... transfers values from UI to obj's proprties'''
        self.updateToolController(obj, self.form.toolController)
        self.updateCoolant(obj, self.form.coolantController)

        if obj.Side != str(self.form.cutSide.currentData()): #Uses the data stored in Qt.UserRole
            obj.Side = str(self.form.cutSide.currentData())
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
sliptonic
Veteran
Posts: 3459
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Path OPs don't work with translated UI

Post by sliptonic »

I've created a PR to resolve this based on chennes's ideas.

It goes a bit farther and clears the combobox contents when the forms are loaded and then populates them with the strings. This means all the string literals are defined in the code and the code ignores any literals that are in the .UI files. At some point, we should go back to the .UI files and replace the text there with 'PLACEHOLDER' or something so future developers don't waste their time. I've left them for now because it's probably easier to troubleshoot if I made a mistake somewhere.

The changes are a lot of cut-n-paste but this PR touches a LOT of files so I'd appreciate some testers.

https://github.com/FreeCAD/FreeCAD/pull/5242
Samu
Posts: 51
Joined: Fri Jan 29, 2021 2:16 pm

Re: Path OPs don't work with translated UI

Post by Samu »

OS: Ubuntu 20.04.3 LTS (ubuntu:GNOME/ubuntu)
Word size of FreeCAD: 64-bit
Version: 0.20.
Build type: Release
Branch: unknown
Hash: e54b6e167a5d5ab863e8d4db68e4add65b1525ba
Python version: 3.8.10
Qt version: 5.12.8
Coin version: 4.0.0
OCC version: 7.5.2
Locale: English/United States (en_US)

Since the last update I'm experiencing the above mentioned problem also in the English UI. But only for the 'slot' Operation. If I want to create a slot e.g. on the attached file, I get the following error:

16:46:18 Running the Python command 'Path_Slot' failed:
Traceback (most recent call last):
File "/usr/share/freecad-daily/Mod/Path/PathScripts/PathOpGui.py", line 1440, in Activated
return Create(self.res)
File "/usr/share/freecad-daily/Mod/Path/PathScripts/PathOpGui.py", line 1402, in Create
obj = res.objFactory(res.name, obj=None, parentJob=res.job)
File "/usr/share/freecad-daily/Mod/Path/PathScripts/PathSlot.py", line 1774, in Create
obj.Proxy = ObjectSlot(obj, name, parentJob)
File "/usr/share/freecad-daily/Mod/Path/PathScripts/PathOp.py", line 351, in __init__
job = self.setDefaultValues(obj)
File "/usr/share/freecad-daily/Mod/Path/PathScripts/PathOp.py", line 576, in setDefaultValues
obj.CoolantMode = job.SetupSheet.CoolantMode

'Flood' is not part of the enumeration in Unnamed#Slot.CoolantMode

I'm sorry, if that is not related to the problem described in this topic - If so, I will create a new topic.

Any help greatly appreciated because many of my files I need on a daily basis contain slot operations :)
Attachments
Slot_Bug_Example_1.FCStd
(27.7 KiB) Downloaded 13 times
User avatar
FBXL5
Posts: 988
Joined: Sat Aug 03, 2019 8:45 pm

Re: Path OPs don't work with translated UI

Post by FBXL5 »

PartDesign Sprocket... has an enumeration problem, too:

Bicycle with Derailleur and Bicycle without Derailleur must not be translated and I have made a new suggestion in Crowdin in the meantime. Since there hasn't been any voting the new "translations" are on top of the list and used in the UI.

Motorrad... is still false and needs correction back to Motorcycle...
User avatar
sliptonic
Veteran
Posts: 3459
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Path OPs don't work with translated UI

Post by sliptonic »

Samu wrote: Sun Feb 06, 2022 3:59 pm
Since the last update I'm experiencing the above mentioned problem also in the English UI. But only for the 'slot' Operation. If I want to create a slot e.g. on the attached file, I get the following error:
Slot is the only operation that hasn't been completed for the translation cleanup project. It's kinda hairy code and I asked @Russ4262 to help out.
Russ4262
Posts: 952
Joined: Sat Jun 30, 2018 3:22 pm
Location: Oklahoma
Contact:

Re: Path OPs don't work with translated UI

Post by Russ4262 »

sliptonic wrote: Mon Feb 07, 2022 2:33 pm ...
Slot is the only operation that hasn't been completed for the translation cleanup project. It's kinda hairy code and I asked @Russ4262 to help out.
Evening Sir.
I just submitted a PR with what I believe to be the fix for translation issues within this operation, Path: Fix Slot operation translation issue #6340.

Thanks for your patience and tremendous contributions.

Russell
Post Reply