[Po4a-commits] po4a/lib/Locale/Po4a Common.pm,1.7,1.8

Martin Quinson po4a-devel@lists.alioth.debian.org
Mon, 30 May 2005 07:00:37 +0000


Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory haydn:/tmp/cvs-serv24551/lib/Locale/Po4a

Modified Files:
	Common.pm 
Log Message:
Add a wrapper around Locale::gettext so that things still work (without translating error messages) when the dependency is missing [FG]

Index: Common.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Common.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- Common.pm	21 Mar 2005 10:11:59 -0000	1.7
+++ Common.pm	30 May 2005 07:00:34 -0000	1.8
@@ -24,12 +24,11 @@
 require Exporter;
 use vars qw(@ISA @EXPORT);
 @ISA = qw(Exporter);
-@EXPORT = qw(wrap_msg wrap_mod wrap_ref_mod load_config);
+@EXPORT = qw(wrap_msg wrap_mod wrap_ref_mod textdomain gettext dgettext load_config);
 
 use 5.006;
 use strict;
 use warnings;
-use Locale::gettext;
 use Text::WrapI18N qw(wrap $columns);
 use Term::ReadKey;
 
@@ -51,6 +50,50 @@
 }
 
 =head1 FUNCTIONS
+
+=head2 Wrappers for other modules
+
+=item textdomain($)
+
+This is a wrapper for Locale::gettext's textdomain() so that po4a still
+works if that module is missing. This wrapper also calls
+setlocale(LC_MESSAGES, "") so callers don't depend on the POSIX module either.
+
+=cut
+
+sub textdomain
+{
+    my ($domain)=@_;
+    return eval "use Locale::gettext; use POSIX; setlocale(LC_MESSAGES, ''); textdomain(\$domain)";
+}
+
+=item gettext($)
+
+This is a wrapper for Locale::gettext's gettext() so that things still
+work ok if that module is missing.
+
+=cut
+
+sub gettext
+{
+    my ($str)=@_;
+    my $rc=eval "use Locale::gettext; Locale::gettext::gettext(\$str)";
+    return ($@ ? $str : $rc);
+}
+
+=item dgettext($$)
+
+This is a wrapper for Locale::gettext's dgettext() so that things still
+work ok if that module is missing.
+
+=cut
+
+sub dgettext
+{
+    my ($domain, $str)=@_;
+    my $rc=eval "use Locale::gettext; dgettext(\$domain, \$str)";
+    return ($@ ? $str : $rc);
+}
 
 =head2 Showing output messages