The API of ocaml-gettext is really reduced. It is made on purpose. The design is heavily based on modules and functors. There is no real reason for this design, it was just really useful at the time the code was written.
The library supposes that all the textdomain
that will be used during
translation, are declared before using it. It is a real constraint, but it enables more
optimisation. Moreover, it allows having a more "functional" use.
First of all, a parameter t
should be defined. This parameter holds
all the required value to initialise ocaml-gettext. In particular, it contains information
about :
which textdomain will be used,
which language will be used,
how the error should be handle,
which directory to search.
This parameter is build and updated through internal functions. You don't have direct access to it.
The parameter t
is not directly used for translation. It must be converted into
a parameter t'
which is a real function to access translation. The transformation
from t
to t'
is handled through a function
realize
. The parameter t'
is used in low level translation.
All the work of the library is done in the function realize
. This function is
not provided in the base package. It is build out of real implementation of ocaml-gettext ( such as
gettext-camomile
or gettext-stub
). This function could handle
all the parameters in different ways. Concerning gettext-camomile
, it builds a
translation table for all the files found which correspond to a declared textdomain
.
Since it should be very difficult to pass a parameter t
or t'
in
all functions that should use translation, we provide a more simple way to use the library. The
top level functions use a global reference to store the parameters t
and
t'
. This helps to integrate ocaml-gettext more easily into existing application.