-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative translation method in Python #81
Comments
I have added translation support to some external WB, previously using the tools from Qt5 there were problems: using I have just made a test with I think continuing to use the functions from translate = FreeCAD.Qt.translate
QT_TRANSLATE_NOOP = FreeCAD.Qt.QT_TRANSLATE_NOOP |
Strange 🤔 - I have never had problems with generating translation in Qt5. As I remember, the context is extracted only when Also, I found another limitation of this approach - a class inheritance. When you define string on class Base(QObject):
def m1(self):
return self.tr("tr text")
class Inherited(Base):
pass
inh = Inherited()
inh.m1() # returns untranslated text
# this is because, the context for `tr` method is now `Inherited` and we created transaltion with context named `Base` Both limitations may be fixed using some python inspections (I have code that was tested with all possible combinations). |
I made this change but not translations was done, the string is properly attached to its class as context though, do you a a simple working example? What is the main advantage of using In terms of translation functions I would like to have |
Your code @hasecilu, probably does not work, because I created repository with Qt translation example: https://github.com/ostr00000/tr-example - you can analyze there some tricks I discovered over the years. In your example, you are using inheritance, so you will have probably problems in |
In this markdown:
DevelopersHandbook/technical/translation.md
Lines 109 to 115 in 245f3d3
I only see Qt translation by function, but it is possible to translate using
tr
method fromQObject
.In my opinion, this is a much better option (especially when object-oriented style is used).
Actually
lupdate
do not care about parent class, so it should be even possible to implement a custom method:Should this translation pattern be encouraged? Or there are reasons why this is not mentioned here?
(There are problems with subclassing, but I know a workaround for this.)
This is a very frustrating error:
DevelopersHandbook/technical/translation.md
Line 127 in 245f3d3
It is so frustrating that I created a flake8 plugin to detect these errors. Can I advertise this flake8 plugin/pre-commit check here?
The text was updated successfully, but these errors were encountered: