Re: [PATCH v2 05/11] i18n: add--interactive: mark message for translation
A Sáb, 01-10-2016 às 19:09 +0200, Jakub Narębski escreveu: > W dniu 26.09.2016 o 01:09, Junio C Hamano pisze: > > Vasco Almeida writes: > > > >> -print colored $prompt_color, > $patch_mode_flavour{VERB}, > >> - ($hunk[$ix]{TYPE} eq 'mode' ? ' mode change' : > >> - $hunk[$ix]{TYPE} eq 'deletion' ? ' deletion' : > >> - ' this hunk'), > >> - $patch_mode_flavour{TARGET}, > >> - " [y,n,q,a,d,/$other,?]? "; > > > > I hate to say this but expanding this single-liner into if/elsif/ > > cascade of uncountable number of arms is simply a disaster. > > Even if we turn this "single"-liner composition of sentence into > interpolation (allowing for reordering of parts in translation), > like > > print colored $prompt_color, __x("{verb} {noun}{maybe_target} > [y,n,q,a,d,/{other},?]? ", > verb => $patch_mode_flavour{VERB}, noun => > $patch_mode_noun{$hunk[$ix]{TYPE}}, > maybe_target => $patch_mode_flavour{TARGET} || "", other => > $other); > > This would of course require N__() on values of hash, somewhere. > > the problem is that the ordering may need to change depending on > verb: "Stage", "Stash", "Unstage", "Apply", "Discard", and/or noun: > "mode change", "deletion", "this hunk", and/or presence and value > of maybe_target: " to index", " from worktree", " from index and > worktree", > " to index and worktree". So it does not work, unfortunately. The plus side is it would be very concise compared to laying every combination as entire sentences. However, if it worked, I think it would be a bit difficult to translate and translators would be prone to commit some mistake somewhere. It may be harder to translate a sentence by its bits than translate it as a whole.
Re: [PATCH v2 05/11] i18n: add--interactive: mark message for translation
W dniu 26.09.2016 o 01:09, Junio C Hamano pisze: > Vasco Almeida writes: > >> -print colored $prompt_color, $patch_mode_flavour{VERB}, >> - ($hunk[$ix]{TYPE} eq 'mode' ? ' mode change' : >> - $hunk[$ix]{TYPE} eq 'deletion' ? ' deletion' : >> - ' this hunk'), >> - $patch_mode_flavour{TARGET}, >> - " [y,n,q,a,d,/$other,?]? "; > > I hate to say this but expanding this single-liner into if/elsif/ > cascade of uncountable number of arms is simply a disaster. Even if we turn this "single"-liner composition of sentence into interpolation (allowing for reordering of parts in translation), like print colored $prompt_color, __x("{verb} {noun}{maybe_target} [y,n,q,a,d,/{other},?]? ", verb => $patch_mode_flavour{VERB}, noun => $patch_mode_noun{$hunk[$ix]{TYPE}}, maybe_target => $patch_mode_flavour{TARGET} || "", other => $other); This would of course require N__() on values of hash, somewhere. the problem is that the ordering may need to change depending on verb: "Stage", "Stash", "Unstage", "Apply", "Discard", and/or noun: "mode change", "deletion", "this hunk", and/or presence and value of maybe_target: " to index", " from worktree", " from index and worktree", " to index and worktree". >> +if ($patch_mode eq 'stage') { >> +if ($hunk[$ix]{TYPE} eq 'mode') { >> + print colored $prompt_color, >> +sprintf(__("Stage mode change [y,n,q,a,d,/%s,?]? >> "), $other); >> +} elsif ($hunk[$ix]{TYPE} eq 'deletion') { >> + print colored $prompt_color, >> +sprintf(__("Stage deletion [y,n,q,a,d,/%s,?]? "), >> $other); >> +} else { >> + print colored $prompt_color, >> +sprintf(__("Stage this hunk [y,n,q,a,d,/%s,?]? "), >> $other); >> +} >> +} elsif ($patch_mode eq 'stash') { >> + ... >> +} >> +} > > I wonder if you can make a simple helper function so that the caller > here can still be a single-liner: > > print_colored $prompt_color, > sprintf(patch_update_prompt_string($patch_mode, > $hunk[$ix]{TYPE}), $other); > > where the patch_update_prompt_string helper function would look up > these messages from a table that is looked up by patch-mode and TYPE > and the run __() on it, or something? Yes, this would be necessary; hide complexity behind helper function. -- Jakub Narębski
Re: [PATCH v2 05/11] i18n: add--interactive: mark message for translation
Vasco Almeida writes: > - print colored $prompt_color, $patch_mode_flavour{VERB}, > - ($hunk[$ix]{TYPE} eq 'mode' ? ' mode change' : > -$hunk[$ix]{TYPE} eq 'deletion' ? ' deletion' : > -' this hunk'), > - $patch_mode_flavour{TARGET}, > - " [y,n,q,a,d,/$other,?]? "; I hate to say this but expanding this single-liner into if/elsif/ cascade of uncountable number of arms is simply a disaster. > + if ($patch_mode eq 'stage') { > + if ($hunk[$ix]{TYPE} eq 'mode') { > + print colored $prompt_color, > + sprintf(__("Stage mode change [y,n,q,a,d,/%s,?]? > "), $other); > + } elsif ($hunk[$ix]{TYPE} eq 'deletion') { > + print colored $prompt_color, > + sprintf(__("Stage deletion [y,n,q,a,d,/%s,?]? "), > $other); > + } else { > + print colored $prompt_color, > + sprintf(__("Stage this hunk [y,n,q,a,d,/%s,?]? "), > $other); > + } > + } elsif ($patch_mode eq 'stash') { > + ... > + } > + } I wonder if you can make a simple helper function so that the caller here can still be a single-liner: print_colored $prompt_color, sprintf(patch_update_prompt_string($patch_mode, $hunk[$ix]{TYPE}), $other); where the patch_update_prompt_string helper function would look up these messages from a table that is looked up by patch-mode and TYPE and the run __() on it, or something?
[PATCH v2 05/11] i18n: add--interactive: mark message for translation
Mark 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 --- git-add--interactive.perl | 91 ++- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 08badfa..5b89b97 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -91,6 +91,7 @@ sub colored { } # command line options +my $cmd; my $patch_mode; my $patch_mode_revision; @@ -171,7 +172,8 @@ my %patch_modes = ( }, ); -my %patch_mode_flavour = %{$patch_modes{stage}}; +$patch_mode = 'stage'; +my %patch_mode_flavour = %{$patch_modes{$patch_mode}}; sub run_cmd_pipe { if ($^O eq 'MSWin32') { @@ -1372,12 +1374,84 @@ sub patch_update_file { for (@{$hunk[$ix]{DISPLAY}}) { print; } - print colored $prompt_color, $patch_mode_flavour{VERB}, - ($hunk[$ix]{TYPE} eq 'mode' ? ' mode change' : - $hunk[$ix]{TYPE} eq 'deletion' ? ' deletion' : - ' this hunk'), - $patch_mode_flavour{TARGET}, - " [y,n,q,a,d,/$other,?]? "; + if ($patch_mode eq 'stage') { + if ($hunk[$ix]{TYPE} eq 'mode') { + print colored $prompt_color, + sprintf(__("Stage mode change [y,n,q,a,d,/%s,?]? "), $other); + } elsif ($hunk[$ix]{TYPE} eq 'deletion') { + print colored $prompt_color, + sprintf(__("Stage deletion [y,n,q,a,d,/%s,?]? "), $other); + } else { + print colored $prompt_color, + sprintf(__("Stage this hunk [y,n,q,a,d,/%s,?]? "), $other); + } + } elsif ($patch_mode eq 'stash') { + if ($hunk[$ix]{TYPE} eq 'mode') { + print colored $prompt_color, + sprintf(__("Stash mode change [y,n,q,a,d,/%s,?]? "), $other); + } elsif ($hunk[$ix]{TYPE} eq 'deletion') { + print colored $prompt_color, + sprintf(__("Stash deletion [y,n,q,a,d,/%s,?]? "), $other); + } else { + print colored $prompt_color, + sprintf(__("Stash this hunk [y,n,q,a,d,/%s,?]? "), $other); + } + } elsif ($patch_mode eq 'reset_head') { + if ($hunk[$ix]{TYPE} eq 'mode') { + print colored $prompt_color, + sprintf(__("Unstage mode change [y,n,q,a,d,/%s,?]? "), $other); + } elsif ($hunk[$ix]{TYPE} eq 'deletion') { + print colored $prompt_color, + sprintf(__("Unstage deletion [y,n,q,a,d,/%s,?]? "), $other); + } else { + print colored $prompt_color, + sprintf(__("Unstage this hunk [y,n,q,a,d,/%s,?]? "), $other); + } + } elsif ($patch_mode eq 'reset_nothead') { + if ($hunk[$ix]{TYPE} eq 'mode') { + print colored $prompt_color, + sprintf(__("Apply mode change to index [y,n,q,a,d,/%s,?]? "), $other); + } elsif ($hunk[$ix]{TYPE} eq 'deletion') { + print colored $prompt_color, + sprintf(__("Apply deletion to index [y,n,q,a,d,/%s,?]? "), $other); + } else { + print colored $prompt_color, + sprintf(__("Apply this hunk to index [y,n,q,a,d,/%s,?]? "), $other); + } + } elsif ($patch_mode eq 'checkout_index') { + if ($hunk[$ix]{TYPE} eq 'mode') { + print colored $prompt_color, + sprintf(__("Discard mode change from worktree [y,n,q,a,d,/%s,?]? "), $other); + } elsif ($hunk[$ix]{TYPE} eq 'deletion') { + pr
[PATCH v2 05/11] i18n: add--interactive: mark message for translation
Mark 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 --- git-add--interactive.perl | 91 ++- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 08badfa..5b89b97 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -91,6 +91,7 @@ sub colored { } # command line options +my $cmd; my $patch_mode; my $patch_mode_revision; @@ -171,7 +172,8 @@ my %patch_modes = ( }, ); -my %patch_mode_flavour = %{$patch_modes{stage}}; +$patch_mode = 'stage'; +my %patch_mode_flavour = %{$patch_modes{$patch_mode}}; sub run_cmd_pipe { if ($^O eq 'MSWin32') { @@ -1372,12 +1374,84 @@ sub patch_update_file { for (@{$hunk[$ix]{DISPLAY}}) { print; } - print colored $prompt_color, $patch_mode_flavour{VERB}, - ($hunk[$ix]{TYPE} eq 'mode' ? ' mode change' : - $hunk[$ix]{TYPE} eq 'deletion' ? ' deletion' : - ' this hunk'), - $patch_mode_flavour{TARGET}, - " [y,n,q,a,d,/$other,?]? "; + if ($patch_mode eq 'stage') { + if ($hunk[$ix]{TYPE} eq 'mode') { + print colored $prompt_color, + sprintf(__("Stage mode change [y,n,q,a,d,/%s,?]? "), $other); + } elsif ($hunk[$ix]{TYPE} eq 'deletion') { + print colored $prompt_color, + sprintf(__("Stage deletion [y,n,q,a,d,/%s,?]? "), $other); + } else { + print colored $prompt_color, + sprintf(__("Stage this hunk [y,n,q,a,d,/%s,?]? "), $other); + } + } elsif ($patch_mode eq 'stash') { + if ($hunk[$ix]{TYPE} eq 'mode') { + print colored $prompt_color, + sprintf(__("Stash mode change [y,n,q,a,d,/%s,?]? "), $other); + } elsif ($hunk[$ix]{TYPE} eq 'deletion') { + print colored $prompt_color, + sprintf(__("Stash deletion [y,n,q,a,d,/%s,?]? "), $other); + } else { + print colored $prompt_color, + sprintf(__("Stash this hunk [y,n,q,a,d,/%s,?]? "), $other); + } + } elsif ($patch_mode eq 'reset_head') { + if ($hunk[$ix]{TYPE} eq 'mode') { + print colored $prompt_color, + sprintf(__("Unstage mode change [y,n,q,a,d,/%s,?]? "), $other); + } elsif ($hunk[$ix]{TYPE} eq 'deletion') { + print colored $prompt_color, + sprintf(__("Unstage deletion [y,n,q,a,d,/%s,?]? "), $other); + } else { + print colored $prompt_color, + sprintf(__("Unstage this hunk [y,n,q,a,d,/%s,?]? "), $other); + } + } elsif ($patch_mode eq 'reset_nothead') { + if ($hunk[$ix]{TYPE} eq 'mode') { + print colored $prompt_color, + sprintf(__("Apply mode change to index [y,n,q,a,d,/%s,?]? "), $other); + } elsif ($hunk[$ix]{TYPE} eq 'deletion') { + print colored $prompt_color, + sprintf(__("Apply deletion to index [y,n,q,a,d,/%s,?]? "), $other); + } else { + print colored $prompt_color, + sprintf(__("Apply this hunk to index [y,n,q,a,d,/%s,?]? "), $other); + } + } elsif ($patch_mode eq 'checkout_index') { + if ($hunk[$ix]{TYPE} eq 'mode') { + print colored $prompt_color, + sprintf(__("Discard mode change from worktree [y,n,q,a,d,/%s,?]? "), $other); + } elsif ($hunk[$ix]{TYPE} eq 'deletion') { + pr