[Solved] Issue with translation tr("string")
-
wrote on 16 Jun 2014, 09:42 last edited by
Hi
I am successfully using linguist for translating all the labels on buttons for a small app, which works perfectly.
I am now trying to translate some strings by wrapping tr:@DebugShow(tr("IP address of module: ") + GetLocalIP(), DBG_DIRECT, Qt::black, Qt::white);@
DebugShow is a function that uses the given arguments to format as simple html and send to a QPlainTextEdit which works perfect, just not translated.
Linguist does show the string, I translated it, but the translation does not appear.
Any idea?
Thanks
McL -
wrote on 16 Jun 2014, 10:11 last edited by
Hi,
I do not believe you are able to copy the string to each other with the + operator. To use the linquist you need to use .arg option:
@
QString MyString(tr("Your text here: %1).arg(AddedString));
@ -
wrote on 16 Jun 2014, 10:17 last edited by
.. I've rerun lupdate and lrelease many times ..
I've used a QPlainTextEdit because this is the easiest way to have the "latest" 100 (settable with maximumBlockcount) messages stored scrollable in FIFO style in a debugwindows and be able to have colored messages (foreground/background) and further attributes for grouping and showing importance.
IMHO, this works perfect and is a good thing. -
wrote on 16 Jun 2014, 10:24 last edited by
Hi, See my editted last post. use the .arg option for QString.
-
wrote on 16 Jun 2014, 11:50 last edited by
That is not the issue. Concatenate with the + works perfect. The issue is the same with this as well:
@DebugShow(tr("BlaBlaBal"), DBG_DIRECT, Qt::black, Qt::white);@
-
wrote on 16 Jun 2014, 13:21 last edited by
Does only this string not work? Or do all non gui string fail? If so, it would seem to be a install of your translator. Do you set the translator run-time in an menu action? Do you set it before MainWindow is created?
Did you implement a languageEvent handler?? -
wrote on 16 Jun 2014, 13:51 last edited by
Is the translator definitely installed? You have loaded it with the right translation file, and it didn't return any error values?
-
wrote on 16 Jun 2014, 14:04 last edited by
Jeroen,
That was the correct hint.The calls like
@DebugShow(tr("BlaBlaBal"), DBG_DIRECT, Qt::black, Qt::white);@
are in the constructor:@
QMainWindow(parent,Qt::FramelessWindowHint),
ui(new Ui::QTGUI_MainWindow),
video(this),
m_translator(0)
{
ui->setupUi(this);
.....
@as well as being called later from code.
The calls later from code are working. It's just that the translator is not yet active when the MainWindow is created. I'll need to change this .. somehow.From main:
@ MyApplication program(argc, argv);
QDesktopWidget *desk = program.desktop();
QTGUI_MainWindow window;window.setGeometry(desk->availableGeometry());
window.setLanguage("fr_CH");
window.show();return program.exec();@
setLanguage installs (or removes/reinstalls) the Translator.
Thanks so far.
-
wrote on 16 Jun 2014, 14:09 last edited by
In my code, I load the translator at the earliest opportunity; directly after the QApplication is created.
If your code to load the translator is part of the class function setLanguage, that's too late. Load the translator before creating your MainWindow.
-
wrote on 16 Jun 2014, 14:49 last edited by
I've moved it to before the MainWindow is created ... and it now works :-)
Thank you guys!
1/10