I am far from being a gettext expert, but I think the new version
doesn't work. My understanding is that one can either mark strings for
translation - or one inserts a translation function call, which also
marks them for translation. In either case, the string passed to gettext
will be used as key for the translation.
On 07/17/2012 02:49 PM, Janus Weil wrote:
+ char buffer[50];
- error_print (_("Warning:"), _(gmsgid), argp);
Namely, that version passed "Warning" to the gettext library, which
returns a string with the translated version.
+ strcpy (buffer, _("Warning:"));
Ditto here. Though, I think you are in danger of exceeding the buffer -
if not here, then further down. I admit that having 49 characters should
be enough, but with UTF8 one might quickly have only 24 characters - and
then it gets tight ... especially as you will strcat more output.
+ strcat (buffer, _(" Fortran 2008 obsolescent feature:"));
That would be a candidate for overflow. The current wording has 43
characters in English. Assume, e.g., the same length but in Cyrillic; I
think that's then 2*43 = 84 plus '\0' = 85 bytes!
+ error_print (buffer, _(gmsgid), argp);
Wouldn't it be simplyer to keep the error print for Warning/Error,
assign the messages to a "const char * msg" and then pass the msg to
error_print? That would be two calls to error_print, but would avoid
buffer issues, calls to strcpy/strcat, and would work with i18n.
Namely:
error_print (_("Warning:"), _(gmsgid), argp);
...
case GFC_STD_F2008_OBS:
msg = N_(" Fortran 2008 obsolescent feature:");
break;
...
error_print (_(msg), _(gmsgid), argp);
Note the N_() which marks the string as translatable without actually calling gettext. (I
think one of the header files contains "#define _ gettext".)
Okay, that won't work as one has to call error_print only once. Maybe something
like the following will work:
const char *msg, *msg2;
char *buffer;
msg = _("Warning: ");
msg2 = _("Deleted feature:");
buffer = (char *) alloca (strlen (msg) + strlen (msg2)+1);
strcpy(buffer, msg);
strcat (buffer, msg2);
error_print (buffer, _(gmsgid), argp);
where the buffer itself is not send through _().
Tobias