Translating error messages in SketchObjectPyImp.cpp

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: Translating error messages in SketchObjectPyImp.cpp

Post by chrisb »

chennes wrote: Fri May 19, 2023 3:58 pm whether it is better for the error message to make direct sense to you (in your native language) so you have a chance to correct whatever is wrong, or whether the error message is "universal" so that you don't even try to understand it, you just hit Google immediately. I suppose this is one of the reasons that "error codes" have stuck with us.
This is exactly what I experience, but i tseems completely independent from the language in which a message is shown.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
chennes
Veteran
Posts: 3881
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Translating error messages in SketchObjectPyImp.cpp

Post by chennes »

@chrisb what is your preference here: for translated error messages, or for the message to be in English?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: Translating error messages in SketchObjectPyImp.cpp

Post by chrisb »

chennes wrote: Fri May 19, 2023 10:00 pm @chrisb what is your preference here: for translated error messages, or for the message to be in English?
I would go for the English version. I mean we are not Microsoft or Apple, and even they did not yet get this completely fixed. We know by now that 3D modeling cannot be learned by clicking around and thus it can be seen as a detail to be learned how to handle error messages.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Translating error messages in SketchObjectPyImp.cpp

Post by abdullah »

I am not sure I am understanding it in full.

Are we referring to using English in the Report View or to using English in the UI dialogs/Notification area?

For me the ReportView is just a view showing a log.

There is this other related issue running in GH:
https://github.com/FreeCAD/FreeCAD-tran ... issues/223

I think it is important we make a decision to this topic, or any solution we find may be suboptimal.
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: Translating error messages in SketchObjectPyImp.cpp

Post by chrisb »

I was rather referring to report view. For popups, I can imagine to show both: a translated message and a button showing the untranslated version. This button would be suppressed if no translation exists, to avoid something similar to the messages in report view, which ask for checking report view.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Translating error messages in SketchObjectPyImp.cpp

Post by wmayer »

I have the idea that we do not translate messages that are reported in the report view.
I fully agree with this. IMO we should only translate text for things that a user interacts with, like a dialog or the notification area. The report view isn't something the user interacts with.

As already pointed out in this thread if somebody asks for help then it's important to easily locate the source code for a given message/warning/error and if really everything is translated this will become very difficult.
This is mostly messages triggered from the App part of FreeCAD (not the Gui part)
This doesn't mean that they shouldn't be translated when showing them in a dialog or the notification area.
One problem starts when we have dynamically generated strings, such as this code (from SketchObjectPyImp.cpp):
One way is to use placeholders in the string. With the recently added fmt library this should be very easy now.

Code: Select all

fmt::format(QT_TRANSLATE_NOOP("Exception", "Datum {} for the constraint with index {} is invalid"), (const char*)Quantity.getUserString().toUtf8(), Index);
What we then need is a structure that stores the format string and the arguments so that the actual string can be regenerated and translated if needed.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Translating error messages in SketchObjectPyImp.cpp

Post by abdullah »

wmayer wrote: Tue May 23, 2023 10:58 am
One problem starts when we have dynamically generated strings, such as this code (from SketchObjectPyImp.cpp):
One way is to use placeholders in the string. With the recently added fmt library this should be very easy now.

Code: Select all

fmt::format(QT_TRANSLATE_NOOP("Exception", "Datum {} for the constraint with index {} is invalid"), (const char*)Quantity.getUserString().toUtf8(), Index);
What we then need is a structure that stores the format string and the arguments so that the actual string can be regenerated and translated if needed.
I thought of this (although storing the printf format string instead of the fmt::format one).

As we need this in one python exception, we would need a pair of c++/python exceptions that can store the arguments as a Python dictionary and then, when creating the c++ exception from the python one (in Interpreter.cpp), store them in the c++ one, so that when caught it can be processed. In fact, the c++ exception could have methods to retrieve an non-localised and a localised version of it.

Did I get your idea right? BTW, is there any advantage (other than possibly performance), from using the fmt syntax as opposed to printf syntax?

The simpler yet way less flexible alternative to this that I have thought, is to create a new exception pair "ErrorCodeError", which stores an error code. This means duplicating the strings at both ends which are only related by the error code. I do not like the error-code to string association, and the duplication. It is by far not very maintainable.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Translating error messages in SketchObjectPyImp.cpp

Post by wmayer »

BTW, is there any advantage (other than possibly performance), from using the fmt syntax as opposed to printf syntax?
Safety, simplification and portability.
Post Reply