Blame doc/reference-manual.xml

Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
"/usr/share/xml/schema/dtd/4.3/docbookx.dtd" [
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
TO DO</xi:fallback>'> 
Packit 802e35
&fb;;</xi:include>' >
Packit 802e35
&fb;;</xi:include>' >
Packit 802e35
&fb;;</xi:include>' >
Packit 802e35
&fb;;</xi:include>' >
Packit 802e35
&fb;;</xi:include>' >
Packit 802e35
&fb;;</xi:include>' >
Packit 802e35
&fb;;</xi:include>' >
Packit 802e35
&fb;;</xi:include>' >
Packit 802e35
&fb;;</xi:include>' >
Packit 802e35
&fb;;</xi:include>' >
Packit 802e35
&fb;;</xi:include>' >
Packit 802e35
&fb;;</xi:include>' >
Packit 802e35
&fb;;</xi:include>' >
Packit 802e35
' >
Packit 802e35
' >
Packit 802e35
' >
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
Packit 802e35
  ]>
Packit 802e35
<book>
Packit 802e35
  <title>ocaml-gettext reference manual</title>
Packit 802e35
  <bookinfo>
Packit 802e35
    <legalnotice>
Packit 802e35
      <para>
Packit 802e35
        This user manual is considered as a source code and is licensed under the GNU Lesser General Public 
Packit 802e35
        License v2.1 with OCaml static compilation exception.
Packit 802e35
      </para>
Packit 802e35
    </legalnotice>
Packit 802e35
    <author>
Packit 802e35
      <firstname>Sylvain</firstname>
Packit 802e35
      <surname>Le Gall</surname>
Packit 802e35
    </author>
Packit 802e35
    <copyright>
Packit 802e35
      <year>2005</year>
Packit 802e35
      <holder>Sylvain Le Gall</holder>
Packit 802e35
    </copyright>
Packit 802e35
    <revhistory>
Packit 802e35
      <revision>
Packit 802e35
        
Packit 802e35
        <revnumber>svn:revision</revnumber>
Packit 802e35
        <date>svn:date</date>
Packit 802e35
      </revision>
Packit 802e35
    </revhistory>
Packit 802e35
  </bookinfo>
Packit 802e35
  <chapter>
Packit 802e35
    <title>Overview</title>
Packit 802e35
    <section>
Packit 802e35
      <title>What is ocaml-gettext?</title>
Packit 802e35
      <para>
Packit 802e35
        ocaml-gettext is a library to support string translation in OCaml. It provides a simple interface 
Packit 802e35
        to help programmers and translators to create programs that can support different languages. This
Packit 802e35
        allows the internationalisation of programs.
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        ocaml-gettext provides two main functionalities: 
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              translate English strings into localised strings (depending on which gettext data are installed),
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              convert charset from the one used by the translator into the charset of the user.
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
      </para>
Packit 802e35
      <para>The library is build according three points of view:
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              for the programmer: this library provides functions that can be used in OCaml,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              for the translator: this library provides a standard file format (PO file) to help the translator,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              for the user: this library provides a set of command line options to set the language 
Packit 802e35
              and the charset.
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        ocaml-gettext was initially only a wrapper of gettext. It comes with a patch against the source of
Packit 802e35
        xgettext to add support of the OCaml language. As i already used this approach, 
Packit 802e35
        i was convinced that this library should be better integrated by using more advanced features of 
Packit 802e35
        OCaml (such as <command>camlp4</command>). 
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        As a result of porting gettext to ocaml-gettext, we have :
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              a library that can understood the native format of gettext file (MO file),
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              two implementations: a wrapper around gettext and a pure OCaml implementation using 
Packit 802e35
              camomile,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <command>ocaml-gettext</command>: a command line tool to help you to extract, to merge and to install
Packit 802e35
              gettext data.
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
      </para>
Packit 802e35
    </section>
Packit 802e35
    <section>
Packit 802e35
      <title>How is ocaml-gettext related to gettext?</title>
Packit 802e35
      <para>
Packit 802e35
        ocaml-gettext is a close cousin of gettext. In fact, the API is based on gettext. Almost everything 
Packit 802e35
        in ocaml-gettext is compatible with gettext:
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>functions provided in the API are very close to the gettext one,</para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>the library contains a binding of the gettext library,</para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              all the file used are gettext compatible: the library uses PO file for translator 
Packit 802e35
              and MO file for translation,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              the library tries to use the same initialisation sequence as gettext :
Packit 802e35
              it uses the same environment variable, tries to find MO files in the
Packit 802e35
              same places...
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        This documentation will not covered the point that are better explained in the 
Packit 802e35
        <link linkend="gettext-documentation">gettext documentation</link>. It is highly recommended 
Packit 802e35
        to read this documentation, before reading this manual. Most of the point that are explained there 
Packit 802e35
        are not explained again here. However, we have tried to be as precise as possible to enable 
Packit 802e35
        programming with ocaml-gettext without having the need to be a gettext expert.
Packit 802e35
      </para>
Packit 802e35
    </section>
Packit 802e35
  </chapter>
Packit 802e35
  <chapter>
Packit 802e35
    <title>How to install ocaml-gettext</title>
Packit 802e35
    <section>
Packit 802e35
      <title>Using source</title>
Packit 802e35
      <para>To compile ocaml-gettext, you need to install the following prerequisites :
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <ulink url="&download-ocaml;">OCaml</ulink> v3.10.1 or later,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <ulink url="&download-findlib;">findlib</ulink> v1.0.4 or later,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <ulink url="&download-ocaml-fileutils;">ocaml-fileutils</ulink> v0.3.0 or later,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <ulink url="&download-camomile;">camomile</ulink> v0.7.1 or later,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <ulink url="&download-gettext;">gettext</ulink> v0.14.3 or later,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <ulink url="&download-ounit;">OUnit</ulink> v1.0.1 or later
Packit 802e35
              <footnote id="build-test"><para>Only if you want to build unitary test tool</para></footnote>,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <ulink url="&download-ocaml-benchmark;">ocaml-benchmark</ulink> v0.6 or later 
Packit 802e35
              <footnote id="build-benchmark"><para>Only if you want to build benchmarking tool</para></footnote>,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <ulink url="&download-docbook;">Docbook DTD and stylesheets</ulink> v4.3
Packit 802e35
              <footnote id="build-doc"><para>Only if you want to build the documentation</para></footnote>,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
           <listitem>
Packit 802e35
            <para>
Packit 802e35
              <ulink url="&download-xsltproc;">xsltproc</ulink> v1.1.12 or later,
Packit 802e35
              <footnoteref linkend="build-doc"/>,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <ulink url="&download-fop;">fop</ulink> v0.20.5 or later.
Packit 802e35
              <footnoteref linkend="build-doc"/>,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        Camomile and gettext are optional but you need at least one of them in order to be able to build 
Packit 802e35
        the command line tool <command>ocaml-gettext</command>. 
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        After having build and install all prerequisites, extract the source
Packit 802e35
        code of ocaml-gettext to a directory. Go to the source directory and type :
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <command>./configure</command>
Packit 802e35
              <footnote>
Packit 802e35
                <para>
Packit 802e35
                  If needed, you can use <command>./configure <option>--help</option></command> 
Packit 802e35
                  to have a complete help on every option you can use to tweak the 
Packit 802e35
                  installation of ocaml-gettext. To enable documentation generation, use 
Packit 802e35
                  <option>--enable-doc</option>. To enable benchmark executable, use 
Packit 802e35
                  <option>--enable-bench</option>. To enable test executable, use 
Packit 802e35
                  <option>--enable-test</option>.
Packit 802e35
                </para>
Packit 802e35
              </footnote>
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <command>make</command>
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <command>make install</command>
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <command>cd test</command>
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <command>./test</command>
Packit 802e35
              <footnoteref linkend="build-test"/>
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <command>./benchmark</command>
Packit 802e35
              <footnoteref linkend="build-benchmark"/>
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        Since ocaml-gettext is not yet a stable release, building the benchmark and the unitary test tools
Packit 802e35
        is important, especially for debugging purpose. If you encounter problems, you should first
Packit 802e35
        try to run this two commands. They will give you good hints on what causes the problem.
Packit 802e35
      </para>
Packit 802e35
      <note>
Packit 802e35
        <para>
Packit 802e35
          There is a <filename>patches</filename> directory in the source tree. This directory contains patches
Packit 802e35
          against different programs that should be compatible with ocaml-gettext. Please have a look to the
Packit 802e35
          <filename>README.patches</filename> of this directory, to know how to handle patching these programs.
Packit 802e35
        </para>
Packit 802e35
      </note>
Packit 802e35
    </section>
Packit 802e35
    <section>
Packit 802e35
      <title>Debian distribution</title>
Packit 802e35
      <para>
Packit 802e35
        
Packit 802e35
        A debian package is available in the official Debian archive (release "unstable",
Packit 802e35
        "main" section). 
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        To install it, use the command :
Packit 802e35
        <command>apt-get 
Packit 802e35
          <option>install</option> <varname>libgettext-ocaml-dev</varname>
Packit 802e35
        </command>.
Packit 802e35
      </para>
Packit 802e35
    </section>
Packit 802e35
    <section>
Packit 802e35
      <title>Other distributions</title>
Packit 802e35
      <para>
Packit 802e35
        There is no plan to release packages for other distributions. If you have any skill
Packit 802e35
        concerning the packaging of ocaml-gettext for any other distribution, please contact me.
Packit 802e35
      </para>
Packit 802e35
    </section>
Packit 802e35
  </chapter>
Packit 802e35
  <chapter>
Packit 802e35
    <title>Programming with ocaml-gettext</title>
Packit 802e35
    <section>
Packit 802e35
      <title>Overview</title>
Packit 802e35
      <para>
Packit 802e35
        The API of ocaml-gettext is really reduced. It is made on purpose. The design is heavily
Packit 802e35
        based on modules and functors. There is no real reason for this design, it was just 
Packit 802e35
        really useful at the time the code was written.
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        The library supposes that all the <varname>textdomain</varname> that will be used during 
Packit 802e35
        translation, are declared before using it. It is a real constraint, but it enables more
Packit 802e35
        optimisation. Moreover, it allows having a more "functional" use. 
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        
Packit 802e35
        First of all, a parameter <varname>t</varname> should be defined. This parameter holds 
Packit 802e35
        all the required value to initialise ocaml-gettext. In particular, it contains information 
Packit 802e35
        about :
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              which textdomain will be used,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              which language will be used,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              how the error should be handle,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              which directory to search.
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
        This parameter is build and updated through internal functions. You don't have direct access
Packit 802e35
        to it.
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        
Packit 802e35
        The parameter <varname>t</varname> is not directly used for translation. It must be converted into
Packit 802e35
        a parameter <varname>t'</varname> which is a real function to access translation. The transformation
Packit 802e35
        from <varname>t</varname> to <varname>t'</varname> is handled through a function 
Packit 802e35
        <varname>realize</varname>. The parameter <varname>t'</varname> is used in low level translation.
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        
Packit 802e35
        All the work of the library is done in the function <varname>realize</varname>. This function is
Packit 802e35
        not provided in the base package. It is build out of real implementation of ocaml-gettext (such as
Packit 802e35
        <varname>gettext-camomile</varname> or <varname>gettext-stub</varname>). This function could handle
Packit 802e35
        all the parameters in different ways. Concerning <varname>gettext-camomile</varname>, it builds a 
Packit 802e35
        translation table for all the files found which correspond to a declared <varname>textdomain</varname>.
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        
Packit 802e35
        Since it should be very difficult to pass a parameter <varname>t</varname> or <varname>t'</varname> in 
Packit 802e35
        all functions that should use translation, we provide a more simple way to use the library. The 
Packit 802e35
        top level functions use a global reference to store the parameters <varname>t</varname> and 
Packit 802e35
        <varname>t'</varname>. This helps to integrate ocaml-gettext more easily into existing application.
Packit 802e35
      </para>
Packit 802e35
    </section>
Packit 802e35
    <section>
Packit 802e35
      <title>Makefile and source layout</title>
Packit 802e35
      
Packit 802e35
      <para>
Packit 802e35
        The source layout should conform to the one described in 
Packit 802e35
        <link linkend="gettext-documentation">gettext documentation</link>. In particular, it should 
Packit 802e35
        contain a <filename>po</filename> directory. There should be in this directory : 
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              a file <filename>LINGUAS</filename> describing available translations,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              a file <filename>POTFILES</filename> containing the listing of all files that
Packit 802e35
              contain translatable strings,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              a <filename>Makefile</filename> to build the whole thing,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              a set of PO file which contains translated strings for different languages.
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
        During the build, the <filename>Makefile</filename> should generate a file 
Packit 802e35
        <filename>your-domain.pot</filename> that contains a template PO file that can be used
Packit 802e35
        by translator.
Packit 802e35
      </para>
Packit 802e35
      <example>
Packit 802e35
        <title><filename>Makefile</filename> for <filename>po</filename></title>
Packit 802e35
        <programlisting>&po-makefile;</programlisting>
Packit 802e35
      </example>
Packit 802e35
      <example>
Packit 802e35
        <title><filename>LINGUAS</filename></title>
Packit 802e35
        <programlisting>&LINGUAS;</programlisting>
Packit 802e35
      </example>
Packit 802e35
      <example>
Packit 802e35
        <title><filename>POTFILES</filename></title>
Packit 802e35
        <programlisting>&POTFILES;</programlisting>
Packit 802e35
      </example>
Packit 802e35
      
Packit 802e35
      <para>
Packit 802e35
        To build programs and libraries with ocaml-gettext, the preferred way is to use ocamlfind. 
Packit 802e35
        There are five findlib packages: 
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              gettext.base: the base package of ocaml-gettext. It contains the top level type
Packit 802e35
              required to compile any library,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              gettext.extension
Packit 802e35
              <footnote id="advanced-features">
Packit 802e35
                <para>
Packit 802e35
                  This feature is described here for your information only. Since it belongs to 
Packit 802e35
                  low level implementation of ocaml-gettext, it should not be used.
Packit 802e35
                </para>
Packit 802e35
              </footnote>
Packit 802e35
              : a package used to extend ocaml-gettext. It is reserved for very
Packit 802e35
              particular functions (such as creating a new <varname>realize</varname> function),
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              gettext.extract<footnoteref linkend="advanced-features"/>: a package that enables 
Packit 802e35
              to create special <command>camlp4</command> program (such as 
Packit 802e35
              <command>ocaml-xgettext</command>),
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              gettext-stub: an implementation of ocaml-gettext using gettext,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              gettext-camomile: an implementation of ocaml-gettext using camomile. It is a pure
Packit 802e35
              ocaml implementation.
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        In order to link an application or a library using ocaml-gettext, you should link with one of : gettext.base,
Packit 802e35
        gettext-camomile or gettext-stub.
Packit 802e35
      </para>
Packit 802e35
      <example>
Packit 802e35
        <title><filename>Makefile</filename></title>
Packit 802e35
        <programlisting>&makefile;</programlisting>
Packit 802e35
      </example>
Packit 802e35
    </section>
Packit 802e35
    <section>
Packit 802e35
      <title>Library</title>
Packit 802e35
      <para>
Packit 802e35
        Library should use the module <varname>Gettext.Library</varname>. It doesn't need any real implementation 
Packit 802e35
        of ocaml-gettext. By this way, you can let the library user choose the most appropriate ocaml-gettext 
Packit 802e35
        implementation. This point is essential : a library could be used as well in a GUI program or in short run
Packit 802e35
        command line program. These two examples don't require the same kind of implementation at all: GUI program 
Packit 802e35
        loads most of their translated strings, command line program only use one among them. So by using the module
Packit 802e35
        <varname>Gettext.Library</varname> framework, you don't restrict programs to use one particular implementation 
Packit 802e35
        of ocaml-gettext.
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        The library should define, using the functor <varname>Init</varname> provided: 
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              his textdomain through the <varname>textdomain</varname> value,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              his dependencies through the <varname>dependencies</varname> value,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              if needed his charset and directory binding (but it is not recommended to do so).
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        After having instantiated the module <varname>Gettext.Library</varname> with the appropriate <varname>Init</varname>, 
Packit 802e35
        you should use the function provided : 
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <varname>s_</varname> : for translating singular strings,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <varname>f_</varname> : for translating singular strings which will be used with <varname>Printf</varname> 
Packit 802e35
              function
Packit 802e35
              <footnote id="printf-strings">
Packit 802e35
                <para>
Packit 802e35
                  Strings which should be used by <varname>Printf</varname> function are checked to be sure
Packit 802e35
                  that the returned strings are equivalent to the provided English string. In particular, every 
Packit 802e35
                  "%"-symbol should be the same in the provided string and the returned string. If not,
Packit 802e35
                  it is the untranslated string which is returned.
Packit 802e35
                </para>
Packit 802e35
              </footnote>,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <varname>sn_</varname> : for translating plural strings,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              <varname>fn_</varname> : for translating plural strings which will be used with <varname>Printf</varname>
Packit 802e35
              function<footnoteref linkend="printf-strings"/>,
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
      </para>
Packit 802e35
      <warning>
Packit 802e35
        <para>
Packit 802e35
          You must keep the function name <varname>s_</varname>, <varname>f_</varname>, <varname>sn_</varname> and <varname>fn_</varname>.
Packit 802e35
          The extraction of translatable strings matches these names. If you don't keep it, the extraction of translatable strings
Packit 802e35
          will fail.
Packit 802e35
        </para>
Packit 802e35
      </warning>
Packit 802e35
      <example>
Packit 802e35
        <title><filename>library.ml</filename></title>
Packit 802e35
        <programlisting>&library-ml;</programlisting>
Packit 802e35
      </example>
Packit 802e35
      <example>
Packit 802e35
        <title><filename>libraryGettext.ml</filename></title>
Packit 802e35
        <programlisting>&library-gettext-ml;</programlisting>
Packit 802e35
      </example>
Packit 802e35
      <para>
Packit 802e35
        All the calls to translation functions, use the textdomain provided in <varname>Init</varname>.
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        The only constraint when using ocaml-gettext in your library is to provide an access to the value 
Packit 802e35
        <varname>Gettext.Library.init</varname>. This value is used as dependencies for other libraries and
Packit 802e35
        programs that depend on it. For example, since you use the library ocaml-gettext, your primary dependency
Packit 802e35
        is the function <varname>init</varname> provided in the top level (the function <varname>Gettext.string_of_exception</varname>
Packit 802e35
        is localised).
Packit 802e35
      </para>
Packit 802e35
      <warning>
Packit 802e35
        <para>
Packit 802e35
          If you distribute your library, don't forget to mention that ocaml-gettext will only be able to translate
Packit 802e35
          the string defined in your library, if and only if the MO file build with is also installed. If not installed
Packit 802e35
          ocaml-gettext is useless.
Packit 802e35
        </para>
Packit 802e35
      </warning>
Packit 802e35
    </section>
Packit 802e35
    <section>
Packit 802e35
      <title>Program</title>
Packit 802e35
      <para>
Packit 802e35
        Program should use ocaml-gettext just as libraries do. The only difference lies in the fact that you should provide 
Packit 802e35
        a <varname>realize</varname> function in the <varname>InitProgram</varname>. The other difference is that the 
Packit 802e35
        <varname>init</varname> value is not a dependency that should be used by other program. It is a <varname>Arg</varname>
Packit 802e35
        usable value. It allows user to define some important parameters. 
Packit 802e35
      </para>
Packit 802e35
      <example>
Packit 802e35
        <title><filename>program.ml</filename></title>
Packit 802e35
        <programlisting>&program-ml;</programlisting>
Packit 802e35
      </example>
Packit 802e35
      <example>
Packit 802e35
        <title><filename>programGettext.ml</filename></title>
Packit 802e35
        <programlisting>&program-gettext-ml;</programlisting>
Packit 802e35
      </example>
Packit 802e35
      <example>
Packit 802e35
        <title>Output of <command>program <option>--help</option></command></title>
Packit 802e35
        <screen>
Packit 802e35
          <prompt>$></prompt><command>./program <option>--help</option></command>
Packit 802e35
          <computeroutput>
Packit 802e35
              --my-name name                      Your name. Default : ""
Packit 802e35
              --gettext-failsafe {ignore|inform-stderr|raise-exception}  
Packit 802e35
                                                  Choose how to handle failure in ocaml-gettext. Default: ignore.
Packit 802e35
              --gettext-disable                   Disable the translation perform by ocaml-gettext. Default: enable.
Packit 802e35
              --gettext-domain-dir textdomain dir Set a dir to search ocaml-gettext files for the specified domain. Default: [  ].
Packit 802e35
              --gettext-dir dir                   Add a search dir for ocaml-gettext files. Default: [ "/usr/share/locale"; 
Packit 802e35
                                                  "/usr/local/share/locale" ].
Packit 802e35
              --gettext-language language         Set the default language for ocaml-gettext. Default: (none).
Packit 802e35
              --gettext-codeset codeset           Set the default codeset for outputting string with ocaml-gettext. Default: ISO-8859-1.
Packit 802e35
              -help                               Display this list of options
Packit 802e35
              --help                              Display this list of options
Packit 802e35
          </computeroutput>
Packit 802e35
        </screen>
Packit 802e35
      </example>
Packit 802e35
      <para>
Packit 802e35
        If you want to include a manpage (or info file), that describes the command line option of ocaml-gettext, you should use the Docbook 
Packit 802e35
        XML fragment distributed with this application. Docbook should be enough generic to allow you to link it into your documentation. 
Packit 802e35
        If you don't want to link it with your documentation, you can refer to <link linkend="ocaml-gettext-options">
Packit 802e35
        ocaml-gettext-options manpage</link>.
Packit 802e35
      </para>
Packit 802e35
      <example>
Packit 802e35
        <title><filename>program.xml</filename> : Docbook manpage</title>
Packit 802e35
        <programlisting>&program-xml;</programlisting>
Packit 802e35
      </example>
Packit 802e35
Packit 802e35
      <example>
Packit 802e35
        <title><filename>Makefile</filename> : Makefile for docbook manpage</title>
Packit 802e35
        <programlisting>&makefile-doc;</programlisting>
Packit 802e35
      </example>
Packit 802e35
Packit 802e35
      <para>
Packit 802e35
        You should take care of what implementation of ocaml-gettext you are using. In order to choose the right implementation
Packit 802e35
        you should consider your program and every characteristic of it (how many strings does it need to fetch? Does it use already
Packit 802e35
        a C library that link with gettext?).
Packit 802e35
        
Packit 802e35
          <title>Characteristics of ocaml-gettext implementation.</title>
Packit 802e35
          <tgroup cols="3">
Packit 802e35
            
Packit 802e35
              <row>
Packit 802e35
                <entry>Implementation</entry>
Packit 802e35
                <entry>Characteristics</entry>
Packit 802e35
                <entry>Use</entry>
Packit 802e35
              </row>
Packit 802e35
            
Packit 802e35
            
Packit 802e35
              <row>
Packit 802e35
                <entry>GettextCamomile.Map</entry>
Packit 802e35
                <entry>
Packit 802e35
                  <itemizedlist>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Pure OCaml implementation,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Full load of all MO files before any translation,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Use OCaml standard <varname>Map</varname>.
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                  </itemizedlist>
Packit 802e35
                </entry>
Packit 802e35
                <entry>
Packit 802e35
                  <itemizedlist>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Pure OCaml program,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Program that requires to translate a lot of strings,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Threaded program (since it use OCaml Map, it should be thread safe without
Packit 802e35
                        problem).
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                  </itemizedlist>
Packit 802e35
                </entry>
Packit 802e35
              </row>
Packit 802e35
              <row>
Packit 802e35
                <entry>GettextCamomile.Hashtbl</entry>
Packit 802e35
                <entry>
Packit 802e35
                  <itemizedlist>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Pure OCaml implementation,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Full load of all MO file before any translation,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Use OCaml standard <varname>Hashtbl</varname>.
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                  </itemizedlist>
Packit 802e35
                </entry>
Packit 802e35
                <entry>
Packit 802e35
                  <itemizedlist>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Pure OCaml program,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Program that requires to translate a lot of strings,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Should work with threaded program, provided that the <varname>Hashtbl</varname> 
Packit 802e35
                        works in threaded environment.
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                  </itemizedlist>
Packit 802e35
                </entry>
Packit 802e35
              </row>
Packit 802e35
              <row>
Packit 802e35
                <entry>GettextCamomile.Open</entry>
Packit 802e35
                <entry>
Packit 802e35
                  <itemizedlist>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Pure OCaml implementation,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Load strings from MO if needed,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Use OCaml standard <varname>Hashtbl</varname>,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Use a dichotomic search for the strings,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Compute MO file to open at initialisation,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Open a file when fetching string,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Doesn't memorise already translated strings,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Implementation design copied from gettext.
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                  </itemizedlist>
Packit 802e35
                </entry>
Packit 802e35
                <entry>
Packit 802e35
                  <itemizedlist>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Pure OCaml program,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Program that require to translate very few strings,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Should work with threaded program, provided that <varname>open_in</varname> function call
Packit 802e35
                        work.
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                  </itemizedlist>
Packit 802e35
                </entry>
Packit 802e35
              </row>
Packit 802e35
              <row>
Packit 802e35
                <entry>GettextStub.Native</entry>
Packit 802e35
                <entry>
Packit 802e35
                  <itemizedlist>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Native gettext library,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Partial load of all MO file before any translation, use
Packit 802e35
                        <varname>mmap</varname>.
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                  </itemizedlist>
Packit 802e35
                </entry>
Packit 802e35
                <entry>
Packit 802e35
                  <itemizedlist>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        OCaml program that uses library compiled with gettext,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Should work with threaded program, provided that the
Packit 802e35
                        <varname>gettext</varname> work in threaded
Packit 802e35
                        environment. To support a language, the corresponding
Packit 802e35
                        locales need to be generated.
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                  </itemizedlist>
Packit 802e35
                </entry>
Packit 802e35
              </row>
Packit 802e35
              <row>
Packit 802e35
                <entry>GettextStub.Preload</entry>
Packit 802e35
                <entry>
Packit 802e35
                  <itemizedlist>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Native gettext library,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Forced load of all MO file before any translation, the preload is realized by trying to load
Packit 802e35
                        the string "" for all the textdomain defined.
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                  </itemizedlist>
Packit 802e35
                </entry>
Packit 802e35
                <entry>
Packit 802e35
                  <itemizedlist>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        OCaml program that uses library compiled with gettext,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Program that needs to translate a lot of strings,
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                    <listitem>
Packit 802e35
                      <para>
Packit 802e35
                        Should work with threaded program, provided that the
Packit 802e35
                        <varname>gettext</varname> work in threaded
Packit 802e35
                        environment. To support a language, the corresponding
Packit 802e35
                        locales need to be generated.
Packit 802e35
                      </para>
Packit 802e35
                    </listitem>
Packit 802e35
                  </itemizedlist>
Packit 802e35
                </entry>
Packit 802e35
              </row>
Packit 802e35
            
Packit 802e35
          </tgroup>
Packit 802e35
        
Packit 802e35
      </para>
Packit 802e35
    </section>
Packit 802e35
    <section>
Packit 802e35
      <title>Graphical user interface</title>
Packit 802e35
      <para>
Packit 802e35
        Graphical user interface works just as a program or a library. The only difference is that the file which contains
Packit 802e35
        the graphical user interface should not be written in OCaml. You have two cases :
Packit 802e35
        <itemizedlist>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              You use glade file, so you should extract the strings from this file using <command>xgettext</command>
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
          <listitem>
Packit 802e35
            <para>
Packit 802e35
              You use a hand written interface written in OCaml, the extraction of the strings follow the same way
Packit 802e35
              as a library.
Packit 802e35
            </para>
Packit 802e35
          </listitem>
Packit 802e35
        </itemizedlist>
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        You should use the first alternative : it is easier for a translator to extract strings, without having to compile
Packit 802e35
        your application (it enables translators that don't know OCaml to help you). In order to do so, you should use the native
Packit 802e35
        <command>xgettext</command> binary (provided with gettext). It should support the format of the translatable strings found
Packit 802e35
        in your GUI file (for example, <command>xgettext</command> supports glade file).
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        But for now you can only use the second alternative, because OCaml is not yet supported in <command>xgettext</command>. This
Packit 802e35
        should be fixed, once <command>ocaml-gettext</command> will be enough stable to become a back-end for <command>xgettext</command>
Packit 802e35
        <footnote>
Packit 802e35
          <para>
Packit 802e35
            For now, extracting strings from OCaml source file and glade file, requires to patch <productname>gettext</productname>. 
Packit 802e35
            You can find this path in patches. This patch will be sent to upstream author once it will be considered enough stable.
Packit 802e35
          </para>
Packit 802e35
        </footnote>.
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        In the two cases, you just have to add your GUI file (in OCaml or native form) to <filename>POTFILES</filename>.
Packit 802e35
      </para>
Packit 802e35
      <para>
Packit 802e35
        Graphical user interfaces are good candidates for settings a fixed <varname>Init.codeset</varname>. Typically, GTK2 interfaces require 
Packit 802e35
        to have these parameters set to UTF-8.
Packit 802e35
      </para>
Packit 802e35
Packit 802e35
      <example>
Packit 802e35
        <title><filename>gui.ml</filename></title>
Packit 802e35
        <programlisting>&gui-ml;</programlisting>
Packit 802e35
      </example>
Packit 802e35
Packit 802e35
      <example>
Packit 802e35
        <title><command>./program --gettext-dir ../build/share/locale --gettext-lang C --my-name Sylvain</command></title>
Packit 802e35
        <screenshot>
Packit 802e35
          <graphic fileref="gui.png" format="PNG"/>
Packit 802e35
        </screenshot>
Packit 802e35
      </example>
Packit 802e35
Packit 802e35
      <example>
Packit 802e35
        <title><command>./program --gettext-dir ../build/share/locale --gettext-lang fr --my-name Sylvain</command></title>
Packit 802e35
        <screenshot>
Packit 802e35
          <graphic fileref="gui-fr.png" format="PNG"/>
Packit 802e35
        </screenshot>
Packit 802e35
      </example>
Packit 802e35
Packit 802e35
      <warning>
Packit 802e35
        <para>
Packit 802e35
          If you build <productname>lablgtk</productname> application, you must keep in mind that some locale settings are made
Packit 802e35
          in the function <varname>GMain.Init</varname>. Those settings could override those done through the command line
Packit 802e35
          options. In order to correctly use ocaml-gettext, you must be sure to call <varname>GMain.Init</varname> before 
Packit 802e35
          using <varname>Arg.parse</varname> with the ocaml-gettext args.
Packit 802e35
        </para>
Packit 802e35
      </warning>
Packit 802e35
Packit 802e35
    </section>
Packit 802e35
  </chapter>
Packit 802e35
  <chapter>
Packit 802e35
    <title>Translating ocaml-gettext programs and libraries</title>
Packit 802e35
    <para>
Packit 802e35
      ocaml-gettext has been built around gettext. This allows translators to use exactly the same technics as they should
Packit 802e35
      use with gettext. All the documentation required for translating can be found in <link linkend="gettext-documentation">
Packit 802e35
      gettext documentation</link>.
Packit 802e35
    </para>
Packit 802e35
    <para>
Packit 802e35
      It is recommended to use GUI which allows easier translation such as : 
Packit 802e35
      <itemizedlist>
Packit 802e35
        <listitem>
Packit 802e35
          <para>
Packit 802e35
            <ulink url="&site-gtranslator;">gtranslator</ulink>,
Packit 802e35
          </para>
Packit 802e35
        </listitem>
Packit 802e35
        <listitem>
Packit 802e35
          <para>
Packit 802e35
            <ulink url="&site-kbabel;">kbabel</ulink>.
Packit 802e35
          </para>
Packit 802e35
        </listitem>
Packit 802e35
      </itemizedlist>
Packit 802e35
    </para>
Packit 802e35
  </chapter>
Packit 802e35
  <chapter>
Packit 802e35
    <title>Using ocaml-gettext programs</title>
Packit 802e35
    <para>
Packit 802e35
      ocaml-gettext program can be used just as any OCaml program. The only difference with standard OCaml program is that
Packit 802e35
      they come with a bunch of command line options which are specific to OCaml program. In most cases, you just have to define
Packit 802e35
      a well suited <varname>LC_ALL</varname> or <varname>LANG</varname> environment variable. Since ocaml-gettext is compatible
Packit 802e35
      with gettext, if your environment variable works with gettext, it should also works with ocaml-gettext.
Packit 802e35
    </para>
Packit 802e35
    <para>
Packit 802e35
      You can find more details in the <link linkend="gettext-documentation">gettext documentation</link> or in the 
Packit 802e35
      linkend="ocaml-gettext-options">ocaml-gettext-options manpage</link>.
Packit 802e35
    </para>
Packit 802e35
  </chapter>
Packit 802e35
  <appendix>
Packit 802e35
    <title>Tips and tricks</title>
Packit 802e35
Packit 802e35
    <section>
Packit 802e35
      <title>Adding gettext support without depending on ocaml-gettext</title>
Packit 802e35
Packit 802e35
      <para>
Packit 802e35
        You want to 'gettextify' your program, adding 's_' and 'f_'
Packit 802e35
        annotations throughout. However now your program has an additional
Packit 802e35
        dependency, ocaml-gettext. You can make ocaml-gettext optional by
Packit 802e35
        creating a set of dummy functions which do nothing:
Packit 802e35
      </para>
Packit 802e35
Packit 802e35
      <example>
Packit 802e35
        <title><filename>prog_gettext.ml</filename></title>
Packit 802e35
        <programlisting>
Packit 802e35
          (* This file is generated automatically by ./configure. *)
Packit 802e35
          module Gettext = 
Packit 802e35
          struct
Packit 802e35
            external s_ : string -> string = "%identity"
Packit 802e35
            external f_ : ('a -> 'b, 'c, 'd) format -> ('a -> 'b, 'c, 'd) format = "%identity"
Packit 802e35
            
Packit 802e35
            let sn_ : string -> string -> int -> string = 
Packit 802e35
              fun s p n -> 
Packit 802e35
                if n = 1 then s else p
Packit 802e35
                
Packit 802e35
            let fn_ : ('a -> 'b, 'c, 'd) format -> ('a -> 'b, 'c, 'd) format -> int -> ('a -> 'b, 'c, 'd) format = 
Packit 802e35
              fun s p n -> 
Packit 802e35
                if n = 1 then s else p
Packit 802e35
          end
Packit 802e35
        </programlisting>
Packit 802e35
      </example>
Packit 802e35
Packit 802e35
      <para>
Packit 802e35
        You have to arrange for your configure script to place the above
Packit 802e35
        content or the real ProgramGettext module into 'prog_gettext.ml',
Packit 802e35
        depending on whether it detects that ocaml-gettext is installed
Packit 802e35
        (eg. using 'ocamlfind query gettext' or some other method).
Packit 802e35
      </para>
Packit 802e35
    </section>
Packit 802e35
  </appendix>
Packit 802e35
  <appendix>
Packit 802e35
    <title>Links</title>
Packit 802e35
    <itemizedlist>
Packit 802e35
      <listitem>
Packit 802e35
        <para>
Packit 802e35
          <ulink url="&site-ocaml;">OCaml website</ulink>
Packit 802e35
        </para>
Packit 802e35
      </listitem>
Packit 802e35
      <listitem>
Packit 802e35
        <para>
Packit 802e35
          <ulink url="&site-gettext;">Gettext website</ulink>
Packit 802e35
        </para>
Packit 802e35
      </listitem>
Packit 802e35
      <listitem id="gettext-documentation">
Packit 802e35
        <para>
Packit 802e35
          <ulink url="&site-documentation-gettext;">Gettext documentation</ulink>
Packit 802e35
        </para>
Packit 802e35
      </listitem>
Packit 802e35
      <listitem>
Packit 802e35
        <para>
Packit 802e35
          <ulink url="&site-camomile;">Camomile website</ulink>
Packit 802e35
        </para>
Packit 802e35
      </listitem>
Packit 802e35
      <listitem>
Packit 802e35
        <para>
Packit 802e35
          <ulink url="&site-ocaml-fileutils;">ocaml-fileutils website</ulink>
Packit 802e35
        </para>
Packit 802e35
      </listitem>
Packit 802e35
      <listitem>
Packit 802e35
        <para>
Packit 802e35
          <ulink url="&site-ounit;">OUnit website</ulink>
Packit 802e35
        </para>
Packit 802e35
      </listitem>
Packit 802e35
      <listitem>
Packit 802e35
        <para>
Packit 802e35
          <ulink url="&site-ocaml-benchmark;">ocaml-benchmark website</ulink>
Packit 802e35
        </para>
Packit 802e35
      </listitem>
Packit 802e35
      <listitem>
Packit 802e35
        <para>
Packit 802e35
          <ulink url="&site-docbook;">Docbook website</ulink>
Packit 802e35
        </para>
Packit 802e35
      </listitem>
Packit 802e35
    </itemizedlist>
Packit 802e35
  </appendix>
Packit 802e35
  <appendix>
Packit 802e35
    <title>Manpages</title>
Packit 802e35
    <refentry>
Packit 802e35
      &ocaml-gettext-manual;
Packit 802e35
    </refentry>
Packit 802e35
    <refentry>
Packit 802e35
      &ocaml-xgettext-manual;
Packit 802e35
    </refentry>
Packit 802e35
    <refentry id="ocaml-gettext-options">
Packit 802e35
      &ocaml-gettext-options-manual;
Packit 802e35
    </refentry>
Packit 802e35
  </appendix>
Packit 802e35
</book>