summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki.pm32
-rw-r--r--debian/changelog2
-rwxr-xr-xt/basewiki_brokenlinks.t2
-rwxr-xr-xt/permalink.t2
4 files changed, 24 insertions, 14 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index d7c827c89..a0a61ac64 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -14,7 +14,7 @@ use open qw{:utf8 :std};
use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
%pagestate %wikistate %renderedfiles %oldrenderedfiles
%pagesources %destsources %depends %hooks %forcerebuild
- $gettext_obj %loaded_plugins};
+ %loaded_plugins};
use Exporter q{import};
our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
@@ -459,7 +459,7 @@ sub checkconfig () {
if (defined $config{locale}) {
if (POSIX::setlocale(&POSIX::LC_ALL, $config{locale})) {
$ENV{LANG}=$config{locale};
- $gettext_obj=undef;
+ define_gettext();
}
}
@@ -1704,29 +1704,37 @@ sub file_pruned ($$) {
return $file =~ m/$regexp/ && $file ne $base;
}
-sub gettext {
- # Only use gettext in the rare cases it's needed.
+sub define_gettext () {
+ # If translation is needed, redefine the gettext function to do it.
+ # Otherwise, it becomes a quick no-op.
+ no warnings 'redefine';
if ((exists $ENV{LANG} && length $ENV{LANG}) ||
(exists $ENV{LC_ALL} && length $ENV{LC_ALL}) ||
(exists $ENV{LC_MESSAGES} && length $ENV{LC_MESSAGES})) {
- if (! $gettext_obj) {
- $gettext_obj=eval q{
+ *gettext=sub {
+ my $gettext_obj=eval q{
use Locale::gettext q{textdomain};
Locale::gettext->domain('ikiwiki')
};
- if ($@) {
- print STDERR "$@";
- $gettext_obj=undef;
+
+ if ($gettext_obj) {
+ $gettext_obj->get(shift);
+ }
+ else {
return shift;
}
- }
- return $gettext_obj->get(shift);
+ };
}
else {
- return shift;
+ *gettext=sub { return shift };
}
}
+sub gettext {
+ define_gettext();
+ gettext(@_);
+}
+
sub yesno ($) {
my $val=shift;
diff --git a/debian/changelog b/debian/changelog
index 7f8257813..126c1826b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -18,6 +18,8 @@ ikiwiki (3.15) UNRELEASED; urgency=low
name, to support several cases including mercurial's long user
names on the RecentChanges page, and urls with spaces being handled
by the 404 plugin.
+ * Optimise use of gettext, and avoid ugly warnings if Locale::gettext
+ is not available. Closes: #532285
-- Joey Hess <joeyh@debian.org> Tue, 02 Jun 2009 17:03:41 -0400
diff --git a/t/basewiki_brokenlinks.t b/t/basewiki_brokenlinks.t
index 2871b1dd2..fd0037492 100755
--- a/t/basewiki_brokenlinks.t
+++ b/t/basewiki_brokenlinks.t
@@ -8,7 +8,7 @@ ok(! system("make -s ikiwiki.out"));
ok(! system("make extra_install DESTDIR=`pwd`/t/tmp/install PREFIX=/usr >/dev/null"));
foreach my $plugin ("", "listdirectives") {
- ok(! system("LC_ALL=C perl -I. ./ikiwiki.out -rebuild -plugin brokenlinks ".
+ ok(! system("perl -I. ./ikiwiki.out -rebuild -plugin brokenlinks ".
# always enabled because pages link to it conditionally,
# which brokenlinks cannot handle properly
"-plugin smiley ".
diff --git a/t/permalink.t b/t/permalink.t
index c326e8d27..b49b98338 100755
--- a/t/permalink.t
+++ b/t/permalink.t
@@ -5,7 +5,7 @@ use Test::More 'no_plan';
ok(! system("mkdir t/tmp"));
ok(! system("make -s ikiwiki.out"));
-ok(! system("LC_ALL=C perl -I. ./ikiwiki.out -plugin inline -url=http://example.com -cgiurl=http://example.com/ikiwiki.cgi -rss -atom -underlaydir=underlays/basewiki -templatedir=templates t/tinyblog t/tmp/out"));
+ok(! system("perl -I. ./ikiwiki.out -plugin inline -url=http://example.com -cgiurl=http://example.com/ikiwiki.cgi -rss -atom -underlaydir=underlays/basewiki -templatedir=templates t/tinyblog t/tmp/out"));
# This guid should never, ever change, for any reason whatsoever!
my $guid="http://example.com/post/";
ok(length `grep '<guid>$guid</guid>' t/tmp/out/index.rss`);