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
Forum Updated to NodeBB v4.3 + New Features

Translate strings with HTML tags

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 191 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 8 Jan 2025, 05:30 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>
    
    P I 2 Replies Last reply 8 Jan 2025, 07:52
    0
    • S shreya_agrawal
      8 Jan 2025, 05:30

      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>
      
      P Offline
      P Offline
      Pl45m4
      wrote on 8 Jan 2025, 07:52 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 8 Jan 2025, 09:00
      1
      • P Pl45m4
        8 Jan 2025, 07:52

        @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 8 Jan 2025, 09:00 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
          8 Jan 2025, 05:30

          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 8 Jan 2025, 09:04 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 8 Jan 2025, 09:11
          0
          • I IgKh
            8 Jan 2025, 09:04

            @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 8 Jan 2025, 09:11 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 8 Jan 2025, 09:11

            1/5

            8 Jan 2025, 05:30

            • Login

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