From 2db87101fc3b221b1c015e763d80ee82681d8753 Mon Sep 17 00:00:00 2001 From: Vasco Almeida Date: Wed, 14 Dec 2016 11:54:24 -0100 Subject: Git.pm: add subroutines for commenting lines Add subroutines prefix_lines and comment_lines. Signed-off-by: Vasco Almeida Signed-off-by: Junio C Hamano --- perl/Git.pm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index ce7e4e8da..f699fee9a 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -1421,6 +1421,44 @@ sub END { } # %TEMP_* Lexical Context +=item prefix_lines ( PREFIX, STRING [, STRING... ]) + +Prefixes lines in C with C. + +=cut + +sub prefix_lines { + my $prefix = shift; + my $string = join("\n", @_); + $string =~ s/^/$prefix/mg; + return $string; +} + +=item get_comment_line_char ( ) + +Gets the core.commentchar configuration value. +The value falls-back to '#' if core.commentchar is set to 'auto'. + +=cut + +sub get_comment_line_char { + my $comment_line_char = config("core.commentchar") || '#'; + $comment_line_char = '#' if ($comment_line_char eq 'auto'); + $comment_line_char = '#' if (length($comment_line_char) != 1); + return $comment_line_char; +} + +=item comment_lines ( STRING [, STRING... ]) + +Comments lines following core.commentchar configuration. + +=cut + +sub comment_lines { + my $comment_line_char = get_comment_line_char; + return prefix_lines("$comment_line_char ", @_); +} + =back =head1 ERROR HANDLING -- cgit v1.2.1 From c4a85c3b8eef8c3b37f5103870e82894d9e5e7d0 Mon Sep 17 00:00:00 2001 From: Vasco Almeida Date: Wed, 14 Dec 2016 11:54:29 -0100 Subject: i18n: add--interactive: mark plural strings Mark plural strings for translation. Unfold each action case in one entire sentence. Pass new keyword for xgettext to extract. Update test to include new subroutine __n() for plural strings handling. Update documentation to include a description of the new __n() subroutine. Signed-off-by: Vasco Almeida Signed-off-by: Junio C Hamano --- perl/Git/I18N.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'perl') diff --git a/perl/Git/I18N.pm b/perl/Git/I18N.pm index f889fd6da..617d8c2a1 100644 --- a/perl/Git/I18N.pm +++ b/perl/Git/I18N.pm @@ -13,7 +13,7 @@ BEGIN { } } -our @EXPORT = qw(__); +our @EXPORT = qw(__ __n); our @EXPORT_OK = @EXPORT; sub __bootstrap_locale_messages { @@ -44,6 +44,7 @@ BEGIN eval { __bootstrap_locale_messages(); *__ = \&Locale::Messages::gettext; + *__n = \&Locale::Messages::ngettext; 1; } or do { # Tell test.pl that we couldn't load the gettext library. @@ -51,6 +52,7 @@ BEGIN # Just a fall-through no-op *__ = sub ($) { $_[0] }; + *__n = sub ($$$) { $_[2] == 1 ? $_[0] : $_[1] }; }; } @@ -70,6 +72,8 @@ Git::I18N - Perl interface to Git's Gettext localizations printf __("The following error occurred: %s\n"), $error; + printf __n("commited %d file\n", "commited %d files\n", $files), $files; + =head1 DESCRIPTION Git's internal Perl interface to gettext via L. If @@ -87,6 +91,10 @@ it. L's gettext function if all goes well, otherwise our passthrough fallback function. +=head2 __n($$$) + +L's ngettext function or passthrough fallback function. + =head1 AUTHOR Evar ArnfjErE Bjarmason -- cgit v1.2.1 From 0539d5e6d535760a99694ff5d5592e46ed929d15 Mon Sep 17 00:00:00 2001 From: Vasco Almeida Date: Wed, 14 Dec 2016 11:54:30 -0100 Subject: i18n: add--interactive: mark patch prompt for translation Mark prompt message assembled in place for translation, unfolding each use case for each entry in the %patch_modes hash table. Previously, this script relied on whether $patch_mode was set to run the command patch_update_cmd() or show status and loop the main loop. Now, it uses $cmd to indicate we must run patch_update_cmd() and $patch_mode is used to tell which flavor of the %patch_modes are we on. This is introduced in order to be able to mark and unfold the message prompt knowing in which context we are. The tracking of context was done previously by point %patch_mode_flavour hash table to the correct entry of %patch_modes, focusing only on value of %patch_modes. Now, we are also interested in the key ('staged', 'stash', 'checkout_head', ...). Signed-off-by: Vasco Almeida Signed-off-by: Junio C Hamano --- perl/Git/I18N.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'perl') diff --git a/perl/Git/I18N.pm b/perl/Git/I18N.pm index 617d8c2a1..c41425c8d 100644 --- a/perl/Git/I18N.pm +++ b/perl/Git/I18N.pm @@ -13,7 +13,7 @@ BEGIN { } } -our @EXPORT = qw(__ __n); +our @EXPORT = qw(__ __n N__); our @EXPORT_OK = @EXPORT; sub __bootstrap_locale_messages { @@ -54,6 +54,8 @@ BEGIN *__ = sub ($) { $_[0] }; *__n = sub ($$$) { $_[2] == 1 ? $_[0] : $_[1] }; }; + + sub N__($) { return shift; } } 1; @@ -74,6 +76,7 @@ Git::I18N - Perl interface to Git's Gettext localizations printf __n("commited %d file\n", "commited %d files\n", $files), $files; + =head1 DESCRIPTION Git's internal Perl interface to gettext via L. If @@ -95,6 +98,12 @@ passthrough fallback function. L's ngettext function or passthrough fallback function. +=head2 N__($) + +No-operation that only returns its argument. Use this if you want xgettext to +extract the text to the pot template but do not want to trigger retrival of the +translation at run time. + =head1 AUTHOR Evar ArnfjErE Bjarmason -- cgit v1.2.1