[PATCH 1 of 2] record: refactored prompt choices to clean code and offer better choices

A. S. Budden abudden at gmail.com
Thu Feb 23 05:44:17 CST 2012


On 23 February 2012 11:23, timeless <timeless at gmail.com> wrote:
> So. Localized command letters can be an interesting disaster. -
> Especially for users likely to switch between en and some other
> language that uses Latin letters (it's a *different* disaster for non
> Latin languages...).

Okay.  This does beg the question: how do you cope if the translated
string doesn't contain the prompt letter?  I guess one alternative
would be to use the prompt string:

    &s - skip remaining changes to this file

and translate it to (obviously there are several 's's in this example,
but that's beside the point):

    &s - überspringe die restlichen änderungen an dieser datei

You could then implement it as something like (not tested):

    choices = ('Y', _('record this change'),
               'n', _('skip this change'),
               's', _('skip remaining changes to this file'),
               'f', _('record remaining changes to this file'),
               'd', _('skip remaining changes and files'),
               'a', _('record all changes to all remaining files'),
               'q', _('quit, recording no changes'),
               '?', _('show help'))
    prompts = ['&%s - %s' % x for x in choices]
    keychars = ''.join([x[0] for x in choices])
    r = ui.promptchoice('%s [%s]' % (query, keychars), prompts)
    # ...
    # ...
    if choices[r][0] == '?':
        # Help text is the same as prompts but without the & and
joined by new-lines
        ui.write(''.join(['%s - %s\n' % x for x in choices]))

Thoughts?

Al


More information about the Mercurial-devel mailing list