Jun. 29th, 2009

elfs: (Default)

One thing I see a lot of in professional Django is the importation of ugettext, Django’s internationalization library that leverages the GNU gettext project’s toolkit for generating translation catalogs. Laying the groundwork for translation is important to larger projects intended for universal appeal. Because the underscore is a valid leading character in a function name in both C and Python, it’s also a valid function name in its own right, and gettext recognizes that single function, _(), as the wrapper for a string to be recorded in the translation catalog, and for that string to be the “key” for translations into other languanges.

However, it gets a little old, after a while, typing in the same “import-as” string in module after module. So I decided, to heck with it, I’m just going to make the gettext function (or in Django’s case, ugettext) absolutely everywhere:

<__init.py__>=
from django.utils.translation import ugettext
import __builtin__
__builtin__.__dict__['_'] = ugettext

Put this into the __init.py__ file in the root of your project (the same directory level as urls.py and settings.py) and this installs _() as a global reference into the current running python VM, and now it’s as universally available as int(), map(), or str().

This is, of course, controversial.  Modifying the python global namespace to add a function can be considered maintenance-hostile.  But the gettext feature is so universal– at least to me– that __init__.py is where it belongs.

This entry was automatically cross-posted from Elf's technical journal, ElfSternberg.com
elfs: (Default)
Why is there a gross food movement? Isn't the existence of McDonald's enough?
elfs: (Default)
I had two job interviews today. The first was with an advertising agency that is putting together a very rapid development site for one of their clients, and needs someone who can write Django fast enough to wrangle together all of the details of of a couple of inbound feeds into displayable objects. It's all back-end stuff, no GIMP-Fu needed sad to say, but it's definitely among the high-water of the kinds of development I do well and would like to be doing. And they seemed to like me.

The other interview-- not so much. Although I read the job description and it seemed to say "Web Developer Wanted," and they read my resume which screames web developer and thought I was a good fit for the role, what they really wanted was a marketer and marketing manager who specialized in search engine optimization and cross-site promotion, rather than a Rails developer.

Funny story: I've already worked for this guy. In 1993. I was temping at the time, and he needed a bunch of data entry people for an emergency calculation over a fraud case they were tracking. Very strange.

I got home and there was a box on the doorstep! I took it inside and eagerly anticipated assembling my new fan into my old laptop-- only to see, after it was open, that this was the replacement paring knife from OXO for the one we'd broken a few weeks ago. Ah, well.

And now I am completely exhausted. I'm going to take a nap.

Profile

elfs: (Default)
Elf Sternberg

May 2025

S M T W T F S
    123
45678910
111213141516 17
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 28th, 2025 09:31 pm
Powered by Dreamwidth Studios