Translate strings with HTML tags
-
wrote on 8 Jan 2025, 05:30 last edited by
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>
-
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>
wrote on 8 Jan 2025, 07:52 last edited by@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.
-
@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.
wrote on 8 Jan 2025, 09:00 last edited byThank 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.
-
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>
wrote on 8 Jan 2025, 09:04 last edited by@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
? -
@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
?wrote on 8 Jan 2025, 09:11 last edited by@IgKh
I was initially using lupdate, but didn't since last few translations.And I understood my mistake, the context has to be the class emitting the signal, not the one containing the slot.
-
1/5