Skip to main content

Warns about incorrect gettext usage.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8-i18n-0.1.0.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file flake8-i18n-0.1.0.tar.gz.

File metadata

  • Download URL: flake8-i18n-0.1.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for flake8-i18n-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6f17e780cb302b8532558d71abf0c99ca5fcc8df3e53ed34c74f0066404d466b
MD5 5a5bfae195f42dc28dc9628cd653bb91
BLAKE2b-256 44948120dfcc8b94c1926c82aa6f36aebcef92a827434bd073f0f1c6c5fe0213

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page