preprocessing printf/regex strings (like ocaml)

Martin Norbäck d95mback@dtek.chalmers.se
14 May 2002 17:04:50 +0200


--=-31X1eyrrGTqACpvbiAt/
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

tis 2002-05-14 klockan 16.45 skrev Robert Ennals:
> > Martin Norb=E4ck <d95mback@dtek.chalmers.se> wrote:
> > > I agree that i18n needs positional arguments.
> > > What's wrong with simply doing like this:
> > >=20
> > > printf "I have %. %. %.."    ["trained", show 1, "Jedi"]
> > > printf "%2. %3. %1. I have." ["trained", show 1, "Jedi"]
> >=20
> > 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=20
> > 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 a=
lso=20
> essentially what is used in most other recent languages, including Java, =
C++,=20
> and (god help me) Perl.
>=20
> In the example given, I could write:
>=20
> "I have " ++ action ++ " " ++ number ++ " " ++ whatas
> where
>     action =3D "trained"
>     number =3D show 1
>     whatas =3D "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 hid=
den=20
> 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

--=20
Martin Norb=E4ck          d95mback@dtek.chalmers.se             =20
Kapplandsgatan 40       +46 (0)708 26 33 60                   =20
S-414 78  G=D6TEBORG      http://www.dtek.chalmers.se/~d95mback/
SWEDEN                  OpenPGP ID: 3FA8580B

--=-31X1eyrrGTqACpvbiAt/
Content-Type: application/pgp-signature; name=signature.asc

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: För information se http://www.gnupg.org/

iD8DBQA84SeSkXyAGj+oWAsRAkehAJ96hVcThlpXE7TfAtze070xZsD2DwCfbS9Q
xPP8ix7Q3dkh+OWNxy3MR3U=
=h5lS
-----END PGP SIGNATURE-----

--=-31X1eyrrGTqACpvbiAt/--