Details
-
Bug
-
Resolution: Fixed
-
P4: Low
-
1.1.0
-
Ubuntu 11.04 64-bit
-
5054038dd43fbb243e2c44b0a9aad35181b043b1 (pyside/tqtc-pyside-setup/5.15) 5c9d4986cdc6ebf63efa0e94430798c81c2dff3e (pyside/pyside-setup/6.1) c61141d43fd6e56a52449cbfe6cc13d07f9156bb (pyside/pyside-setup/6.2)
Description
Perhaps this is a feature request rather than a bug, but I expected this to work. Strings are not translated if the runtime type of the object is not the same as the type in which the string appears. The simple test case attached illustrates the issue. Run
lrelease hu_HU.ts python ./example.py
Note that the source text is used, rather than the translation provided in the attached TS file.
As a workaround, I currently use the following method:
def tr(self, msg, arg2=None, arg3=None): """ @brief Reimplement Qt's tr() function so translations can be found for strings defined in a base class, but displayed by an instance of a derived class. @param msg The sourceText to translate. @param arg2 The optional disambiguation text, or a comment to the translator. @param arg3 The optional number to use for determining a plural form of the translation. """ # The import is here just to keep all aspects of this hack inside the # function. We need the name of the calling function in order to # determine which superclass actually implements it. import inspect caller = inspect.stack()[1][3] context = None for klass in self.__class__.mro(): if caller in klass.__dict__: context = klass.__name__ break # Call the application translation function. There doesn't seem to be # a way to pass the context string to QObject's tr(); it is always # extracted from the name of self's type. The QCoreApplication # translate() adds an extra argument, and I don't trust the PySide # docs' specification of default arguments, so I'm being very explicit # in passing only the arguments passed to this function. qApp = QCoreApplication.instance() if arg3: return qApp.translate ( context, msg, arg2, n=arg3 ) elif arg2: return qApp.translate ( context, msg, arg2 ) else: return qApp.translate ( context, msg )
Attachments
Issue Links
- resulted in
-
PYSIDE-1252 Add Python support in lupdate
- Closed