From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id IAA11470; Thu, 18 Apr 2002 08:47:54 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id IAA11466 for ; Thu, 18 Apr 2002 08:47:54 +0200 (MET DST) Received: from verdot.inria.fr (verdot.inria.fr [128.93.11.7]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g3I6lrb10636 for ; Thu, 18 Apr 2002 08:47:53 +0200 (MET DST) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id IAA11380 for caml-list@inria.fr; Thu, 18 Apr 2002 08:47:53 +0200 Date: Thu, 18 Apr 2002 08:47:53 +0200 From: Daniel de Rauglaudre To: caml-list@inria.fr Subject: Re: [Caml-list] Printf and i18n Message-ID: <20020418084753.A11351@verdot.inria.fr> References: <87ads2rzu8.fsf@marant.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.2.5i In-Reply-To: <87ads2rzu8.fsf@marant.org>; from jmarant@free.fr on Wed, Apr 17, 2002 at 07:37:19PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, On Wed, Apr 17, 2002 at 07:37:19PM +0200, Jérôme Marant wrote: > I was thinking about writing a small gettext-like module > for handling internationalisation of strings in OCaml programs. > > But it is quite useless if it cannot work with printf: the > printf format parameter looks like a string but it isn't > (printf is using some internal magics). In my program GeneWeb, I use internationalization with printf. I have a function ftransl function defined like this (revised syntax): value ftransl lang (fmt : format 'a 'b 'c) : format 'a 'b 'c = valid_format fmt (transl lang (Obj.magic fmt : string)); The function "transl", called inside this function, takes the language and the format fmt constrained to be a string and applies the translation. The function "valid_format" checks that this resulting translation has the same % defined in the same order than fmt. Return the translated format if ok. If not ok, it returns the initial format, but you can fail, if you prefer. Therefore, instead of printf "hello, my name is %s\n" name you can write: printf (ftransl "hello, y name is %s\n") name For the translations, I use a lexicon file, containing a list of entries which I want to be i18n. It is an idea I took from Caml Light. The first string, without language, is the format to be translated, in a vehicular language (actually English), and I give the translation in each language I want. E.g. an entry can be: hello, my name is %s\n en: hello, my name is %s\n es: buenos dias, me llamo %s\n fr: bonjour, je m'appelle %s\n -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- 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