Never use t function in a global context!

We were struggling with performance issues on a client's site for some time now. We pinned down the real cause today. It was hidden very well as a bug in the Advanced User module.

I'm writing this down here since I'll probably make the same mistake myself sooner or later:

"Usage of t() in a global context, such as define(‘CONST’, t(‘...’)). The locale system is not yet initialized at that time, so this usage is incorrect and also leads to nasty performance problems. Never do it."

I got this quote from Gábor Hojtsy's Drupal 6 Translation Cheat Sheet.

Written on October 13, 2008 at 19:18, tagged as Drupal, module development, things you might have overlooked

Comments

And yes, I didn't know about that one at StuBru, but I remember all the node access trouble as it was yesterday :)

I think it can be gracefully solved http://drupal.org/node/320686 so unaware users don't have this again.

You probably started working a VRT after that, but we fixed a simular bug in stubru a few weeks after the release. ...with some help of Gabor...
(I think it was in the location views module)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

About

drupalcoder.com is a blog on all things Drupal in specific and LAMP on OS X in general. It is maintained by Davy Van Den Bremt, a Belgian (Drupal) web developer and designer living in Ghent. The goal of this blog is to log all interesting things that have crossed the writer's path while developing Drupal sites. You can read all about Davy's professional activities on his LinkedIn profile. If you want to get in touch, use the contact form.