Some fun with Python

Yesterday I for some reason decided to have some fun with Python by writing a simple script to Find Dead Translation keys in MediaWiki extensions. The resulting script, titled FDT, can be found on GitHub, and is licenced under the GNU GPL v3+ (yes, the later probably comes as a shock to you!).

FDT (Find/Fix Dead Translations) script running on my laptop for the Maps MediaWiki extension

What is does, and how

The script works by first obtaining a list of defined language keys from the specified i18n file (which is done via an evil PHP subprocess, to avoid messy parsing of array keys), and then looping over all php files in the directory (recursively ofc) to check if they contain any of the keys, after which a list of not-found keys is returned. If there are not-found keys, the script offers to delete those from the i18n file, which also saves quite some work if they are assigned to for many languages. One important limitation is that the script finds key usage by doing a simple “in string” search on the whole contents of each file, which obviously will miss dynamically constructed strings. An example of the work this script did (for Semantic Maps) can be found in this commit.

Some more points of interest

This was a nice little exercise in Python for me, making me more familiar with the language basics, which after several similar small projects, I now think I pretty much have mastered. Also fun was that this is the first project I did using Apatana Studio 3, which was released very recently. It’s an Eclipse based IDE aimed at Python and Ruby web development, including excellent support for JavaScript and various JS libraries such as jQuery and Ext. It also has some support for PHP, but that’s a bit meagre compared to Zend Studio or PhpStorm, an IntelliJ based IDE I’ve been trying out lately.

More posts to come

Over the past 2 years I’ve changed my blog posting style from posting casual updates about small stuff like this post, to only posting about new MediaWiki extensions or important updates to existing ones. I’ve decided to reverse this trend and post more lightweight for fun things, as opposed to only big release announcements 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.