Skip to content

Minimise use of HTML tags in GUI texts that will be translated #926

@SlySven

Description

@SlySven

Unfortunately QtLinguist really does not do well with HTML and presents those using it to build translations with the complete text including the mark-up tags. If possible please construct texts with as much as possible of the tags outside of the strings that get presented for translation. E.g. instead of:

pWidget->setToolTip(tr("<html><head /><body><p>This is a long tool-tip that, by "
      "being entered as HTML uses the built-in Qt rendering systems to produce a "
      "word-wrapped rectangular tool-tip near to the cursor as opposed to a single-"
      "line of text across the screen that could extend beyond the edge and be "
      "awkward to read or be hard to determine to what it applies to as the length "
      "prevents the start or end from being near the cursor.</p><p>This is a "
      "separate paragraph to show that some tags will need to be kept."</body>"
      "</html>"));

try using:

pWidget->setToolTip(QLatin1String("<html><head /><body><p>")
      % tr("This is a long tool-tip that, by being entered as HTML uses the built-in "
          "Qt rendering systems to produce a word-wrapped rectangular tool-tip "
          "near to the cursor as opposed to a single-line of text across the screen "
          "that could extend beyond the edge and be awkward to read or be hard "
          "to determine to what it applies to as the length prevents the start or end "
          "from being near the cursor.</p>
          "<p>This is a separate paragraph to show that some tags will need to be kept.")
      % QLatin1String("</p></body></html>"));

Sadly this does not help with large blocks of text in .ui files: the following from within the Designer plugin fairly well represents the text that a translators get shoved at them to copy and edit to the desired target language:
qt_snapshot1

Things can be improved a little with the "Simplify Rich Text" option:
qt_snapshot2

qt_snapshot3

What is NOT obvious is that most of that CSS can be avoided and it is possible to clean up the Source by copying it to an external text editor and dropping in simple <b>...</b>; <i>...</i> and other HTML tags to replace many of the <span style:"XXXX"> entities:
e.g.:
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:10pt; font-weight:600; text-decoration: underline; color:#bc8942;">Stephen Lyons</span><span style=" font-family:'Sans Serif'; font-size:10pt;"> ( </span><span style=" font-family:'Sans Serif'; font-size:10pt; color:#0000ff;">slysven@virginmedia.com</span><span style=" font-family:'Sans Serif'; font-size:10pt;"> ) after joining in 2013, has been poking various bits of the C++ code and GUI with a pointy stick; subsequently trying to patch over some of the holes made/found.</span></p>
Can be replaced by:
<p><span style=" color:#bc8942;"><b><u>Stephen Lyons</u></b></span> ( <span style=" color:#0000ff;">slysven@virginmedia.com</span> ) after joining in 2013, has been poking various bits of the C++ code and GUI with a pointy stick; subsequently trying to patch over some of the holes made/found.</p>
with less explicit control over the font used to render it but that is not necessarily bad as then the "default" one will kick in auto-magically rather than taking the value currently in force in your (the developer's) system and embedding them in the source. Fair enough text in different sizes and styles is harder but the bottom line is that translating this stuff is going to be painful so we want to make the source material as simple as possible...!

Once a block has been done like this it is possible to switch back and forth between the "source" and "rich text" tabs to see the results - but don't edit the text in the "rich text" view else Qt may helpfully restore all the stuff you have just painstaking culled. 😠

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions