FreeCAD / FreeCAD/DevelopersHandbook

Alternative translation method in Python

Open
#81 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
81
Forks
56
PR merge metrics
No merged PRs in 30d

Description

1. In this markdown:
https://github.com/FreeCAD/DevelopersHandbook/blob/245f3d339187d67716fb6d77c2d4002775ae0549/technical/translation.md?plain=1#L109-L115
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:
```python
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.)

3. This is a very frustrating error:
https://github.com/FreeCAD/DevelopersHandbook/blob/245f3d339187d67716fb6d77c2d4002775ae0549/technical/translation.md?plain=1#L127
It is so frustrating that I created a [flake8 plugin](https://pypi.org/project/flake8-qt-tr/) to detect these errors. Can I advertise this flake8 plugin/pre-commit check here?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.