How to have bullet points in an error message?

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
DeepSOIC
Posts: 6185
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: How to have bullet points in an error message?

Postby DeepSOIC » Tue Dec 04, 2018 9:40 am

NormandC wrote:
Tue Dec 04, 2018 3:16 am
DeepSOIC wrote:
Mon Dec 03, 2018 2:07 pm
Use html, maybe?
Thanks, creative, but not working for me. C++ may not be directly recognizing html, seems like Python does?
Hmm, strange. I was under impression that it's Qt doing the recognition and formatting. It is certainly not python, we are just calling the same QMessageBox after all. Maybe html in messageboxes isn't supported on linux? Or maybe it wants some flag? I don't know...

Can you try this? It's as close as it can get to C++ code. HTML formatting works here on Win for this warning popup.

Code: Select all

from PySide import QtGui
QtGui.QMessageBox.warning(None, "test", "<html>message<ul><li>item1</li><li>item2</li></ul></html>")
DeepSOIC
Posts: 6185
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: How to have bullet points in an error message?

Postby DeepSOIC » Tue Dec 04, 2018 9:46 am

NormandC wrote:
Tue Dec 04, 2018 3:16 am
DeepSOIC wrote:
Mon Dec 03, 2018 2:07 pm
Use html, maybe?
Thanks, creative, but not working for me. C++ may not be directly recognizing html, seems like Python does?
OK, I think I found why it didn't work for you: <html> is ignored if a newline character is encountered before <html> tag. Try wrapping the whole message in html tags.
wmayer
Site Admin
Posts: 13366
Joined: Thu Feb 19, 2009 10:32 am

Re: How to have bullet points in an error message?

Postby wmayer » Tue Dec 04, 2018 10:35 am

DeepSOIC wrote:
Tue Dec 04, 2018 9:29 am
wmayer wrote:
Tue Dec 04, 2018 9:06 am

Code: Select all

std::string message = QT_TR_NOOP("The requested feature cannot be created. The reason may be that:");
message += "\n\xe2\x80\xa2";
message += QT_TR_NOOP("the active Body does not contain a base shape, so there is no material to be removed");
message += "\n\xe2\x80\xa2";
message += QT_TR_NOOP("the selected sketch does not belong to the active Body.");
...
The code to display the error message should then be changed to (TaskDlgFeatureParameters::accept()):

Code: Select all

QMessageBox::warning(..., QApplication::translate(..., e.what()));
But will it work at all? I thought, Qt looks up the whole string in the translation library, but will not find it because only pieces are in the library?
Oh shit, you're right! I haven't thought of this. So, if following this idea you have to use QCoreApplication::translate already inside the Pocket feature, convert the whole QString into a raw C string using toUtf8() and later convert back with fromUtf8().

Code: Select all

QString message = QCoreApplication::translate("PartDesign::Pocket", "The requested feature cannot be created. The reason may be that:");
message += QLatin1String("\n\xe2\x80\xa2");
message += QCoreApplication::translate("PartDesign::Pocket", "the active Body does not contain a base shape, so there is no material to be removed");
message += QLatin1String("\n\xe2\x80\xa2");
message += QCoreApplication::translate("PartDesign::Pocket", "the selected sketch does not belong to the active Body.");
return new App::DocumentObjectExecReturn(message.toUtf8());

Code: Select all

QMessageBox::warning(..., QString::fromUtf8(e.what()));
User avatar
NormandC
Posts: 17221
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: How to have bullet points in an error message?

Postby NormandC » Sat Dec 08, 2018 8:57 pm

You guys have completely and utterly lost me, you know that, right?

How is the existing string currently translated? It must be, right? Why then won't the current translation system work if I make the aforementioned change to the string?
DeepSOIC
Posts: 6185
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: How to have bullet points in an error message?

Postby DeepSOIC » Sun Dec 09, 2018 11:45 am

NormandC wrote:
Sat Dec 08, 2018 8:57 pm
How is the existing string currently translated?
I don't quite know all the details, but the overall mechanism is:
1. a Qt tool ("lupdate"?) sweeps the source code, searching for translate("somethingsomething") and QT_TR_NOOP("somethingsomething"). It creates a .ts file with all the strings, along with some additional information (context).

2. translators add translations of the strings to the .ts file.
3. when FreeCAD is built, the .ts file with translations is packed into FreeCAD. In the calls to translate("somethingsomething"), the string "somethingsomething" is looked up in the packed .ts file, and the translated string is returned. (and afaik, the .ts file is converted into a binary database for faster lookup)