-
-
Notifications
You must be signed in to change notification settings - Fork 185
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
Some of the converted strings into fstrings are no longer processed by babel #487
Comments
Hi @iranzo - are you sure this isn't a bug in babel? The conversion here looks correct, do you have a reproducible example of where it isn't? |
Hi @MarcoGorelli see the linked issue in babel python-babel/babel#715 and the comment:
Thanks |
what's the |
Hi Marco, "_()" is usually the function defined for translatting strings, so in your code, you add stuff like: _("This code works") This function is defined from gettext (https://docs.python.org/3/library/gettext.html#localizing-your-application) and the way it works is that from all the strings inside it, it will generate a "pot" file with When you run your code in an Italian environment (LANG=it_IT@UTF-8), the code will try to locate the translation strings inside the folder you defined, usually a This makes that the msgid is searched in that catalog, and the msgstr is returned instead so: Will return on English or unstranslated languages: And so on The strings are grabbed from the python files by using pybabel via:
And that's what causes the traceback in issue 715, when pyupgrade gets fstrings inside that function |
Sounds like Babel doesn't support f-strings, which is a Babel bug, not pyupgrade. But can you use the pyupgrade |
The workaround I'm using is to use instead the {} markers without defined vars that should be good to go, but as the issue arised when using pyupgrade, I raised this here for awareness |
you're misusing translation -- those strings aren't being translated. if anything babel should produce an error for accidentally using string formatting inside of a translation function babel will scan those (incorrectly) as |
I'm using babel via a custom function
_(string,language)
that outputs the translated version.When running pyupgrade over the source files:
It causes babel to segfault as per python-babel/babel#715
I would expect pyupgrade not to touch the code in a way that makes it later fail.
The text was updated successfully, but these errors were encountered: