Next: , Previous: Invoking the transtalo Command, Up: Top



3 Using the User Library

The user library is an easy to use C interface to the Transtalo Translation System. It actually is a convience library, since it is possible to call the translation modules by hand.

The transtalo user library consists of a number of functions, enumerations and defines. Besides the translation, it also allows looking up information about the available translation modules.

The library's name is libtranstalo, you can use it by adding -ltranstalo to the command line while linking.

3.1 The Functions

3.1.1 transtalo_translate

     #include <transtalo.h>
     
     int transtalo_translate(char *source_lang,
       char *source_lang_dialect, char *dest_lang, char *dest_lang_dialect,
       char *sentence, char *target, int verbosity);

This function is the library equivalent of the translate command from the transtalo command line interface.

It translates sentence from source_lang with source_lang_dialect as dialect into dest_lang with dest_lang_dialect as dialect and puts it into target.

If source_lang_dialect and/or dest_lang_dialect are NULL, they will be ignored. target must be an initialized string (1000 characters—this will change in the future).

3.1.2 transtalo_lang2xml

     #include <transtalo.h>
     
     int transtalo_lang2xml(char *source_lang,
       char *source_lang_dialect, char *sentence, char *xml_file,
       int verbosity);

This function is the library equivalent of the lang2xml command from the transtalo command line interface.

It translates sentence from source_lang with source_lang_dialect as dialect into an XML file and puts it into the xml_file file.

If source_lang_dialect is NULL, it will be ignored.

3.1.3 transtalo_xml2lang

     #include <transtalo.h>
     
     int transtalo_xml2lang(char *xml_file, char *dest_lang,
       char *dest_lang_dialect, char *target, int verbosity);

This function is the library equivalent of the xml2lang command from the transtalo command line interface.

It translated the xml_file XML file into dest_lang with dest_lang_dialect as dialect and puts it into target.

If dest_lang_dialect is NULL, it will be ignored. target must be an initialized string (1000 characters—this will change in the future).

3.1.4 transtalo_get_modules

     #include <transtalo.h>
     
     void transtalo_get_modules(char *buffer[], int type);

Get all supported modules of type and put it into buffer. type is one out of TS_INPUT_MODULE and TS_OUTPUT_MODULE.

buffer must be an initialized array of pointers, for example:

     char *modules[100];

This will change in the future.

3.1.5 transtalo_get_long_name

     #include <transtalo.h>
     
     char *transtalo_get_long_name(const char *lang);

This function returns the full name for the ISO language code in lang.

3.1.6 transtalo_get_info

     #include <transtalo.h>
     
     TRANSTALO_MODULE_INFO *transtalo_get_info(int module_type,
     char *language);

This function puts information about the specified translation module into a pointer to a TRANSTALO_MODULE_INFO structure.

module_type is one out of TS_INPUT_MODULE and TS_OUTPUT_MODULE, and specifies wether you want respectively an input or an output module.

language is a string containing the language code you want to get the information from.

The function returns a struct TRANSTALO_MODULE_INFO declared in <transtalo.h> as

     typedef struct {
       char *short_language;
       char *long_language;
       char *version;
       int state;
       char *authors[16];
       char *contributors_name[16];
       int *contributors_function[16];
     } TRANSTALO_MODULE_INFO;

In the struct state defines how well the module can translate, and is a value from 0 up to 5.

contributors_function is an array which defines the functions of the contributors, anolog to the ones in contributors_name, and is: TS_FUNCTION_UNKNOWN if the function was not specified, TS_FUNCTION_BUG_REPORT if it was a bug reporter, TS_FUNCTION_FEATURE_REQUEST if he or she requested a function, TS_FUNCTION_PATCH if it was someone who provided a patch.

3.1.7 transtalo_get_release

     #include <transtalo.h>
     
     char *transtalo_get_release();

Returns the release information of the current core library, for example: “Transtalo Translation System, release 0.3.0”.

3.1.8 transtalo_get_copyright

     #include <transtalo.h>
     
     char *transtalo_get_copyright();

Returns copyright information of the current core library, for example: “Copyright (C) 2004, 2005 the Transtalo team”.

3.1.9 transtalo_get_version

     #include <transtalo.h>
     
     char *transtalo_get_version();

Returns the version of the current core library, for example: “0.3.0”.

3.2 Verbosity

The verbose variable that is uses in some functions can be one out of:

TS_QUIET
Quiet, no messages are output
TS_NORMAL
Normal, only warnings and errors are output
TS_VERBOSE
Verbose, warnings and errors are output, but information messages too

3.3 Return Values

The first 3 functions that deal with a translation return an integer that is defined as one out of the following:

TS_NO_ERROR
no errors (value 0)
TS_SOURCELANG_MISSING
the source lang is missing
TS_SOURCELANG_DIALECT_MISSING
the source lang dialect is missing
TS_DESTLANG_MISSING
the destination lang is missing
TS_DESTLANG_DIALECT_MISSING
the destination lang dialect is missing
TS_TRANSLATION_INPUT_FAILURE
fatal error in input module
TS_TRANSLATION_OUTPUT_FAILURE
fatal error in output module
TS_FORK_FAILED
process fork failed
TS_PIPE_FAILED
making a pipe failed