<?xml version="1.0"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
  <!ENTITY lib "libtranslate">
  <!ENTITY rfc3066-table SYSTEM "rfc3066-table.xml">
  <!ENTITY version SYSTEM "version.xml">

  <!ENTITY example-application SYSTEM "example-application.c.xml">
  <!ENTITY example-service SYSTEM "example-service.c.xml">

  <!ENTITY translate SYSTEM "xml/translate.xml">
  <!ENTITY translate-common SYSTEM "xml/translate-common.xml">
  <!ENTITY TranslatePair SYSTEM "xml/translate-pair.xml">
  <!ENTITY TranslateService SYSTEM "xml/translate-service.xml">
  <!ENTITY TranslateSession SYSTEM "xml/translate-session.xml">
  <!ENTITY translate-util SYSTEM "xml/translate-util.xml">

  <!ENTITY index-Object-Tree SYSTEM "xml/tree_index.sgml">
]>

<!-- Copyright (C) 2005 Jean-Yves Lefort -->
<!-- All rights reserved. -->

<!-- Redistribution and use in source (SGML DocBook) and 'compiled' -->
<!-- forms (SGML, HTML, PDF, PostScript, RTF and so forth) with or -->
<!-- without modification, are permitted provided that the following -->
<!-- conditions are met: -->
<!-- 1. Redistributions of source code (SGML DocBook) must -->
<!--    retain the above copyright notice, this list of conditions and -->
<!--    the following disclaimer as the first lines of this file -->
<!--    unmodified. -->
<!-- 2. Redistributions in compiled form (transformed to other -->
<!--    DTDs, converted to PDF, PostScript, RTF and other formats) -->
<!--    must reproduce the above copyright notice, this list of -->
<!--    conditions and the following disclaimer in the documentation -->
<!--    and/or other materials provided with the distribution. -->

<!-- THIS DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND -->
<!-- CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -->
<!-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -->
<!-- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -->
<!-- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -->
<!-- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -->
<!-- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -->
<!-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -->
<!-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -->
<!-- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR -->
<!-- TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -->
<!-- THE USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY -->
<!-- OF SUCH DAMAGE. -->

<book id="index">
  <bookinfo>
    <title>&lib; Reference Manual</title>
    <releaseinfo>for &lib; &version;</releaseinfo>
    <date>January 15, 2005</date>
    <author>
      <firstname>Jean-Yves</firstname>
      <surname>Lefort</surname>
      <email>jylefort@brutele.be</email>
    </author>
  </bookinfo>

  <chapter id="overview">
    <title>Overview</title>
    <para>
      &lib; is a library for translating text and web pages between
      natural languages. Its modular infrastructure allows to
      implement new translation services separately from the core
      library.
    </para>
    <para>
      &lib; is shipped with a generic module supporting web-based translation services such as
      <ulink url="http://babelfish.altavista.com" type="http">Babel Fish</ulink>,
      <ulink url="http://www.google.com/language_tools" type="http">Google Language Tools</ulink>
      and <ulink url="http://www.systransoft.com" type="http">SYSTRAN</ulink>.
      Moreover, the generic module allows to add new services simply
      by adding a few lines to a XML file (see the
      <citerefentry><refentrytitle>services.xml</refentrytitle><manvolnum>5</manvolnum></citerefentry>
      manual page).
    </para>
    <para>
      &lib; is implemented on top of the <ulink
      url="http://developer.gnome.org/doc/API/2.0/gobject"
      type="http">GLib Object System</ulink>.
    </para>

    <section>
      <title>Conventions</title>
      <itemizedlist>
	<listitem>
	  <para>
	    Unless noted otherwise, strings passed to library functions
	    must be encoded in UTF-8.
	  </para>
	</listitem>
	<listitem>
	  <para>
	    Unless noted otherwise, strings returned by &lib; are
	    encoded in UTF-8.
	  </para>
	</listitem>
	<listitem>
	  <para>
	    Unless noted otherwise, &lib; is thread-safe.
	  </para>
	</listitem>
      </itemizedlist>
    </section>

    <section>
      <title>Compiling &lib; Applications</title>
      <section>
	<title>Compiling on UNIX</title>
	<para>
	  To compile a &lib; application, you need to tell the
	  compiler where to find the &lib; header files and
	  libraries. This is done with the
	  <command>pkg-config</command> utility.
	</para>
	<para>
	  The following interactive shell session demonstrates how
	  <command>pkg-config</command> is used:
	  <programlisting>$ pkg-config --cflags libtranslate
-I/usr/local/include/libtranslate -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include
$ pkg-config --libs libtranslate
-L/usr/local/lib -ltranslate -lgobject-2.0 -lglib-2.0 -liconv</programlisting>
	</para>
	<para>
	  The simplest way to compile a program is to use the
	  "backticks" feature of the shell. If you enclose a command
	  in backticks (<emphasis>not single quotes</emphasis>), then
	  its output will be substituted into the command line before
	  execution. So to compile a &lib; Hello World, you would type
	  the following:
	  <programlisting>$ cc `pkg-config --cflags --libs libtranslate` hello.c -o hello</programlisting>
	</para>
      </section>
      <section>
	<title>Compiling on UNIX With Autoconf and Automake</title>
	<para>
	  To compile a &lib; application using <ulink
	  url="http://www.gnu.org/software/autoconf" type="http">GNU
	    Autoconf</ulink> and <ulink
	    url="http://www.gnu.org/software/automake" type="http">GNU
	    Automake</ulink>, insert the following line at the
	  appropriate place in the <filename>configure.ac</filename>
	  file:
	  <programlisting>PKG_CHECK_MODULES(LIBTRANSLATE, libtranslate,, [AC_MSG_ERROR([unable to find libtranslate])])</programlisting>
	  and insert the following lines in the appropriate
	  <filename>Makefile.am</filename> file:
	  <programlisting>bin_PROGRAMS = hello
hello_SOURCES = hello.c
hello_CPPFLAGS = $(LIBTRANSLATE_CFLAGS)
hello_LDFLAGS = $(LIBTRANSLATE_LIBS)</programlisting>
	</para>
      </section>
    </section>

    <section id="compiling-modules">
      <title>Compiling &lib; Modules</title>
      <section>
	<title>Compiling on UNIX</title>
	<para>
	  To compile a &lib; module, you need to tell the compiler
	  where to find the &lib; header files. This is done with the
	  <command>pkg-config</command> utility.
	</para>
	<para>
	  For instance, to compile a &lib; Hello World module, you
	  would type the following:
	  <programlisting>$ cc `pkg-config --cflags libtranslate` -shared -fPIC hello.c -o hello.so</programlisting>
	</para>
      </section>
      <section>
	<title>Compiling on UNIX With Autoconf, Automake and Libtool</title>
	<para>
	  To compile a &lib; module using <ulink
	  url="http://www.gnu.org/software/autoconf" type="http">GNU
	  Autoconf</ulink>, <ulink
	  url="http://www.gnu.org/software/automake" type="http">GNU
	  Automake</ulink> and <ulink
	  url="http://www.gnu.org/software/libtool" type="http">GNU
	  Libtool</ulink>, insert the following line at the
	  appropriate place in the <filename>configure.ac</filename>
	  file:
	  <programlisting>PKG_CHECK_MODULES(LIBTRANSLATE, libtranslate,, [AC_MSG_ERROR([unable to find libtranslate])])</programlisting>
	  and insert the following lines in the appropriate
	  <filename>Makefile.am</filename> file:
	  <programlisting>modulesdir = $(libdir)/libtranslate/modules
modules_LTLIBRARIES = hello.la
hello_la_SOURCES = hello.c
hello_la_CPPFLAGS = $(LIBTRANSLATE_CFLAGS)
hello_la_LDFLAGS = -avoid-version -module</programlisting>
	</para>
      </section>
      <section>
	<title>Module Search Paths</title>
	<para>
	  &lib; loads modules from <filename
	  class="directory"><replaceable>prefix</replaceable>/libtranslate/modules</filename>
	  (where <replaceable>prefix</replaceable> is the prefix where
	  &lib; is installed) and from <filename
	  class="directory"><replaceable>~</replaceable>/.libtranslate/modules</filename>
	  (where <replaceable>~</replaceable> is the path to your home
	  directory).  Filenames not having the system-specific shared
	  object extension (usually .so) are ignored.
	</para>
      </section>
    </section>
  </chapter>

  <chapter id="tutorials">
    <title>Tutorials</title>
    <section>
      <title>Translating Text or Web Pages</title>
      <para>
	To translate text or web pages, you need to initialize &lib;
	with a call to <link
	linkend="translate-init">translate_init()</link>, create a new
	session using <link
	linkend="translate-session-new">translate_session_new()</link>,
	and call the appropriate translation function, <link
	linkend="translate-session-translate-text">translate_session_translate_text()</link>
	or <link
	linkend="translate-session-translate-web-page">translate_session_translate_web_page()</link>.
      </para>
      <example>
	<title>A Simple Command-Line Translator</title>
	<para>
	  The following example demonstrates how to use &lib; for
	  creating a simple command-line text and web page translator.
	</para>
	<para>
	  The source code of this example is available in the &lib;
	  source distribution
	  (<filename>docs/reference/example-application.c</filename>),
	  and is reproduced below.
	  On UNIX, compile it as follows:
	  <programlisting>$ cc `pkg-config --cflags --libs libtranslate` example-application.c -o example-application</programlisting>
	</para>
	<programlisting>&example-application;</programlisting>
      </example>
    </section>

    <section>
      <title>Implementing Translation Services</title>
      <para>
	To implement a translation service, you need to create a
	subclass of <link
	linkend="TranslateService">TranslateService</link>, create an
	instance of your subclass with g_object_new(), and add the
	service using <link
	linkend="translate-add-service">translate_add_service()</link>.
	<note>
	  <title>Web-Based Services</title>
	  <para>
	    If you are implementing support for a web-based service,
	    just adding a definition to the <filename>services.xml</filename>
	    file (without having to resort to C code) might be sufficient.
	    See the
	    <citerefentry><refentrytitle>services.xml</refentrytitle><manvolnum>5</manvolnum></citerefentry>
	    manual page.
	  </para>
	</note>
      </para>
      <example>
	<title>A Simple Service for Reversing Text</title>
	<para>
	  The following example demonstrates how to create an add-on
	  service for &lib;, and compile it either as a module or as a
	  standalone application.
	</para>
	<para>
	  The source code of this example is available in the &lib;
	  source distribution
	  (<filename>docs/reference/example-service.c</filename>),
	  and is reproduced below.
	  To build a module on UNIX, compile the source as follows:
	  <programlisting>$ cc `pkg-config --cflags libtranslate` -shared -fPIC example-service.c -o example-service.so</programlisting>
	  To build a standalone application on UNIX, compile the
	  source as follows:
	  <programlisting>$ cc `pkg-config --cflags --libs libtranslate` -DSTANDALONE example-service.c -o example-service</programlisting>
	</para>
	<programlisting>&example-service;</programlisting>
      </example>
    </section>
  </chapter>

  <chapter id="api-reference">
    <title>API Reference</title>
    <section>
      <title>Object Hierarchy</title>
      &index-Object-Tree;
    </section>
      
    &translate;
    &translate-common;
    &TranslatePair;
    &TranslateService;
    &TranslateSession;
    &translate-util;
  </chapter>

  <appendix id="rfc3066-builtin">
    <title>Built-in RFC 3066 Tag to Name Mappings</title>
    <para>
      The following tag to name mappings are built into &lib;. Calling
      <link
      linkend="translate-get-language-name">translate_get_language_name()</link>
      for any tag of this table will return its localized language
      name.
    </para>
    &rfc3066-table;
  </appendix>
 
  <index/>
</book>
