Translate strings with HTML tags
-
This is my string which is being set on a label:
ui->label->setText(tr("Sample Text<br/>"));
This is how I translate it in .ts file:
<message> <source>Sample Text<br/></source> <translation>Sample Translation</translation> </message>
But, the translation is not successful.
I have confirmed that my context is right and that the text is translated on removing the HTML tag.
I also tried with the following two source texts, but it didn't translate:<source>Sample Text<br/></source> <source>Sample Text</source>
-
@shreya_agrawal said in Translate strings with HTML tags:
ui->label->setText(tr("Sample Text<br/>"));
What about
setText(QString(tr("Sample Text") + QString("<br>")));
?
Unless there is a better way.
-
Thank you for your reply !
The text to be set is dynamic in nature. The text is sent via a signal which then calls the slot for setting the text.
I tried this approach too:emit mySignal(tr("Sample Text") + QString("<br/>")) void mySlot(QString text) { ui->label->setText(text); // Also ui->label->setText(tr(text)); }
But, it is still not working.
-
@shreya_agrawal said in Translate strings with HTML tags:
I also tried with the following two source texts, but it didn't translate:
Wait, do you write the .ts file by hand, or do you use
lupdate
? -