![]() |
![]() |
![]() |
libtranslate Reference Manual | ![]() |
---|---|---|---|---|
TranslateSession; #define TRANSLATE_SESSION_ERROR enum TranslateSessionError; TranslateSession* translate_session_new (const GSList *services); void translate_session_set_services (TranslateSession *session, const GSList *services); void translate_session_set_max_threads (TranslateSession *session, unsigned int max_threads); void translate_session_set_max_retries (TranslateSession *session, unsigned int max_retries); GSList* translate_session_get_services (TranslateSession *session); GSList* translate_session_get_pairs (TranslateSession *session); unsigned int translate_session_get_max_threads (TranslateSession *session); int translate_session_get_max_retries (TranslateSession *session); char* translate_session_translate_text (TranslateSession *session, const char *text, const char *from, const char *to, TranslateProgressFunc progress_func, gpointer user_data, GError **err); char* translate_session_translate_web_page (TranslateSession *session, const char *url, const char *from, const char *to, TranslateProgressFunc progress_func, gpointer user_data, GError **err);
"max-retries" gint : Read / Write / Construct "max-threads" guint : Read / Write / Construct "pairs" gpointer : Read "services" gpointer : Read / Write / Construct
A TranslateSession object is used to translate a text or web page
using a set of translation services. After creating a new session with
translate_session_new()
, you can translate a text or web page using
translate_session_translate_text()
or
translate_session_translate_web_page()
.
typedef struct _TranslateSession TranslateSession;
The TranslateSession struct contains private data only, and should be accessed using the functions below.
#define TRANSLATE_SESSION_ERROR (translate_session_error_quark())
The error domain of translate_session_translate_text()
and
translate_session_translate_web_page()
. Errors in this domain are from
the TranslateSessionError enumeration.
typedef enum { TRANSLATE_SESSION_ERROR_NO_SERVICE } TranslateSessionError;
Error codes returned by translate_session_translate_text()
and
translate_session_translate_web_page()
.
TranslateSession* translate_session_new (const GSList *services);
Creates a new translation session, which will use services
for
performing translations.
|
a list of TranslateService objects to use. See
translate_session_set_services() .
|
Returns : |
a new translation session. |
void translate_session_set_services (TranslateSession *session, const GSList *services);
Sets the services used by session
. Default value: NULL
.
The list of services determines the available language pairs (see
translate_session_get_pairs()
). The order of the list is important,
as translate_session_translate_text()
and
translate_session_translate_web_page()
iterate over the list until
the translation can be performed.
|
a session. |
|
a list of TranslateService objects to use. |
void translate_session_set_max_threads (TranslateSession *session, unsigned int max_threads);
Sets the maximum number of concurrent threads to use for translating text. Default value: 8.
|
a session. |
|
a maximum number of threads. |
void translate_session_set_max_retries (TranslateSession *session, unsigned int max_retries);
Sets the maximum number of retries per text chunk. Default value: 3.
|
a session. |
|
a maximum number of retries. |
GSList* translate_session_get_services (TranslateSession *session);
Gets the services used by session. When no longer needed, the list should be freed with:
g_slist_foreach(list, (GFunc) g_object_unref, NULL); g_slist_free(list);
|
a session. |
Returns : |
the list of TranslateService objects used by
session .
|
GSList* translate_session_get_pairs (TranslateSession *session);
Gets the list of language pairs available for translations. When no longer needed, the list should be freed with:
g_slist_foreach(list, (GFunc) g_object_unref, NULL); g_slist_free(list);
|
a session. |
Returns : |
the list of TranslatePair objects available for translations. |
unsigned int translate_session_get_max_threads (TranslateSession *session);
Gets the maximum number of concurrent threads to use for translating text.
|
a session. |
Returns : |
the maximum number of threads. |
int translate_session_get_max_retries (TranslateSession *session);
Gets the maximum number of retries per text chunk.
|
a session. |
Returns : |
the maximum number of retries. |
char* translate_session_translate_text (TranslateSession *session, const char *text, const char *from, const char *to, TranslateProgressFunc progress_func, gpointer user_data, GError **err);
Translates text from the language from
into the language to
.
If progress_func
is specified, it may be
called periodically to report progress. If, when called,
progress_func
returns FALSE
, the translation is cancelled as soon
as possible, NULL
is returned, and err
is set to an error of
domain TRANSLATE_ERROR and code TRANSLATE_ERROR_CANCELLED.
|
a session. |
|
a nul-terminated string. |
|
a RFC 3066 language tag. |
|
a RFC 3066 language tag. |
|
a function to call when progressing, or NULL .
|
|
data to pass to progress_func , or NULL .
|
|
a location to report errors, or NULL . Any of the errors in
TranslateSessionError, TranslateError or other domains may occur.
|
Returns : |
the translated text on success, or NULL on failure
(in such case err is set). The returned string should be freed
when no longer needed.
|
char* translate_session_translate_web_page (TranslateSession *session, const char *url, const char *from, const char *to, TranslateProgressFunc progress_func, gpointer user_data, GError **err);
Translates a web page from the language from
into the language
to
.
If progress_func
is specified, it may be
called periodically to report progress. If, when called,
progress_func
returns FALSE
, the translation is cancelled as soon
as possible, NULL
is returned, and err
is set to an error of
domain TRANSLATE_ERROR and code TRANSLATE_ERROR_CANCELLED.
|
a session. |
|
an URL. |
|
a RFC 3066 language tag. |
|
a RFC 3066 language tag. |
|
a function to call when progressing, or NULL .
|
|
data to pass to progress_func , or NULL .
|
|
a location to report errors, or NULL . Any of the errors in
TranslateSessionError, TranslateError or other domains may occur.
|
Returns : |
an URL pointing to the translated web page on
success, or NULL on failure (in such case err is set). The
returned string should be freed when no longer needed.
|
"max-retries"
property"max-retries" gint : Read / Write / Construct
The maximum number of times to retry a translation of the same chunk (-1 for unlimited).
Allowed values: >= -1
Default value: 3
"max-threads"
property"max-threads" guint : Read / Write / Construct
The maximum number of translation threads to use.
Allowed values: <= G_MAXINT
Default value: 8
"services"
property"services" gpointer : Read / Write / Construct
The list of services used by this session.