chiark / gitweb /
i18n: Source-level framework: call setlocale, provide __ and ___
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Sep 2018 00:20:17 +0000 (01:20 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Sep 2018 11:04:52 +0000 (12:04 +0100)
This is the general plumbing for looking up translated messages - the
consumer-side.  No actual messages are flagged for translation yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Debian/Dgit.pm
Debian/Dgit/I18n.pm [new file with mode: 0644]
Makefile
debian/control
dgit
git-debrebase

index 91d4c7111f57dc80a16943714f38fe66850e0dfb..6642917a093d20a952d39e0efd092a5c473da436 100644 (file)
@@ -33,6 +33,7 @@ use File::Path;
 use File::Basename;
 use Dpkg::Control::Hash;
 use Debian::Dgit::ExitStatus;
+use Debian::Dgit::I18n;
 
 BEGIN {
     use Exporter   ();
diff --git a/Debian/Dgit/I18n.pm b/Debian/Dgit/I18n.pm
new file mode 100644 (file)
index 0000000..c6f9e16
--- /dev/null
@@ -0,0 +1,26 @@
+# -*- perl -*-
+
+package Debian::Dgit::I18n;
+
+# This module provides
+#    __       a function which is an alias for gettext
+#    ___      sprintf wrapper that gettexts the format
+#
+# In perl the sub `_' is a `superglobal', which means there
+# is only one of it in the whole program and every reference
+# is to the same one.  So it's not really useable in modules.
+# Hence __.
+
+use Locale::gettext;
+
+BEGIN {
+    use Exporter;
+    @ISA = qw(Exporter);
+    @EXPORT = qw(__ ___);
+}
+
+
+sub __ { gettext @_; }
+sub ___ { my $f = shift @_; sprintf +(gettext $f), @_; }
+
+1;
index 934ead1df719d25634b2e43947d16569f684daf3..3215fec3114d7ee11f48211f7370652ce020bd91 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -45,14 +45,18 @@ MAN7PAGES=dgit.7                            \
        dgit-sponsorship.7
 
 TXTDOCS=README.dsc-import
-PERLMODULES=Debian/Dgit.pm Debian/Dgit/ExitStatus.pm
+PERLMODULES= \
+       Debian/Dgit.pm \
+       Debian/Dgit/ExitStatus.pm \
+       Debian/Dgit/I18n.pm
 ABSURDITIES=git
 
 GDR_PROGRAMS=git-debrebase
 GDR_PERLMODULES= \
        Debian/Dgit.pm \
        Debian/Dgit/GDR.pm \
-       Debian/Dgit/ExitStatus.pm
+       Debian/Dgit/ExitStatus.pm \
+       Debian/Dgit/I18n.pm
 GDR_MAN1PAGES=git-debrebase.1
 GDR_MAN5PAGES=git-debrebase.5
 
index 5bc2a65e4732725e442d111737746912c91e2f73..e9afddcf9c0991b9eadf845c8979bc6cc9be0b8c 100644 (file)
@@ -11,6 +11,7 @@ Vcs-Browser: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git/dgit.git/
 Package: dgit
 Depends: perl, libwww-perl, libdpkg-perl, git-core, devscripts, dpkg-dev,
          ${misc:Depends}, git-buildpackage, liblist-moreutils-perl,
+         liblocale-gettext-perl,
          coreutils (>= 8.23-1~),
          libdigest-sha-perl, dput, curl, apt,
          libjson-perl, ca-certificates,
@@ -28,6 +29,7 @@ Description: git interoperability with the Debian archive
 
 Package: git-debrebase
 Depends: perl, git-core, libdpkg-perl, libfile-fnmatch-perl, devscripts,
+         liblocale-gettext-perl,
          ${misc:Depends}
 Recommends: dgit, git-buildpackage
 Architecture: all
@@ -38,7 +40,8 @@ Description: rebasing git workflow tool for Debian packaging
 Package: dgit-infrastructure
 Depends: ${misc:Depends}, perl, git-core, gpgv, chiark-utils-bin,
          libjson-perl, libdigest-sha-perl, libdbd-sqlite3-perl, sqlite3,
-         libwww-perl, libdpkg-perl
+         libwww-perl, libdpkg-perl,
+         liblocale-gettext-perl
 Recommends: dgit
 Architecture: all
 Priority: extra
diff --git a/dgit b/dgit
index ea74cad71b04284b045a8d5a3e74641425e8335d..6a3c4da6cf7c0a22f0c71f29c3ea6d5b8c1d62eb 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -20,6 +20,7 @@
 
 END { $? = $Debian::Dgit::ExitStatus::desired // -1; };
 use Debian::Dgit::ExitStatus;
+use Debian::Dgit::I18n;
 
 use strict;
 
@@ -37,6 +38,7 @@ use Dpkg::Version;
 use Dpkg::Compression;
 use Dpkg::Compression::Process;
 use POSIX;
+use Locale::gettext;
 use IPC::Open2;
 use Digest::SHA;
 use Digest::MD5;
@@ -7208,6 +7210,9 @@ sub parseopts_late_defaults () {
     $bpd_glob =~ s#[][\\{}*?~]#\\$&#g;
 }
 
+setlocale(LC_MESSAGES, "");
+textdomain("dgit");
+
 if ($ENV{$fakeeditorenv}) {
     git_slurp_config();
     quilt_fixup_editor();
index 3d1f2a81bc48bba8dc20dd520435791699ae22eb..0ef1077ff67210c7eb5c3080bc068c3598f949be 100755 (executable)
@@ -21,6 +21,7 @@
 END { $? = $Debian::Dgit::ExitStatus::desired // -1; };
 use Debian::Dgit::GDR;
 use Debian::Dgit::ExitStatus;
+use Debian::Dgit::I18n;
 
 use strict;
 
@@ -30,6 +31,7 @@ setup_sigwarn();
 use Memoize;
 use Carp;
 use POSIX;
+use Locale::gettext;
 use Data::Dumper;
 use Getopt::Long qw(:config posix_default gnu_compat bundling);
 use Dpkg::Version;
@@ -2961,6 +2963,9 @@ sub cmd_downstream_rebase_launder_v0 () {
     }
 }
 
+setlocale(LC_MESSAGES, "");
+textdomain("git-debrebase");
+
 getoptions_main
           ("bad options\n",
           "D+" => \$debuglevel,