Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Printf and i18n
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jérôme_Marant <jerome.marant@f...>
Subject: Re: [Caml-list] Printf and i18n
On Thu, Apr 18, 2002 at 08:47:53AM +0200, Daniel de Rauglaudre wrote:
> 
> 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

  Thanks. That sounds what I'm looking for.

  By the way, in order to improve the localization process, we would need
  to add the "argument reordering" feature to printf functions.
  For instance, with: 

  printf " %2$d %1$s" "foo" 1

  you get : 1 foo

  because some languages do not order words the same way.

  One more question : could you (or any other OCaml developer) give some
  explainations about the Obj module since, even "not for the casual user",
  it can be usefull sometimes (well at least for you and in the printf
  functions)?

  Thanks in advance.

-- 
Jérôme Marant
-------------------
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