diff options
author | Kevin McCarthy <kevin@8t8.us> | 2017-06-14 19:21:22 -0700 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2017-06-14 19:21:22 -0700 |
commit | 9958c5dd77e448ee6cc689891b3bfeb745c4f8b6 (patch) | |
tree | 69e70b9a851f893a4cf3ee5b817cbce6dc1a28e5 /crypt-gpgme.c | |
parent | d21b1ef8dde5ff40237c97f4876e32a3a67bac4b (diff) |
Auto-pad translation for the GPGME key selection "verify key" headers.
Remove the ridiculous need for the translators to pad the translation
strings themselves.
Diffstat (limited to 'crypt-gpgme.c')
-rw-r--r-- | crypt-gpgme.c | 126 |
1 files changed, 94 insertions, 32 deletions
diff --git a/crypt-gpgme.c b/crypt-gpgme.c index 61f8d8a7..14d420e9 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -3365,6 +3365,40 @@ key_check_cap (gpgme_key_t key, key_cap_t cap) 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 @@ static void print_key_info (gpgme_key_t key, FILE *fp) 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 @@ static void print_key_info (gpgme_key_t key, FILE *fp) 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 @@ static void print_key_info (gpgme_key_t key, FILE *fp) #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 @@ static void print_key_info (gpgme_key_t key, FILE *fp) if (key->subkeys) aval = key->subkeys->length; - /* L10N: DOTFILL */ - fprintf (fp, _("Key Type ..: %s, %lu bit %s\n"), s2, aval, s); + 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); - /* L10N: DOTFILL */ - fprintf (fp, "%s", _("Key Usage .: ")); + 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 @@ static void print_key_info (gpgme_key_t key, FILE *fp) 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 @@ static void print_key_info (gpgme_key_t key, FILE *fp) { 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 @@ static void print_key_info (gpgme_key_t key, FILE *fp) 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 @@ static void print_key_info (gpgme_key_t key, FILE *fp) 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 @@ static void print_key_info (gpgme_key_t key, FILE *fp) #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 @@ static void print_key_info (gpgme_key_t key, FILE *fp) #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 @@ static void print_key_info (gpgme_key_t key, FILE *fp) else aval = 0; - /* L10N: DOTFILL */ - fprintf (fp, _("Key Type ..: %s, %lu bit %s\n"), "PGP", aval, s); + fprintf (fp, "%*s", KeyInfoPadding[KIP_KEY_TYPE], + _(KeyInfoPrompts[KIP_KEY_TYPE])); + fprintf (fp, _("%s, %lu bit %s\n"), "PGP", aval, s); - /* L10N: DOTFILL */ - fprintf (fp, "%s", _("Key Usage .: ")); + fprintf (fp, "%*s", KeyInfoPadding[KIP_KEY_USAGE], + _(KeyInfoPrompts[KIP_KEY_USAGE])); delim = ""; if (subkey->can_encrypt) |