changeset: 7088:7dc8a6a3592a user: Kevin McCarthy <ke...@8t8.us> date: Wed Jun 14 19:21:22 2017 -0700 link: http://dev.mutt.org/hg/mutt/rev/7dc8a6a3592a
Auto-pad translation for the GPGME key selection "verify key" headers. Remove the ridiculous need for the translators to pad the translation strings themselves. diffs (264 lines): diff -r 2188de087f35 -r 7dc8a6a3592a crypt-gpgme.c --- a/crypt-gpgme.c Wed Jun 14 15:23:07 2017 -0700 +++ b/crypt-gpgme.c Wed Jun 14 19:21:22 2017 -0700 @@ -3365,6 +3365,40 @@ return ret; } +enum +{ + KIP_NAME = 0, + KIP_AKA, + KIP_VALID_FROM, + KIP_VALID_TO, + KIP_KEY_TYPE, + KIP_KEY_USAGE, + KIP_FINGERPRINT, + KIP_SERIAL_NO, + KIP_ISSUED_BY, + KIP_SUBKEY, + KIP_END +}; + +static const char * const KeyInfoPrompts[] = +{ + /* L10N: + * The following are the headers for the "verify key" output from the + * GPGME key selection menu (bound to "c" in the key selection menu). + * They will be automatically aligned. */ + N_("Name: "), + N_("aka: "), + N_("Valid From: "), + N_("Valid To: "), + N_("Key Type: "), + N_("Key Usage: "), + N_("Fingerprint: "), + N_("Serial-No: "), + N_("Issued By: "), + N_("Subkey: ") +}; + +int KeyInfoPadding[KIP_END] = { 0 }; /* Print verbose information about a key or certificate to FP. */ static void print_key_info (gpgme_key_t key, FILE *fp) @@ -3379,6 +3413,22 @@ int is_pgp = 0; int i; gpgme_user_id_t uid = NULL; + static int max_header_width = 0; + int width; + + if (!max_header_width) + { + for (i = 0; i < KIP_END; i++) + { + KeyInfoPadding[i] = mutt_strlen (_(KeyInfoPrompts[i])); + width = mutt_strwidth (_(KeyInfoPrompts[i])); + if (max_header_width < width) + max_header_width = width; + KeyInfoPadding[i] -= width; + } + for (i = 0; i < KIP_END; i++) + KeyInfoPadding[i] += max_header_width; + } is_pgp = key->protocol == GPGME_PROTOCOL_OpenPGP; @@ -3388,13 +3438,14 @@ continue; s = uid->uid; - /* L10N: - Fill dots to make the DOTFILL entries the same length. - In English, msgid "Fingerprint: " is the longest entry for this menu. - Your language may vary. */ - fputs (idx ? _(" aka ......: ") :_("Name ......: "), fp); + + if (!idx) + fprintf (fp, "%*s", KeyInfoPadding[KIP_NAME], _(KeyInfoPrompts[KIP_NAME])); + else + fprintf (fp, "%*s", KeyInfoPadding[KIP_AKA], _(KeyInfoPrompts[KIP_AKA])); if (uid->invalid) { + /* L10N: comes after the Name or aka if the key is invalid */ fputs (_("[Invalid]"), fp); putc (' ', fp); } @@ -3415,22 +3466,22 @@ #else strftime (shortbuf, sizeof shortbuf, "%c", tm); #endif - /* L10N: DOTFILL */ - fprintf (fp, _("Valid From : %s\n"), shortbuf); + fprintf (fp, "%*s%s\n", KeyInfoPadding[KIP_VALID_FROM], + _(KeyInfoPrompts[KIP_VALID_FROM]), shortbuf); } - + if (key->subkeys && (key->subkeys->expires > 0)) { tt = key->subkeys->expires; - + tm = localtime (&tt); #ifdef HAVE_LANGINFO_D_T_FMT strftime (shortbuf, sizeof shortbuf, nl_langinfo (D_T_FMT), tm); #else strftime (shortbuf, sizeof shortbuf, "%c", tm); #endif - /* L10N: DOTFILL */ - fprintf (fp, _("Valid To ..: %s\n"), shortbuf); + fprintf (fp, "%*s%s\n", KeyInfoPadding[KIP_VALID_TO], + _(KeyInfoPrompts[KIP_VALID_TO]), shortbuf); } if (key->subkeys) @@ -3443,25 +3494,31 @@ if (key->subkeys) aval = key->subkeys->length; - /* L10N: DOTFILL */ - fprintf (fp, _("Key Type ..: %s, %lu bit %s\n"), s2, aval, s); - - /* L10N: DOTFILL */ - fprintf (fp, "%s", _("Key Usage .: ")); + fprintf (fp, "%*s", KeyInfoPadding[KIP_KEY_TYPE], + _(KeyInfoPrompts[KIP_KEY_TYPE])); + /* L10N: This is printed after "Key Type: " and looks like this: + * PGP, 2048 bit RSA */ + fprintf (fp, _("%s, %lu bit %s\n"), s2, aval, s); + + fprintf (fp, "%*s", KeyInfoPadding[KIP_KEY_USAGE], + _(KeyInfoPrompts[KIP_KEY_USAGE])); delim = ""; if (key_check_cap (key, KEY_CAP_CAN_ENCRYPT)) { + /* L10N: value in Key Usage: field */ fprintf (fp, "%s%s", delim, _("encryption")); delim = _(", "); } if (key_check_cap (key, KEY_CAP_CAN_SIGN)) { + /* L10N: value in Key Usage: field */ fprintf (fp, "%s%s", delim, _("signing")); delim = _(", "); } if (key_check_cap (key, KEY_CAP_CAN_CERTIFY)) { + /* L10N: value in Key Usage: field */ fprintf (fp, "%s%s", delim, _("certification")); delim = _(", "); } @@ -3470,8 +3527,8 @@ if (key->subkeys) { s = key->subkeys->fpr; - /* L10N: DOTFILL */ - fputs (_("Fingerprint: "), fp); + fprintf (fp, "%*s", KeyInfoPadding[KIP_FINGERPRINT], + _(KeyInfoPrompts[KIP_FINGERPRINT])); if (is_pgp && strlen (s) == 40) { for (i=0; *s && s[1] && s[2] && s[3] && s[4]; s += 4, i++) @@ -3503,8 +3560,8 @@ { s = key->issuer_serial; if (s) - /* L10N: DOTFILL */ - fprintf (fp, _("Serial-No .: 0x%s\n"), s); + fprintf (fp, "%*s0x%s\n", KeyInfoPadding[KIP_SERIAL_NO], + _(KeyInfoPrompts[KIP_SERIAL_NO]), s); } if (key->issuer_name) @@ -3512,8 +3569,8 @@ s = key->issuer_name; if (s) { - /* L10N: DOTFILL */ - fprintf (fp, "%s", _("Issued By .: ")); + fprintf (fp, "%*s", KeyInfoPadding[KIP_ISSUED_BY], + _(KeyInfoPrompts[KIP_ISSUED_BY])); parse_and_print_user_id (fp, s); putc ('\n', fp); } @@ -3528,30 +3585,34 @@ idx++, subkey = subkey->next) { s = subkey->keyid; - + putc ('\n', fp); if ( strlen (s) == 16) s += 8; /* display only the short keyID */ - /* L10N: DOTFILL */ - fprintf (fp, _("Subkey ....: 0x%s"), s); + fprintf (fp, "%*s0x%s", KeyInfoPadding[KIP_SUBKEY], + _(KeyInfoPrompts[KIP_SUBKEY]), s); if (subkey->revoked) { putc (' ', fp); + /* L10N: describes a subkey */ fputs (_("[Revoked]"), fp); } if (subkey->invalid) { putc (' ', fp); + /* L10N: describes a subkey */ fputs (_("[Invalid]"), fp); } if (subkey->expired) { putc (' ', fp); + /* L10N: describes a subkey */ fputs (_("[Expired]"), fp); } if (subkey->disabled) { putc (' ', fp); + /* L10N: describes a subkey */ fputs (_("[Disabled]"), fp); } putc ('\n', fp); @@ -3566,8 +3627,8 @@ #else strftime (shortbuf, sizeof shortbuf, "%c", tm); #endif - /* L10N: DOTFILL */ - fprintf (fp, _("Valid From : %s\n"), shortbuf); + fprintf (fp, "%*s%s\n", KeyInfoPadding[KIP_VALID_FROM], + _(KeyInfoPrompts[KIP_VALID_FROM]), shortbuf); } if (subkey->expires > 0) @@ -3580,8 +3641,8 @@ #else strftime (shortbuf, sizeof shortbuf, "%c", tm); #endif - /* L10N: DOTFILL */ - fprintf (fp, _("Valid To ..: %s\n"), shortbuf); + fprintf (fp, "%*s%s\n", KeyInfoPadding[KIP_VALID_TO], + _(KeyInfoPrompts[KIP_VALID_TO]), shortbuf); } if (subkey) @@ -3594,11 +3655,12 @@ else aval = 0; - /* L10N: DOTFILL */ - fprintf (fp, _("Key Type ..: %s, %lu bit %s\n"), "PGP", aval, s); - - /* L10N: DOTFILL */ - fprintf (fp, "%s", _("Key Usage .: ")); + fprintf (fp, "%*s", KeyInfoPadding[KIP_KEY_TYPE], + _(KeyInfoPrompts[KIP_KEY_TYPE])); + fprintf (fp, _("%s, %lu bit %s\n"), "PGP", aval, s); + + fprintf (fp, "%*s", KeyInfoPadding[KIP_KEY_USAGE], + _(KeyInfoPrompts[KIP_KEY_USAGE])); delim = ""; if (subkey->can_encrypt)