Skip to content

style: Fix all flake8-gettext (INT) errors (INT001, INT002, INT003) #4052

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

Merged
merged 23 commits into from
Sep 14, 2024

Conversation

echoix
Copy link
Member

@echoix echoix commented Jul 14, 2024

This fixes all instances in python files where translated strings are formatted before being fetched by gettext. (underscore function)
Ruff rules:
https://docs.astral.sh/ruff/rules/f-string-in-get-text-func-call/
https://docs.astral.sh/ruff/rules/format-in-get-text-func-call/
https://docs.astral.sh/ruff/rules/printf-in-get-text-func-call/

Some places I changed from percent formatting to dot format in order to use named parameters, to add more context for translators. Unfortunately, it might cause the source string to be different, and I'm not sure of the consequences on Weblate. From this FAQ https://docs.weblate.org/en/latest/faq.html#how-do-i-translate-several-branches-at-once, I understand that they don't really support translating for different branches, so having a source string changed makes it unavailable for backporting (if ever we are doing this). The translation files should be regenerated after this, as they are even out of date currently (merge conflicts when weblate tries to rebase because we use squash merge).

In a small number of cases, where I had added named format parameters, I also changed the strings around so they match the same string, and can be translated as one.

In r.in.wms, I'm pretty sure the variable "format" doesn't exist, and this, since the first commit of that file 12 years ago when it was migrated from an addon. I supposed it meant self.gdal_drv_format, from the context and another translated string near, but it is also possible it meant one of the parameters of the module (that wasn't called correctly if it was the case). Please take a look to confirm my guess.

These were all manual fixes, as no auto-fix was available.

I was committing in batches (also to help reviewing if it's too long in one go), I was planning on having the squash message clean this up.

@echoix echoix added this to the 8.5.0 milestone Jul 14, 2024
@echoix echoix requested a review from ninsbl July 14, 2024 17:20
@github-actions github-actions bot added GUI wxGUI related vector Related to vector data processing raster Related to raster data processing temporal Related to temporal data processing Python Related code is in Python libraries module general display imagery labels Jul 14, 2024
echoix added 8 commits July 14, 2024 17:22
@echoix echoix force-pushed the fix-flake8-gettext-INT branch from 20950c5 to f3e7a4f Compare July 14, 2024 17:23
@echoix
Copy link
Member Author

echoix commented Jul 14, 2024

@neteler Maybe you have an opinion on this too

@neteler
Copy link
Member

neteler commented Jul 14, 2024

Unfortunately, it might cause the source string to be different, and I'm not sure of the consequences on Weblate.

I could imagine that all related existing translations would be changed to "fuzzy". If so, that might be very demotivating for the translators.

What does @HuidaeCho think?

@echoix
Copy link
Member Author

echoix commented Jul 14, 2024

If the translation files are up to date before this PR, there should be a way to undo changes to the source strings, recreate the translation files (I expect no changes), apply back the source string changes (possibly in small batches), recreate the translation files, and manually/with a tool combine back the changes to the translations.

@HuidaeCho
Copy link
Member

HuidaeCho commented Jul 17, 2024

Unfortunately, it might cause the source string to be different, and I'm not sure of the consequences on Weblate.

I could imagine that all related existing translations would be changed to "fuzzy". If so, that might be very demotivating for the translators.

What does @HuidaeCho think?

I'm not sure about that. These strings are still the same, so why would they become fuzzy? Because of line number changes? I'll try it when I get a chance.

@echoix
Copy link
Member Author

echoix commented Jul 17, 2024

Unfortunately, it might cause the source string to be different, and I'm not sure of the consequences on Weblate.

I could imagine that all related existing translations would be changed to "fuzzy". If so, that might be very demotivating for the translators.

What does @HuidaeCho think?

I'm not sure about that. These strings are still the same, so why would they become fuzzy? Because of line number changes? I'll try it when I get a chance.

That's the problem, some were changed just a little (placeholders), but maybe I could revert them.

@echoix
Copy link
Member Author

echoix commented Jul 17, 2024

Also, if you get emails about the status updates of our weblate, it got relocked this morning after a new PR merged...

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
wenzeslaus
wenzeslaus previously approved these changes Sep 13, 2024
@wenzeslaus wenzeslaus removed the request for review from ninsbl September 13, 2024 17:26
@echoix
Copy link
Member Author

echoix commented Sep 13, 2024

@wenzeslaus can you re-approve (or anyone)? I had to resolve a conflict in t.rast.what (a line was removed)

@echoix echoix requested a review from wenzeslaus September 13, 2024 19:21
@echoix echoix merged commit 95da3ef into OSGeo:main Sep 14, 2024
27 checks passed
@echoix echoix deleted the fix-flake8-gettext-INT branch September 14, 2024 14:34
@echoix
Copy link
Member Author

echoix commented Sep 14, 2024

So now, we need to regenerate the template files. Last time it was @HuidaeCho that did it. Is it necessary for it to be a manual job?

Mahesh1998 pushed a commit to Mahesh1998/grass that referenced this pull request Sep 19, 2024
…SGeo#4052)

* style: Fix all flake8-gettext (INT) errors (INT001, INT002, INT003)

Ruff rules:
https://docs.astral.sh/ruff/rules/f-string-in-get-text-func-call/
https://docs.astral.sh/ruff/rules/format-in-get-text-func-call/
https://docs.astral.sh/ruff/rules/printf-in-get-text-func-call/

* Revert source string changes when unneeded.

* Update univar_statistics.py

Co-authored-by: Vaclav Petras <wenzeslaus@gmail.com>

* Update panels.py for Python script type string

* Update pyedit.py to keep path keyword in changed string

* Update univar_statistics.py to make already translated strings match again

* Update pyedit.py

* Update model.py

---------

Co-authored-by: Vaclav Petras <wenzeslaus@gmail.com>
@petrasovaa
Copy link
Contributor

@echoix This breaks WMS, specifically the change in gui/wxpython/web_services/dialogs.py change:

        self.statusbar.SetStatusText(
            _("Connecting to <$s>...") % self.server.GetValue().strip()
        )
Traceback (most recent call last):
  File "/home/anna/dev/grass/grass/dist.x86_64-pc-linux-
gnu/gui/wxpython/web_services/dialogs.py", line 379, in
OnConnect

_("Connecting to <$s>...") % self.server.GetValue().strip()
TypeError
:
not all arguments converted during string formatting

@echoix
Copy link
Member Author

echoix commented Feb 17, 2025

Indeed, I see an unexpected $s instead of %s

@echoix
Copy link
Member Author

echoix commented Feb 17, 2025

Do you mind filing in the PR?

@petrasovaa
Copy link
Contributor

Do you mind filing in the PR?

@arohanajit Can you please do it? Thanks!

@echoix
Copy link
Member Author

echoix commented Feb 17, 2025

Maybe a spot check that $s isn't anywhere else in code strings. I know there's some rules for unused arguments, maybe Pylint, but probably not active yet

echoix added a commit to echoix/grass that referenced this pull request Feb 18, 2025
@echoix
Copy link
Member Author

echoix commented Feb 18, 2025

Do you mind filing in the PR?

@arohanajit Can you please do it? Thanks!

Did it

petrasovaa pushed a commit that referenced this pull request Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display general GUI wxGUI related imagery libraries module Python Related code is in Python raster Related to raster data processing temporal Related to temporal data processing vector Related to vector data processing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants