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.