Flake8 i18n plugin
Way too often using gettext in python results in one of the following errors:
_(f”{context_variable}”)
Not only gettext will not work here because fstring interpolation happens before function call, but using gettext tools for collecting translation keys results in:
File “/usr/lib/python3.6/site-packages/babel/messages/extract.py”,
line 480, in extract_python value = eval(code, {‘__builtins__’: {}}, {})
File “<string>”, line 2, in <module> NameError: name ‘context_variable’ is not defined
- Similar cases are
_(“%s” % value)
- and
_(“{}”.format(value))
which will not trigger a collection error, but will still result in an incorrect key name in gettext function call.
This flake8 extensions provides basic checks for the above cases.
Install
Install with pip:
$ pip install flake8-i18n
Configure
Add following into your .flake8 file
- i18nfuncs =
gettext ngettext myfunny_gettext _
- Otherwise the default function name list is
gettext ngettext _
Using string interpolation inside gettext will now result in one of the following:
I001 fstring is resolved before function call
I002 format is resolved before function call
I003 printf is resolved before function call
Requirements
Python 3.6, 3.7
flake8
License
GNU General Public License v2 (GPLv2)
Changelog
0.1.0 (2019-03-02)
Basic implementation
Metadata
Release files for flake8-i18n 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flake8-i18n-0.1.0.tar.gz | 3.4 kB | Without provenance | Details for flake8-i18n-0.1.0.tar.gz |
Release files / flake8-i18n-0.1.0.tar.gz
| Download URL | flake8-i18n-0.1.0.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f17e780cb302b8532558d71abf0c99ca5fcc8df3e53ed34c74f0066404d466b
|
|
BLAKE2b-256 checksum How to use checksums |
44948120dfcc8b94c1926c82aa6f36aebcef92a827434bd073f0f1c6c5fe0213
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
|
Security for flake8-i18n 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.