How one becomes lazy (when one is being translated by Django)

I’ve enjoyed digging even deeper into the lazy text questions that I came up with last time. The “thingamajig” returned by ugettext_lazy indeed waits until unicode is called upon it, then it runs through translation.

You can see this by the way ugettext_lazy is defined. It’s in core/utils/translation/__init__.py:

core/utils/translation/__init__.py
  1. ugettext_lazy = lazy(ugettext, unicode)

That call to lazy produces a bit of functional programming magic (see core/utils/functional.py for the def lazy) that results in ugettest_lazy calling ugettext (the standard translation function) whenever its unicode value is requested (i.e., every time it’s used as a string.)

Fancy stuff, to my little brain anyway.



Comments

No comments yet.

Add Yours

  • Author Avatar

    YOU


Comment Arrow



About Author

admin

Bill Dawson is an American citizen who, having married an Austrian, lives and works in Vienna, Austria. A programmer by trade, he studied history as an undergraduate at the University of California, Berkeley.