W dniu 26.09.2016 o 01:09, Junio C Hamano pisze:
> Vasco Almeida <vascomalme...@sapo.pt> 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

Reply via email to