From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Jeff Epler" <jepler@unpythonic.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH/RFC v2 5/6] gettext: Add a Gettext interface for Perl
Date: Sun, 30 May 2010 20:54:16 +0000 [thread overview]
Message-ID: <1275252857-21593-6-git-send-email-avarab@gmail.com> (raw)
In-Reply-To: <1275173125-21010-1-git-send-email-avarab@gmail.com>
Make Git's gettext messages available to Perl programs through
Locale::Messages. Gracefully fall back to English on systems that
don't contain the module.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
Makefile | 4 ++-
git-send-email.perl | 3 +-
perl/Git/Gettext.pm | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++
perl/Makefile.PL | 5 ++-
4 files changed, 92 insertions(+), 3 deletions(-)
create mode 100644 perl/Git/Gettext.pm
diff --git a/Makefile b/Makefile
index dce2faa..2101713 100644
--- a/Makefile
+++ b/Makefile
@@ -1884,7 +1884,9 @@ cscope:
$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
pot:
- $(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c) $(SCRIPT_SH)
+ $(XGETTEXT) --keyword=_ --output=po/git.pot --language=C $(C_OBJ:o=c)
+ $(XGETTEXT) --join-existing --output=po/git.pot --language=Shell $(SCRIPT_SH)
+ $(XGETTEXT) --join-existing --output=po/git.pot --language=Perl $(SCRIPT_PERL)
POFILES := $(wildcard po/*.po)
MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
diff --git a/git-send-email.perl b/git-send-email.perl
index 111c981..a36718e 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -26,6 +26,7 @@ use Term::ANSIColor;
use File::Temp qw/ tempdir tempfile /;
use Error qw(:try);
use Git;
+use Git::Gettext qw< :all >;
Getopt::Long::Configure qw/ pass_through /;
@@ -674,7 +675,7 @@ if (!defined $sender) {
$sender = $repoauthor || $repocommitter || '';
$sender = ask("Who should the emails appear to be from? [$sender] ",
default => $sender);
- print "Emails will be sent from: ", $sender, "\n";
+ printf gettext("Emails will be sent from: %s\n"), $sender;
$prompting++;
}
diff --git a/perl/Git/Gettext.pm b/perl/Git/Gettext.pm
new file mode 100644
index 0000000..f434783
--- /dev/null
+++ b/perl/Git/Gettext.pm
@@ -0,0 +1,83 @@
+package Git::Gettext;
+use strict;
+use warnings;
+use Exporter;
+use base 'Exporter';
+
+our $VERSION = '0.01';
+
+our @EXPORT;
+our @EXPORT_OK = qw< gettext >;
+our %EXPORT_TAGS;
+@{ $EXPORT_TAGS{'all'} } = @EXPORT_OK;
+
+sub __bootstrap_locale_messages {
+ our $TEXTDOMAIN = 'git';
+
+ # TODO: How do I make the sed replacements in the top level
+ # Makefile reach me here?
+ #our $TEXTDOMAINDIR = q|@@LOCALEDIR@@|;
+ our $TEXTDOMAINDIR = q</usr/local/share/locale>;
+
+ require POSIX;
+ POSIX->import(qw< setlocale >);
+ # Non-core prerequisite module
+ require Locale::Messages;
+ Locale::Messages->import(qw< :locale_h :libintl_h >);
+
+ setlocale(LC_MESSAGES(), '');
+ setlocale(LC_CTYPE(), '');
+ textdomain($TEXTDOMAIN);
+ bindtextdomain($TEXTDOMAIN => $TEXTDOMAINDIR);
+
+ return;
+}
+
+BEGIN
+{
+ local ($@, $!);
+ eval { __bootstrap_locale_messages() };
+ if ($@) {
+ # Oh noes, no Locale::Messages here
+ *gettext = sub ($) { $_[0] };
+ }
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Git::Gettext - Perl interface to Git's Gettext localizations
+
+=head1 DESCRIPTION
+
+Git's internal interface to Gettext via L<Locale::Messages>. If
+L<Locale::Messages> can't be loaded (it's not a core module) we
+provide stub passthrough fallbacks.
+
+=head1 FUNCTIONS
+
+=head2 gettext($)
+
+L<Locale::Messages>'s gettext function if all goes well, otherwise our
+passthrough fallback function.
+
+=head1 EXPORTS
+
+Exports are done via L<Exporter>. Invididual functions can be
+exporter, or all of them via the C<:all> export tag.
+
+=head1 AUTHOR
+
+E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com>
+
+This program is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
diff --git a/perl/Makefile.PL b/perl/Makefile.PL
index 0b9deca..702ec7c 100644
--- a/perl/Makefile.PL
+++ b/perl/Makefile.PL
@@ -16,7 +16,10 @@ endif
MAKE_FRAG
}
-my %pm = ('Git.pm' => '$(INST_LIBDIR)/Git.pm');
+my %pm = (
+ 'Git.pm' => '$(INST_LIBDIR)/Git.pm',
+ 'Git/Gettext.pm' => '$(INST_LIBDIR)/Git/Gettext.pm',
+);
# We come with our own bundled Error.pm. It's not in the set of default
# Perl modules so install it if it's not available on the system yet.
--
1.7.1.248.gcd6d1
next prev parent reply other threads:[~2010-05-30 20:55 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-29 22:45 [PATCH/RFC 0/5] Add internationalization support to Git Ævar Arnfjörð Bjarmason
2010-05-29 22:45 ` [PATCH 1/5] Add infrastructure for translating Git with gettext Ævar Arnfjörð Bjarmason
2010-05-29 22:45 ` [PATCH 2/5] gitignore: Ignore files generated by gettext Ævar Arnfjörð Bjarmason
2010-05-29 22:45 ` [PATCH 3/5] Makefile: Remove Gettext files on make clean Ævar Arnfjörð Bjarmason
2010-05-29 22:45 ` [PATCH 4/5] gettext: Add a skeleton po/is.po Ævar Arnfjörð Bjarmason
2010-05-29 22:45 ` [PATCH 5/5] Add infrastructure to make shellscripts translatable Ævar Arnfjörð Bjarmason
2010-05-30 1:46 ` [PATCH/RFC 0/5] Add internationalization support to Git Jonathan Nieder
2010-05-30 16:04 ` Ævar Arnfjörð Bjarmason
2010-05-30 22:23 ` Jonathan Nieder
2010-05-31 12:17 ` Ævar Arnfjörð Bjarmason
2010-05-30 20:54 ` [PATCH/RFC v2 0/6] " Ævar Arnfjörð Bjarmason
2010-05-30 20:54 ` [PATCH/RFC v2 1/6] Add infrastructure for translating Git with gettext Ævar Arnfjörð Bjarmason
2010-06-01 17:01 ` Jakub Narebski
2010-06-01 18:11 ` [PATCH/RCF] autoconf: Check if <libintl.h> exists and set NO_GETTEXT Ævar Arnfjörð Bjarmason
2010-06-01 21:22 ` Jakub Narebski
2010-05-30 20:54 ` [PATCH/RFC v2 2/6] gitignore: Ignore files generated by gettext Ævar Arnfjörð Bjarmason
2010-05-30 20:54 ` [PATCH/RFC v2 3/6] Makefile: Remove Gettext files on make clean Ævar Arnfjörð Bjarmason
2010-05-30 20:54 ` [PATCH/RFC v2 4/6] gettext: Add a Gettext interface for shell scripts Ævar Arnfjörð Bjarmason
2010-05-30 20:54 ` Ævar Arnfjörð Bjarmason [this message]
2010-06-01 17:00 ` [PATCH/RFC v2 5/6] gettext: Add a Gettext interface for Perl Jakub Narebski
2010-06-01 19:06 ` Ævar Arnfjörð Bjarmason
2010-06-02 11:47 ` Jakub Narebski
2010-05-30 20:54 ` [PATCH/RFC v2 6/6] gettext: Add a skeleton po/is.po Ævar Arnfjörð Bjarmason
2010-05-30 21:29 ` Jonathan Nieder
2010-05-30 21:39 ` Jonathan Nieder
2010-05-31 14:17 ` Ævar Arnfjörð Bjarmason
2010-06-01 23:39 ` [PATCH/RFC v3 0/7] Add internationalization support to Git Ævar Arnfjörð Bjarmason
2010-06-02 0:11 ` Ævar Arnfjörð Bjarmason
2010-06-02 1:05 ` [PATCH/RFC v4 " Ævar Arnfjörð Bjarmason
2010-06-02 1:05 ` [PATCH/RFC v4 1/7] Add infrastructure for translating Git with gettext Ævar Arnfjörð Bjarmason
2010-06-02 9:12 ` Peter Krefting
2010-06-02 9:29 ` Ævar Arnfjörð Bjarmason
2010-06-02 10:11 ` Peter Krefting
2010-06-02 10:56 ` Ævar Arnfjörð Bjarmason
2010-06-02 11:31 ` Peter Krefting
2010-06-02 1:05 ` [PATCH/RFC v4 2/7] gettext: Add a Gettext interface for shell scripts Ævar Arnfjörð Bjarmason
2010-06-02 1:06 ` [PATCH/RFC v4 3/7] gettext: Add a Gettext interface for Perl Ævar Arnfjörð Bjarmason
2010-06-02 1:06 ` [PATCH/RFC v4 4/7] Makefile: Don't install Gettext .mo files if NO_GETTEXT Ævar Arnfjörð Bjarmason
2010-06-02 1:06 ` [PATCH/RFC v4 5/7] Makefile: Override --keyword= for all languages Ævar Arnfjörð Bjarmason
2010-06-02 1:06 ` [PATCH/RFC v4 6/7] gettext: Sanity tests for Git's Gettext support Ævar Arnfjörð Bjarmason
2010-06-02 1:06 ` [PATCH/RFC v4 7/7] gettext: Add a skeleton po/is.po Ævar Arnfjörð Bjarmason
2010-06-02 6:32 ` [PATCH/RFC v3 0/7] Add internationalization support to Git Johannes Sixt
2010-06-02 22:33 ` [PATCH/RFC v5 0/2] Add infrastructure for translating Git with gettext Ævar Arnfjörð Bjarmason
2010-06-02 22:33 ` [PATCH/RFC v5 1/2] " Ævar Arnfjörð Bjarmason
2010-06-02 22:33 ` [PATCH/RFC v5 2/2] Add initial C, Shell and Perl gettext translations Ævar Arnfjörð Bjarmason
2010-06-01 23:39 ` [PATCH/RFC v3 1/7] Add infrastructure for translating Git with gettext Ævar Arnfjörð Bjarmason
2010-06-01 23:39 ` [PATCH/RFC v3 2/7] gettext: Add a Gettext interface for shell scripts Ævar Arnfjörð Bjarmason
2010-06-02 6:32 ` Johannes Sixt
2010-06-02 8:53 ` Ævar Arnfjörð Bjarmason
2010-06-02 9:38 ` Johannes Sixt
2010-06-01 23:39 ` [PATCH/RFC v3 3/7] gettext: Add a Gettext interface for Perl Ævar Arnfjörð Bjarmason
2010-06-01 23:39 ` [PATCH/RFC v3 4/7] Makefile: Don't install Gettext .mo files if NO_GETTEXT Ævar Arnfjörð Bjarmason
2010-06-01 23:39 ` [PATCH/RFC v3 5/7] Makefile: Override --keyword= for all languages Ævar Arnfjörð Bjarmason
2010-06-01 23:39 ` [PATCH/RFC v3 6/7] gettext: Basic sanity tests for Git's Gettext support Ævar Arnfjörð Bjarmason
2010-06-02 6:32 ` Johannes Sixt
2010-06-01 23:39 ` [PATCH/RFC v3 7/7] gettext: Add a skeleton po/is.po Ævar Arnfjörð Bjarmason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1275252857-21593-6-git-send-email-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=jepler@unpythonic.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).