Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2925

lupdate does not extract translatable strings inside f-strings

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 6.8.0, 6.8.0.2
    • PySide, Tooling
    • None
    • Windows

    Description

      When running either lupdate or pyside6-lupdate on a Python file, all strings on which self.tr is called (i.e. translatable strings) are extracted into a .ts file. This works fine for plain strings, and strings given as arguments to str.format(), but strings that are inside f-strings are not extracted.

      Here is an example to reproduce:

      Create format_reproduce.py:

      from PySide6.QtCore import QObject
      
      class FormatReproduce(QObject):
          def __init__(self):
              super().__init__()
              self.plain = self.tr("Plain string")
              self.formatted = "<b> {0} </b>".format(self.tr("argument after"))
              self.fstring = f"<b> {self.tr('argument inside')} </b>"
      

      Run either pyside6-lupdate format_reproduce.py -ts format_reproduce.ts or lupdate format_reproduce.py -ts format_reproduce.ts

      Open format_reproduce.ts:

      <?xml version="1.0" encoding="utf-8"?>
      <!DOCTYPE TS>
      <TS version="2.1">
      <context>
          <name>FormatReproduce</name>
          <message>
              <location filename="format_reproduce.py" line="7"/>
              <source>Plain string</source>
              <translation type="unfinished"></translation>
          </message>
          <message>
              <location filename="format_reproduce.py" line="7"/>
              <source>argument after</source>
              <translation type="unfinished"></translation>
          </message>
      </context>
      </TS>
      

      Note how "argument inside" was not extracted.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            andreimiculita andreimiculita
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes