i18n: Format large integers before the translation message

The GNU gettext only supports the ISO C99 macros for integral
types. If there is a need to use unsupported formatting macros,
e.g. PRIuGRUB_UINT64_T, according to [1] the number to a string
conversion should be separated from the code printing message
requiring the internationalization. So, the function grub_snprintf()
is used to print the numeric values to an intermediate buffer and
the internationalized message contains a string format directive.

[1] https://www.gnu.org/software/gettext/manual/html_node/Preparing-Strings.html#No-string-concatenation

Signed-off-by: Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Miguel Ángel Arruga Vivas 2021-04-03 15:33:33 +02:00 committed by Daniel Kiper
parent e48fc8880d
commit 837fe48deb
7 changed files with 51 additions and 25 deletions

View File

@ -612,6 +612,7 @@ luks2_recover_key (grub_disk_t source,
/* Try all keyslot */
for (json_idx = 0; json_idx < size; json_idx++)
{
char indexstr[21]; /* log10(2^64) ~ 20, plus NUL character. */
typeof (source->total_sectors) max_crypt_sectors = 0;
grub_errno = GRUB_ERR_NONE;
@ -732,11 +733,12 @@ luks2_recover_key (grub_disk_t source,
continue;
}
grub_snprintf (indexstr, sizeof (indexstr) - 1, "%" PRIuGRUB_UINT64_T, keyslot.idx);
/*
* TRANSLATORS: It's a cryptographic key slot: one element of an array
* where each element is either empty or holds a key.
*/
grub_printf_ (N_("Slot \"%" PRIuGRUB_UINT64_T "\" opened\n"), keyslot.idx);
grub_printf_ (N_("Slot \"%s\" opened\n"), indexstr);
candidate_key_len = keyslot.key_size;
break;

View File

@ -121,10 +121,14 @@ grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs,
return err;
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%" PRIxGRUB_UINT64_T
" is not implemented yet"),
{
char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
ELF_R_TYPE (rel->r_info));
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%s is not implemented yet"), rel_info);
}
}
}
}

View File

@ -183,10 +183,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%" PRIxGRUB_UINT64_T
" is not implemented yet"),
{
char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
ELF_R_TYPE (rel->r_info));
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%s is not implemented yet"), rel_info);
}
}
}

View File

@ -136,10 +136,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
case R_IA64_LDXMOV:
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%" PRIxGRUB_UINT64_T
" is not implemented yet"),
{
char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
ELF_R_TYPE (rel->r_info));
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%s is not implemented yet"), rel_info);
}
}
}
return GRUB_ERR_NONE;

View File

@ -330,10 +330,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
case R_RISCV_RELAX:
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%" PRIxGRUB_UINT64_T
" is not implemented yet"),
{
char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
(grub_uint64_t) ELF_R_TYPE (rel->r_info));
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%s is not implemented yet"), rel_info);
}
}
}

View File

@ -176,10 +176,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
& 0x1fff);
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%" PRIxGRUB_UINT64_T
" is not implemented yet"),
{
char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
ELF_R_TYPE (rel->r_info));
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%s is not implemented yet"), rel_info);
}
}
}

View File

@ -106,10 +106,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%" PRIxGRUB_UINT64_T
" is not implemented yet"),
{
char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
ELF_R_TYPE (rel->r_info));
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%s is not implemented yet"), rel_info);
}
}
}