Potential improvement of localisation of script

Författare: Göran Uddeborg (goeran_at_uddeborg.pp.se)
Datum: 2002-11-02 18:30:32

While doing a "peer review" of the Swedish translation of util-linux,
I noted these two code pieces from misc-utils/script.c:

	fprintf(fscript, _("Script started on %s"), ctime(&tvec));

and

			fprintf(fscript, _("\nScript done on %s"),
				ctime(&tvec));

The messages themselves are marked for translation, but the date and
time will always be in English.  ctime() is not locale sensitive.

May I suggest you instead use strftime() for this?  So instead of

	fprintf(fscript, _("Script started on %s"), ctime(&tvec));

you could use:

	strftime(obuf, sizeof obuf, _("Script started on %c\n"),
	         localtime(&tvec));
	fputs(obuf, fscript);

or alternatively, to avoid the translator getting confused by %c:

	strftime(obuf, sizeof obuf, "%c\n", localtime(&tvec));
	fprintf(fscript, _("Script started on %s"), obuf);

In the C locale, the result would be identical, in any other locale
the complete message, including the time, would get localised.

(If you find it dirty to reuse the obuf for two things, an separate
buffer could of course be used.

Arkiv genererat av hypermail 2.1.4.