--- locale.module[1].bak	2006-12-27 14:12:00.000000000 +0100
+++ locale.module	2007-02-09 23:19:36.446703100 +0100
@@ -166,6 +166,11 @@
 
   // Store database cached translations in a static var.
   if (!isset($locale_t)) {
+    // Detect invalid t() calls outside functions
+    if (!isset($locale)) {
+      _locale_backtrace();
+      return $string;
+    }
     $cache = cache_get("locale:$locale", 'cache');
 
     if (!$cache) {
@@ -413,3 +418,20 @@
   include_once './includes/locale.inc';
   _locale_string_delete($lid);
 }
+
+// Detect invalid t() calls outside functions
+function _locale_backtrace() {
+  static $once;
+  if (isset($once)) {
+    return;
+  }
+  $trace = debug_backtrace();
+  for($i = count($trace) - 1; $i > 0; --$i) {
+    if ($trace[$i]['function'] == 't') {
+      // Cannot use t() here!
+      drupal_set_message('t() called before locale initialized. This is a bug in the following module:<br /><strong>'. $trace[$i]['file'] .'</strong> on line <strong>'. $trace[$i]['line'] .'</strong>', 'error');
+      break;
+    }
+  }
+  $once = true;
+}
