Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Translate strings with HTML tags

Translate strings with HTML tags

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 369 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shreya_agrawal
    wrote on last edited by
    #1

    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&lt;br/&gt;</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>
    
    Pl45m4P I 2 Replies Last reply
    0
    • S shreya_agrawal

      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&lt;br/&gt;</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>
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @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.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      S 1 Reply Last reply
      1
      • Pl45m4P Pl45m4

        @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.

        S Offline
        S Offline
        shreya_agrawal
        wrote on last edited by
        #3

        @Pl45m4

        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.

        1 Reply Last reply
        0
        • S shreya_agrawal

          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&lt;br/&gt;</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>
          
          I Offline
          I Offline
          IgKh
          wrote on last edited by
          #4

          @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?

          S 1 Reply Last reply
          0
          • I IgKh

            @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?

            S Offline
            S Offline
            shreya_agrawal
            wrote on last edited by
            #5

            @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 Reply Last reply
            1
            • S shreya_agrawal has marked this topic as solved on

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved