translate

1

# translate Manual

translate

translate a text or web page

          &cmd;

    	-?
    	-v
    	--list-services

          &cmd;
          -s services
          -f lang
          -t lang
          -l

          &cmd;
          -s services
          -f lang
          -t lang

    	http_url
    	https_url

          &cmd;
          -s services
          -f lang
          -t lang
          --max-threads=n
          --max-retries=n
          file

## Description

&cmd; translates a text or web page.

If the first synopsis form is used, &cmd; prints a quick help, the version information or the list of available translation services to standard output.

If the second synopsis form is used, &cmd; prints the list of available language pairs to standard output.

If the third synopsis form is used, &cmd; translates the web page pointed to by `http_url` or `https_url`, and prints the URL of the translated web page to standard output (`http_url` must be a string starting with `http://`, and `https_url` must be a string starting with `https://`).

If the fourth synopsis form is used, &cmd; translates the text contained in `file`, and prints the translation to standard output (if `file` is omitted or given as a single dash, standard input is used instead).

## Options

`-?`, `--help`

- Prints a quick help to standard output.

`-v`, `--version`

- Prints version information to standard output.

`--list-services`

- Lists the available translation services.

`-s` `services`, `--services`=`services`

- Specifies the translation services to use. The `services` argument must be a comma-separated list of service names (default value: all the available services).

  The list of services determines the available language pairs. The order of the list is important, as libtranslate iterates over the list until the requested translation can be performed.

`-l`, `--list-pairs`

- Lists the available language pairs.

  The `-f` and `-t` options can be used to specify a source and/or destination language filter. If neither `-f` nor `-t` is specified, all the pairs are listed.

`-f` `lang`, `--from`=`lang`

- Specifies the source language of a translation. The `lang` argument must be a RFC 3066 language tag such as `en` or `zh-TW` (default value: see Language Selection).

`-t` `lang`, `--to`=`lang`

- Specifies the destination language of a translation. The `lang` argument must be a RFC 3066 language tag such as `en` or `zh-TW` (default value: see Language Selection).

`--max-threads`=`n`

- Specifies the maximum number of concurrent threads to use for translating text (default value: `8`).

`--max-retries`=`n`

- Specifies the maximum number of retries per text chunk (default value: `3`).

## Language Selection

Definitions: in this section, `default_from` is defined as the contents of the environment variable `TRANSLATE_DEFAULT_FROM`, or, if that variable is not set, `en`; `default_to` is defined as the contents of the environment variable `TRANSLATE_DEFAULT_TO`, or, if that variable is not set, `fr`.

If the source language is not specified, it defaults to `default_from`, or, if the destination language is equal to `default_from`, `default_to`.

If the destination language is not specified, it defaults to `default_to`, or, if the source language is equal to `default_to`, `default_from`.

## Character Set Handling

Internally, libtranslate uses the UTF-8 encoding.

If the input text is not encoded in UTF-8, &cmd; assumes it is encoded in the character set of the current locale, and attempts to convert it to UTF-8. If the conversion fails, &cmd; exits with an error.

The output text is converted to the character set of the current locale before printing.

## Examples

In the following examples, it is assumed that `TRANSLATE_DEFAULT_FROM` is set to `es` and that `TRANSLATE_DEFAULT_TO` is set to `de`.

&cmd; `-f` `fr` `-l`

- Lists all the available language pairs where the source language is French.

&cmd; `document1`

- Translates the contents of the file `document1` from Spanish to German and prints the result to standard output.

&cmd; `-s` `babelfish,freetranslation` `document1`

- Translates the contents of the file `document1` from Spanish to German, only using the Babel Fish and FreeTranslation services, and prints the result to standard output.

&cmd; `-f` `de` `document1`

- Translates the contents of the file `document1` from German to Spanish and prints the result to standard output.

`echo` "Le problème est résolu." | &cmd; `-f` `fr` `-t` `en`

- Translates the text given on standard input from French to English and prints the result to standard output.

&cmd; `-t` `en` `http://www.freebsd.org/es/index.html`

- Translates the web page pointed to by `http://www.freebsd.org/es/index.html` from Spanish to English and prints an URL pointing to the result to standard output.

## Diagnostics

The &cmd; utility exits with a status of 0 on success, and >0 if an error occurs.

## Environment

The following environment variables affect the execution of &cmd;:

`HTTP_PROXY`

- The URL of the proxy to use for HTTP requests.

`http_proxy`

- Same as HTTP_PROXY, for compatibility.

`TRANSLATE_DEFAULT_FROM`

- The default source language (see Language Selection).

`TRANSLATE_DEFAULT_TO`

- The default destination language (see Language Selection).

## See Also

The libtranslate Reference Manual