Skip to content
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

Open
ostr00000 opened this issue Nov 28, 2023 · 0 comments
Open

Alternative translation method in Python #81

ostr00000 opened this issue Nov 28, 2023 · 0 comments

Comments

@ostr00000
Copy link
Contributor

  1. In this markdown:

    ### Python
    In your Python code, import FreeCAD, then create a function called `translate` with the following code:
    ```python
    translate = FreeCAD.Qt.translate
    ```

    I only see Qt translation by function, but it is possible to translate using tr method from QObject.
    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:

    class MyGreatClassAlsoExpandingAnotherClassSoItHasALongName:
        def tr(self, text: str) -> str:
            return translate('MyGreatClassAlsoExpandingAnotherClassSoItHasALongName', text)
    	def runTr(self):
    		print(self.tr("My transalted text"))

    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.)

  2. This is a very frustrating error:

    print(translate("MyMod", f"This won't {work}")) # NO!

    It is so frustrating that I created a flake8 plugin to detect these errors. Can I advertise this flake8 plugin/pre-commit check here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant