tis 2002-05-14 klockan 16.45 skrev Robert Ennals:
Martin Norbäck <d95mback@dtek.chalmers.se> wrote:
I agree that i18n needs positional arguments. What's wrong with simply doing like this:
printf "I have %. %. %.." ["trained", show 1, "Jedi"] printf "%2. %3. %1. I have." ["trained", show 1, "Jedi"]
Nothing is exceptionally wrong with it, except it's not as flexible. Since everything is show'n, how would you handle things like "%5.2f" or "%*d"? In Brian Huffman's version it's almost trivial to add. I know I can use formatDouble and whatnot, but the code looks cluttered this way. "C" printf has many pitfalls, but I like its terseness.
Changing format specifiers normally doesn't happen during translation. Word order changes happen.
I personally much prefer the syntax currently used in Haskell, which is also essentially what is used in most other recent languages, including Java, C++, and (god help me) Perl.
In the example given, I could write:
"I have " ++ action ++ " " ++ number ++ " " ++ whatas where action = "trained" number = show 1 whatas = "Jedi"
How do you internationalize this code snippet? The issue here was with i18n. When doing i18n, you need to give the translator the possibility to change the word order, hence the Yoda example.
Which is IMHO rather more readable than a load of weird control codes hidden in a text string that one then has to match against a list.
The point with hiding them in a control string is that you can have the translator translate the control string, and not have to change the source code, like with gettext. Very nice system. Regards, Martin -- Martin Norbäck d95mback@dtek.chalmers.se Kapplandsgatan 40 +46 (0)708 26 33 60 S-414 78 GÖTEBORG http://www.dtek.chalmers.se/~d95mback/ SWEDEN OpenPGP ID: 3FA8580B