Here is a patch to make the Locale::gettext dependency optional. What it
does is implement wrapper functions in Po4a::Common as was discussed in
the previous email.
The gettext() and dgettext() functions call their Locale::gettext
counterpart in an eval and return the string untranslated if that fails.
The textdomain() wrapper works similarly but also make the setlocale()
call which also removes the dependency on POSIX.
Many files are modified by this patch but in fact for most of them the
only change is removing the 'use Locale::gettext' statement. The two
exceptions are Po4a::Common (of course) and Po4a::Po which defines its
own gettext() function and thus must not import the Po4a::Common one
(just like it did not import the Locale::gettext one before).
Changelog:
* msgsearch
po4a
po4a-gettextize
po4a-normalize
po4a-translate
po4a-updatepo
lib/Locale/Po4a/Chooser.pm
lib/Locale/Po4a/Common.pm
lib/Locale/Po4a/Debconf.pm
lib/Locale/Po4a/Html.pm
lib/Locale/Po4a/Man.pm
lib/Locale/Po4a/NewsDebian.pm
lib/Locale/Po4a/Po.pm
lib/Locale/Po4a/Sgml.pm
lib/Locale/Po4a/TeX.pm
lib/Locale/Po4a/TransTractor.pm
lib/Locale/Po4a/Xml.pm
Francois Gouget <fgouget(a)codeweavers.com>
Implement wrappers for textdomain(), gettext() and dgettext() in
Po4a::Common to make the dependency on Locale::gettext optional.
--
Francois Gouget
fgouget(a)codeweavers.com
Index: msgsearch
===================================================================
RCS file: /cvsroot/po4a/po4a/msgsearch,v
retrieving revision 1.6
diff -u -p -r1.6 msgsearch
--- msgsearch 27 Feb 2005 22:56:00 -0000 1.6
+++ msgsearch 28 May 2005 18:12:03 -0000
@@ -143,13 +142,10 @@ use warnings;
use Getopt::Long qw(GetOptions);
use Locale::Po4a::Po;
+use Locale::Po4a::Common;
use Pod::Usage qw(pod2usage);
-use Locale::gettext;
-use POSIX; # Needed for setlocale()
-
-setlocale(LC_MESSAGES, "");
textdomain('po4a');
sub show_version {
Index: po4a
===================================================================
RCS file: /cvsroot/po4a/po4a/po4a,v
retrieving revision 1.28
diff -u -p -r1.28 po4a
--- po4a 24 Apr 2005 01:09:24 -0000 1.28
+++ po4a 28 May 2005 18:12:03 -0000
@@ -201,10 +199,6 @@ use Pod::Usage qw(pod2usage);
use File::Temp;
-use Locale::gettext;
-use POSIX; # Needed for setlocale()
-
-setlocale(LC_MESSAGES, "");
textdomain('po4a');
Index: po4a-gettextize
===================================================================
RCS file: /cvsroot/po4a/po4a/po4a-gettextize,v
retrieving revision 1.31
diff -u -p -r1.31 po4a-gettextize
--- po4a-gettextize 25 May 2005 16:34:06 -0000 1.31
+++ po4a-gettextize 28 May 2005 18:12:04 -0000
@@ -144,10 +142,6 @@ use Locale::Po4a::Common;
use Pod::Usage qw(pod2usage);
-use Locale::gettext;
-use POSIX; # Needed for setlocale()
-
-setlocale(LC_MESSAGES, "");
textdomain('po4a');
Index: po4a-normalize
===================================================================
RCS file: /cvsroot/po4a/po4a/po4a-normalize,v
retrieving revision 1.25
diff -u -p -r1.25 po4a-normalize
--- po4a-normalize 25 May 2005 16:34:06 -0000 1.25
+++ po4a-normalize 28 May 2005 18:12:04 -0000
@@ -95,12 +93,8 @@ use Locale::Po4a::Common;
use Getopt::Long qw(GetOptions);
-use Locale::gettext;
-use POSIX; # Needed for setlocale()
-
use Pod::Usage qw(pod2usage);
-setlocale(LC_MESSAGES, "");
textdomain('po4a');
sub show_version {
Index: po4a-translate
===================================================================
RCS file: /cvsroot/po4a/po4a/po4a-translate,v
retrieving revision 1.37
diff -u -p -r1.37 po4a-translate
--- po4a-translate 25 May 2005 16:34:13 -0000 1.37
+++ po4a-translate 28 May 2005 18:12:04 -0000
@@ -161,10 +159,6 @@ use Locale::Po4a::Common;
use Pod::Usage qw(pod2usage);
use Getopt::Long qw(GetOptions);
-use Locale::gettext;
-use POSIX; # Needed for setlocale()
-
-setlocale(LC_ALL, "");
textdomain("po4a");
sub show_version {
Index: po4a-updatepo
===================================================================
RCS file: /cvsroot/po4a/po4a/po4a-updatepo,v
retrieving revision 1.34
diff -u -p -r1.34 po4a-updatepo
--- po4a-updatepo 25 May 2005 16:34:13 -0000 1.34
+++ po4a-updatepo 28 May 2005 18:12:04 -0000
@@ -125,10 +123,6 @@ use Pod::Usage qw(pod2usage);
use File::Temp;
-use Locale::gettext;
-use POSIX; # Needed for setlocale()
-
-setlocale(LC_MESSAGES, "");
textdomain('po4a');
sub show_version {
Index: lib/Locale/Po4a/Chooser.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Chooser.pm,v
retrieving revision 1.26
diff -u -p -r1.26 Chooser.pm
--- lib/Locale/Po4a/Chooser.pm 25 May 2005 17:08:40 -0000 1.26
+++ lib/Locale/Po4a/Chooser.pm 28 May 2005 18:12:04 -0000
@@ -18,7 +18,6 @@ package Locale::Po4a::Chooser;
use 5.006;
use strict;
use warnings;
-use Locale::gettext;
use Locale::Po4a::Common;
sub new {
Index: lib/Locale/Po4a/Common.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Common.pm,v
retrieving revision 1.7
diff -u -p -r1.7 Common.pm
--- lib/Locale/Po4a/Common.pm 21 Mar 2005 10:11:59 -0000 1.7
+++ lib/Locale/Po4a/Common.pm 28 May 2005 18:12:04 -0000
@@ -24,12 +24,11 @@ package Locale::Po4a::Common;
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 @@ sub min {
}
=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
Index: lib/Locale/Po4a/Debconf.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Debconf.pm,v
retrieving revision 1.3
diff -u -p -r1.3 Debconf.pm
--- lib/Locale/Po4a/Debconf.pm 27 Feb 2005 22:53:52 -0000 1.3
+++ lib/Locale/Po4a/Debconf.pm 28 May 2005 18:12:04 -0000
@@ -68,7 +68,6 @@ use vars qw(@ISA @EXPORT);
use Locale::Po4a::TransTractor;
use Locale::Po4a::Common;
-use Locale::gettext qw(dgettext);
sub initialize {}
Index: lib/Locale/Po4a/Html.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Html.pm,v
retrieving revision 1.10
diff -u -p -r1.10 Html.pm
--- lib/Locale/Po4a/Html.pm 7 Jan 2005 22:50:52 -0000 1.10
+++ lib/Locale/Po4a/Html.pm 28 May 2005 18:12:04 -0000
@@ -51,7 +51,6 @@ use vars qw(@ISA @EXPORT);
@EXPORT = qw(new initialize);
use Locale::Po4a::TransTractor;
-use Locale::gettext qw(gettext);
use strict;
use warnings;
Index: lib/Locale/Po4a/Man.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Man.pm,v
retrieving revision 1.91
diff -u -p -r1.91 Man.pm
--- lib/Locale/Po4a/Man.pm 25 May 2005 14:12:30 -0000 1.91
+++ lib/Locale/Po4a/Man.pm 28 May 2005 18:12:05 -0000
@@ -274,7 +274,6 @@ use strict;
@EXPORT = qw();# new initialize);
use Locale::Po4a::TransTractor;
use Locale::Po4a::Common;
-use Locale::gettext qw(dgettext);
use File::Spec;
use Getopt::Std;
Index: lib/Locale/Po4a/NewsDebian.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/NewsDebian.pm,v
retrieving revision 1.3
diff -u -p -r1.3 NewsDebian.pm
--- lib/Locale/Po4a/NewsDebian.pm 27 Feb 2005 22:53:53 -0000 1.3
+++ lib/Locale/Po4a/NewsDebian.pm 28 May 2005 18:12:05 -0000
@@ -61,7 +61,6 @@ use vars qw(@ISA @EXPORT);
use Locale::Po4a::TransTractor;
use Locale::Po4a::Common;
-use Locale::gettext qw(dgettext);
sub initialize {}
Index: lib/Locale/Po4a/Po.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Po.pm,v
retrieving revision 1.41
diff -u -p -r1.41 Po.pm
--- lib/Locale/Po4a/Po.pm 3 Apr 2005 21:15:22 -0000 1.41
+++ lib/Locale/Po4a/Po.pm 28 May 2005 18:12:06 -0000
@@ -57,7 +57,7 @@ require Exporter;
package Locale::Po4a::Po;
use Locale::Po4a::TransTractor;
-use Locale::Po4a::Common;
+use Locale::Po4a::Common qw(wrap_msg wrap_mod wrap_ref_mod dgettext);
use 5.006;
use strict;
@@ -70,7 +70,6 @@ require Exporter;
@EXPORT = qw(load write gettext);
use Carp qw(croak);
-use Locale::gettext qw(dgettext);
use File::Path; # mkdir before write
use Encode;
Index: lib/Locale/Po4a/Sgml.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Sgml.pm,v
retrieving revision 1.57
diff -u -p -r1.57 Sgml.pm
--- lib/Locale/Po4a/Sgml.pm 25 May 2005 16:55:20 -0000 1.57
+++ lib/Locale/Po4a/Sgml.pm 28 May 2005 18:12:06 -0000
@@ -176,7 +180,6 @@ use vars qw(@ISA @EXPORT);
use Locale::Po4a::TransTractor;
use Locale::Po4a::Common;
-use Locale::gettext qw(dgettext);
eval qq{use SGMLS};
if ($@) {
Index: lib/Locale/Po4a/TeX.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/TeX.pm,v
retrieving revision 1.58
diff -u -p -r1.58 TeX.pm
--- lib/Locale/Po4a/TeX.pm 23 Apr 2005 17:41:34 -0000 1.58
+++ lib/Locale/Po4a/TeX.pm 28 May 2005 18:12:07 -0000
@@ -80,7 +79,6 @@ $VERSION=$Locale::Po4a::TransTractor::VE
use Locale::Po4a::TransTractor;
use Locale::Po4a::Common;
-use Locale::gettext qw(dgettext);
use File::Basename qw(dirname);
use Carp qw(croak);
Index: lib/Locale/Po4a/TransTractor.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/TransTractor.pm,v
retrieving revision 1.66
diff -u -p -r1.66 TransTractor.pm
--- lib/Locale/Po4a/TransTractor.pm 25 May 2005 17:05:05 -0000 1.66
+++ lib/Locale/Po4a/TransTractor.pm 28 May 2005 18:12:08 -0000
@@ -20,7 +20,6 @@ use Carp qw(croak);
use Locale::Po4a::Po;
use Locale::Po4a::Common;
-use Locale::gettext qw(dgettext);
use File::Path; # mkdir before write
use Encode;
Index: lib/Locale/Po4a/Xml.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Xml.pm,v
retrieving revision 1.27
diff -u -p -r1.27 Xml.pm
--- lib/Locale/Po4a/Xml.pm 21 May 2005 15:51:12 -0000 1.27
+++ lib/Locale/Po4a/Xml.pm 28 May 2005 18:12:08 -0000
@@ -59,7 +59,6 @@ use vars qw(@ISA @EXPORT);
use Locale::Po4a::TransTractor;
use Locale::Po4a::Common;
-use Locale::gettext qw(dgettext);
#It will mantain the path from the root tag to the current one
my @path;