[NUUG fiksgatami] [patch] Report problems also when no locale is set

Petter Reinholdtsen pere at hungry.com
Sat Oct 24 14:47:19 CEST 2009


Hi.  I've been working a bit on our fixmystreet version, and ran into
a problem after upgrading to the latest CVS version.  The Locale
variable $gettext seem to be unset, and this made the report_error()
function in Page.pm fail because it uses _() to translate the error
message.  Here is a patch to avoid the problem, by returning the
original text if $gettext is unset.

Index: perllib/mySociety/Locale.pm
===================================================================
RCS file: /repos/mysociety/perllib/mySociety/Locale.pm,v
retrieving revision 1.12
diff -u -r1.12 Locale.pm
--- perllib/mySociety/Locale.pm 10 Sep 2009 12:16:02 -0000      1.12
+++ perllib/mySociety/Locale.pm 24 Oct 2009 12:46:59 -0000
@@ -21,7 +21,12 @@
 # Note, that this function is forced into the main namespace
 # as Perl treats the _ function as magic
 sub _ {
-    return $gettext->get($_[0]);
+    # Avoid perl error when the locale is unset
+    if ($gettext) {
+       return $gettext->get($_[0]);
+    } else {
+       return $_[0];
+    }
 }

 sub nget {

Happy hacking,
-- 
Petter Reinholdtsen


More information about the fiksgatami mailing list