Closed luisg123v closed 1 year ago
I like the idea, it can probably be made into a simple hook and may be generic enough to go into something like pre-commit-hooks.
@antonag32 Take into account pre-commit hooks is for the OCA and they don't need this, because they have a bot that updates translation terms automatically from Weblate
Oh, I did not know that, thanks for the heads up. I was thinking about the "official" pre-commit hooks: https://github.com/pre-commit/pre-commit-hooks tho
@luisg123v I made a POC for the hook. Can you test it and see if you like it? You can run it with pre-commit run --all-files
. Here is a sample pre-commit-config.yaml
to use it:
repos:
- repo: https://github.com/antonag32/pre-commit-hooks
rev: 85da0ad6d4636ff7c5a84c55b29a45dd7b3df7f0 # Use the ref you want to point at
hooks:
- id: pretty-format-po
args: []
"--autofix"
can be added to args
for autofixing as well.
cc @moylop260
Hi @antonag32,
I've tested your hook but, unfortunately, it's giving unexpected results.
It's wrapping lines to a wrong widdth.
y checking your code, it seems the problem is you're forcing a default line length when it's not provided. I think you should not, because Odoo doesn't specify one, which means it fallbacks to the default one, which is (according to the documentation) 78 characters.
You could test using this file which is already formatted correctly, so you shouldn't get a lint error using that one.
Regards,
I think this can be closed?
One of the things that developers and reviewers (at least myself) invest most of the time on is to insert translations in the right place, i.e. in the same order Odoo exports them.
Adding translations in the correct order is important because:
To help with the above, I propose:
polib
This will also cause lines to be wrapped to 80 characters, similar as Odoo does. Actually, Odoo internally also uses pure
polib
starting from v13 (seethis and this).A code like the following would do the trick:
Another alternative without using
polib
but without wrapping lines, with pure Python would be:What do you think @moylop260 @antonag32?
CC @edy1192 @montesinose @deivislaya