From: Ian Jackson Date: Sat, 29 Sep 2018 00:20:17 +0000 (+0100) Subject: i18n: Source-level framework: call setlocale, provide __ and ___ X-Git-Tag: archive/debian/7.0_pre1~78 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=commitdiff_plain;h=76876bd5a95c3ce1ff6ccf3f633a6cce6fa4e5b2 i18n: Source-level framework: call setlocale, provide __ and ___ 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 --- diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm index 91d4c711..6642917a 100644 --- a/Debian/Dgit.pm +++ b/Debian/Dgit.pm @@ -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 index 00000000..c6f9e166 --- /dev/null +++ b/Debian/Dgit/I18n.pm @@ -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; diff --git a/Makefile b/Makefile index 934ead1d..3215fec3 100644 --- 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 diff --git a/debian/control b/debian/control index 5bc2a65e..e9afddcf 100644 --- a/debian/control +++ b/debian/control @@ -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 ea74cad7..6a3c4da6 100755 --- 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(); diff --git a/git-debrebase b/git-debrebase index 3d1f2a81..0ef1077f 100755 --- a/git-debrebase +++ b/git-debrebase @@ -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,