caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Prevost <visigoth@cs.cmu.edu>
To: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Printf and i18n
Date: 18 Apr 2002 04:01:51 -0400	[thread overview]
Message-ID: <86y9fljuz4.fsf@laurelin.dementia.org> (raw)
In-Reply-To: <20020418084753.A11351@verdot.inria.fr>

>>>>> "dr" == Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr> writes:

    dr> For the translations, I use a lexicon file, containing a list
    dr> of entries which I want to be i18n. It is an idea I took from
    dr> Caml Light. The first string, without language, is the format
    dr> to be translated, in a vehicular language (actually English),
    dr> and I give the translation in each language I want. E.g. an
    dr> entry can be:

    dr>      hello, my name is %s\n
    dr>  en: hello, my name is %s\n
    dr>  es: buenos dias, me llamo %s\n
    dr>  fr: bonjour, je m'appelle %s\n

A good try, but unfortunately it doesn't allow for the more
significant problem, which is word order variation.  Imagine a simple
format like:

Printf.printf "%s's %s" "John" "document"

The problem here is that we have the following translations (sort of,
no character sets here):

en: X's Y
ja: X no Y
ru: Y u X

And of course, with more arguments you get more variety.

One solution is to treat your formats as functions, rather than
formats.  This cuts down on the utility somewhat, since you have to
sprintf instead of printing directly, but:

let owns = [En, fun owner owned -> Printf.sprintf "%s's %s" owner owned;
            Ja, fun owner owned -> Printf.sprintf "%s no %s" owner owned;
            Ru, fun owner owned -> Printf.sprintf "%s u %s" owned owner]

sort of gets you moving in the right direction.  Of course, you need
an automated system to handle things reasonably.

This is why many modern printf-style systems, especially those for
handling internationalization, include numbered or named slots to be
filled in.  For example, in Python:

fmt = "%(owner)s's %(owned)s"
fmt = "%(owner)s no %(owned)s"
fmt = "%(owned) u %(owner)"

can all be used as:

fmt % {'owner':'John', 'owned':'document'}

In Java:

fmt = new MessageFormat("{0}''s {1}");
fmt = new MessageFormat("{0} no {1}");
fmt = new MessageFormat("{1} u {0}");

can all be used as:

fmt.format(new Object[] {"John", "document"})

Either of these mechanisms allow reading a format from a catalog and
using it in that way.  The only way I can see doing this with
something like O'Caml's current mechanism is introducing a new format
function like printf which takes a format like:

("%s%s:{0}'s {1}" : ('a,'b,'c) format)
("%s%s:{0} no {1}" : ('a,'b,'c) format)
("%s%s:{1} u {0}" : ('a,'b,'c) format)

Use the % model up front to indicate the argument types in argument
order, then indicate what order the arguments are to be used
separately.  This is, of course, rather ugly.  A richer format
language would be preferable.  If keyword arguments can't be made to
work right when included in the type (as seems likely), perhaps a
format language like Python's, but using numbered argument positions
instead of names, so:

("%s %d" : (string -> int -> 'a,'b,'a) format)

but also

("%(1)d %(0)s" : (string -> int -> 'a, 'b, 'a) format)


John.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2002-04-18 21:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-17 17:37 Jérôme Marant
2002-04-17 17:53 ` [Caml-list] Modular subject-observer pattern ? Pascal Grossé
2002-04-18  6:47 ` [Caml-list] Printf and i18n Daniel de Rauglaudre
2002-04-18  8:01   ` John Prevost [this message]
2002-04-18  8:02   ` Jérôme Marant
2002-04-18  8:13     ` Jacques Garrigue
2002-04-18  8:17       ` Chris Hecker
2002-04-18  8:21       ` Jérôme Marant
2002-04-18  8:27     ` Daniel de Rauglaudre
2002-04-18  9:33       ` Jérôme Marant
2002-04-18 10:40         ` Daniel de Rauglaudre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86y9fljuz4.fsf@laurelin.dementia.org \
    --to=visigoth@cs.cmu.edu \
    --cc=caml-list@inria.fr \
    --cc=daniel.de_rauglaudre@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).