We are humans and we make typos. So there are typos in our code.
The two common places for typos are documentation and the user interface.
Documentation is normally only provided in a single language and it are large text files, so spell checking is relatively easy. Django documentation is often build with Sphinx. For that, there is a sphinx extension: sphinxcontrib-spelling. You can even integrate it in your CI as a post-build check.
There will be words that are correct for your project but that aren’t in the regular dictionary: for that there’s a local “wordlist” you can use.
But there is a solution! Translations. Once your project gets bigger, you
probably want to start translating it. Once you have set up your translation
mechanism (gettext), you have all your strings gathered into one place: the
.po files. Hurray, now we can do spell checking.
Gettext is the standard mechanism in Django to deal with translations. You’ll
see lines like
from ... import ugettext as _ in your code.
He wrote a tool for it: potypo. polib +
pyenchant = potypo. Polib can read and write the “gettext”
files. pyenchant is an interface to libenchant.
You’re probably familiar with ispell or aspell (an ispell that fits better to unicode). myspell is openenoffice’s spellchecker, hunspell is a variant on this. For English, “aspell” is probably best, for other languages “hunspell”. Libenchant is a library that wraps them all. And pyenchant provides a python apy to libenchant.
When you start using it, you’ll have to install language packages like
aspell-en. Then add a bit of configuration and
potypo can start check your spelling. If desired, it can fail your build in
CI. You can also switch that off for specific languages (for instance if
you’ve just started translating).
Wordlists? You have multiple languages, so wordlists can be in a
wordlists/de.txt. You can also put just a
wordlist.txt inside the translations’
The “pytypo” project is quite new, but it is already used in several projects. Ideas, features, pull requests: everything is welcome!
Photo explanation: constructing a viaduct module (which spans a 2m staircase) for my model railway on my attic.