News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

C++ TIps: IO - internationalized printf

Started by ben2ong2, October 06, 2006, 11:25:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ben2ong2

(Newsgroups: comp.lang.c++.moderated, 28 July 99)


KANZE: You are not allowed to view links. Register or Login

>> On the other hand, printf is typically internationalized (although
>> this is formally an extension, and not part of the C standard); in
>> practice, you can't use iostream when you need internationalization.


RUSS: You are not allowed to view links. Register or Login

> Sorry, maybe I don't understand what you mean, but isn't locale
> used for internationalization?


KANZE:

Locale covers several aspects of internationalization, plus a number of
other issues like conversions between internal and external format.
Like the standard printf (as defined by ISO 9899), however, it is
missing one of the most important parts: position independant arguments.
X/Open defined an extension to do this with printf; I find it incredible
that WG14 hasn't standardized this extension.  The syntax of iostream
pretty much makes such an extension impossible (and in fact, pretty much
makes solving the problem using iostream-like output impossible).

For those unaware of the problem: word order varies between languages,
and so a text in English "xxx 1.45 yyy 23 zzz" might become "zzz 23 yyy
1.45 xxx" in German or French.  The X/Open extension to printf allows
specifying which argument to use in the format specifier, e.g. "%2$2d"
instead of simple "%2d".  For example, for the above text, the English
string might read "xxx %4.2f yyy %2d zzz"; translated to German or
French, it could be "zzz %2$2d yyy %1$4.2f zzz".  Notice that you still
pass the floating point value as the first argument, and the integer as
the second.
You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login