Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 2001-12-20 13:34:43


On 12/20/01 10:12 AM, "rogeeff" <rogeeff_at_[hidden]> wrote:

> Why? Any literals inside format definition could be extracted into
> resouce files. Or do you mean something else?

I meant that translators often need to rearrange pieces of a message. In
English the name of the file might come before the size, but in some other
language the size might need to go first, or be repeated.

This has been discussed in the formatter thread, but perhaps you didn't
follow that part. A classic example is this:

   printf("%04d-%02d-%02d", year, month, day);

A translator can localize this to US "mm/dd/yyyy" format with the Unix
extensions to printf by changing the format string to:

   printf("%2$02d/%3$02d/%1$04d", year, month, day);

This is a powerful thing to offer translators. This sort of technique is
extensively used on some projects that use gettext as their translation
system, and the need to substitute in a different order comes up in many
translation contexts, not just with numeric or date formatting.

Note that ostream formatting is already pretty good. The formatter proposals
appeal to me because of:

    1) reordering capabilities for translators on projects that translate by
string
    2) more-terse way to specify format
    3) easier to decipher the format because it's "by example" -- the format
looks something like the final result
    4) translators on projects that translate by string can easily alter
format specifications like precision or padding
    5) syntax familiar to the many programmers who already know printf
format, but without type safety problems inherent in printf use

I understand that you haven't seen the need for something like the proposed
formatter, but I know many C++ programmers that would benefit from it for
one or more of the reasons above. So I'd like us to iron out the details and
get something into boost.

    -- Darin

PS: In my own programs, I like something a bit less cryptic for translation
purposes, so I often do something less terse like:

    message = Translate("Send <payload> to <recipient>");
    ReplaceAll(message, "<payload>", payload);
    ReplaceAll(message, "<recipient>", recipient);

But this won't work if the payload is something that could contain the
substring "<recipient>", so I probably need to make myself a function or two
to do this right. It also prevents translators from making a translation
includes a literal "<payload>" or "<recipient>" in it, but that's usually
not a problem.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk