Class ZCL_IBMC_LANG_TRANSLATOR_V3

public inheriting from zcl_ibmc_service_ext create public

Documentation

Language Translator

IBM Watson™ Language Translator translates text from one language to another. The service offers multiple IBM-provided translation models that you can customize based on your unique terminology and language. Use Language Translator to take news from across the globe and present it in your language, communicate with your customers in their own language, and more.

Types

Visibility and LevelNameDocumentation
publict_base_model_id type string

Model ID of the base model that was used to customize the

model. If the model is not a custom model, this will be absent or an empty string.
publict_delete_model_result (structured type) No documentation available.
publict_document_id type string

System generated ID identifying a document being translated

using one specific translation model.
publict_document_list (structured type) No documentation available.
publict_document_status (structured type)

Document information, including translation status.

publict_error_response (structured type) No documentation available.
publict_get_translated_doc_response type file No documentation available.
publict_identifiable_language (structured type) No documentation available.
publict_identifiable_languages (structured type) No documentation available.
publict_identified_language (structured type) No documentation available.
publict_identified_languages (structured type) No documentation available.
publict_inline_object (structured type) No documentation available.
publict_inline_object1 (structured type) No documentation available.
publict_language (structured type)

Response payload for languages.

publict_languages (structured type)

The response type for listing supported languages.

publict_model_id type string

A globally unique string that identifies the underlying

model that is used for translation.
publict_source type string

Translation source language code.

publict_target type string

Translation target language code.

publict_translate_request (structured type) No documentation available.
publict_translation (structured type) No documentation available.
publict_translation_model (structured type)

Response payload for models.

publict_translation_models (structured type)

The response type for listing existing translation models.

publict_translation_result (structured type) No documentation available.
publict_translation_status type string

The status of the translation job associated with a

submitted document.

Constants

Visibility and LevelNameDocumentation
public staticc_abapname_dictionary (structured type)

Map ABAP identifiers to service identifiers.

public staticc_required_fields (structured type)

List of required fields per type.

Methods

Visibility and LevelNameDocumentation
public instance
create_model
importingi_base_model_idtype string
i_forced_glossarytype file optional
i_forced_glossary_content_typetype string optional
i_parallel_corpustype file optional
i_parallel_corpus_content_typetype string optional
i_nametype string optional
i_contenttypetype string default 'multipart/form-data'
i_accepttype string default 'application/json'
exportinge_responsetype t_translation_model
raisingzcx_ibmc_service_exception

Create model

Uploads training files to customize a translation model. You can customize a model with a forced glossary or with a parallel corpus:
* Use a *forced glossary* to force certain terms and phrases to be translated in a specific way. You can upload only a single forced glossary file for a model. The size of a forced glossary file for a custom model is limited to 10 MB.
* Use a *parallel corpus* when you want your custom model to learn from general translation patterns in parallel sentences in your samples. What your model learns from a parallel corpus can improve translation results for input text that the model has not been trained on. You can upload multiple parallel corpora files with a request. To successfully train with parallel corpora, the corpora files must contain a cumulative total of at least 5000 parallel sentences. The cumulative size of all uploaded corpus files for a custom model is limited to 250 MB.

Depending on the type of customization and the size of the uploaded files, training time can range from minutes for a glossary to several hours for a large parallel corpus. To create a model that is customized with a parallel corpus and a forced glossary, customize the model with a parallel corpus first and then customize the resulting model with a forced glossary.

You can create a maximum of 10 custom models per language pair. For more information about customizing a translation model, including the formatting and character restrictions for data files, see [Customizing your model](https://cloud.ibm.com/docs/language-translator?topic=language-translator -customizing).

#### Supported file formats

You can provide your training data for customization in the following document formats:
* **TMX** (`.tmx`) - Translation Memory eXchange (TMX) is an XML specification for the exchange of translation memories.
* **XLIFF** (`.xliff`) - XML Localization Interchange File Format (XLIFF) is an XML specification for the exchange of translation memories.
* **CSV** (`.csv`) - Comma-separated values (CSV) file with two columns for aligned sentences and phrases. The first row must have two language codes. The first column is for the source language code, and the second column is for the target language code.
* **TSV** (`.tsv` or `.tab`) - Tab-separated values (TSV) file with two columns for aligned sentences and phrases. The first row must have two language codes. The first column is for the source language code, and the second column is for the target language code.
* **JSON** (`.json`) - Custom JSON format for specifying aligned sentences and phrases.
* **Microsoft Excel** (`.xls` or `.xlsx`) - Excel file with the first two columns for aligned sentences and phrases. The first row contains the language code.

You must encode all text data in UTF-8 format. For more information, see [Supported document formats for training data](https://cloud.ibm.com/docs/language-translator?topic=language-translator- customizing#supported-document-formats-for-training-data).

#### Specifying file formats

You can indicate the format of a file by including the file extension with the file name. Use the file extensions shown in **Supported file formats**.

Alternatively, you can omit the file extension and specify one of the following `content-type` specifications for the file:
* **TMX** - `application/x-tmx+xml`
* **XLIFF** - `application/xliff+xml`
* **CSV** - `text/csv`
* **TSV** - `text/tab-separated-values`
* **JSON** - `application/json`
* **Microsoft Excel** - `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`

For example, with `curl`, use the following `content-type` specification to indicate the format of a CSV file named **glossary**:

`--form "forced_glossary=@glossary;type=text/csv"`
Parameters
i_base_model_id The ID of the translation model to use as the base for customization. To see available models and IDs, use the `List models` method. Most models that are provided with the service are customizable. In addition, all models that you create with parallel corpora customization can be further customized with a forced glossary.
i_forced_glossary A file with forced glossary terms for the source and target languages. The customizations in the file completely overwrite the domain translation data, including high frequency or high confidence phrase translations.

You can upload only one glossary file for a custom model, and the glossary can have a maximum size of 10 MB. A forced glossary must contain single words or short phrases. For more information, see **Supported file formats** in the method description.

*With `curl`, use `--form forced_glossary=@{filename}`.*.
i_forced_glossary_content_type The content type of forcedGlossary.
i_parallel_corpus A file with parallel sentences for the source and target languages. You can upload multiple parallel corpus files in one request by repeating the parameter. All uploaded parallel corpus files combined must contain at least 5000 parallel sentences to train successfully. You can provide a maximum of 500,000 parallel sentences across all corpora.

A single entry in a corpus file can contain a maximum of 80 words. All corpora files for a custom model can have a cumulative maximum size of 250 MB. For more information, see **Supported file formats** in the method description.

*With `curl`, use `--form parallel_corpus=@{filename}`.*.
i_parallel_corpus_content_type The content type of parallelCorpus.
i_name An optional model name that you can use to identify the model. Valid characters are letters, numbers, dashes, underscores, spaces, and apostrophes. The maximum length of the name is 32 characters.
e_response Service return value of type T_TRANSLATION_MODEL
Class-based Exceptions
zcx_ibmc_service_exception Exception being raised in case of an error.
public instance
delete_document
importingi_document_idtype string
raisingzcx_ibmc_service_exception

Delete document

Deletes a document
Parameters
i_document_id Document ID of the document to delete.
Class-based Exceptions
zcx_ibmc_service_exception Exception being raised in case of an error.
public instance
delete_model
importingi_model_idtype string
i_accepttype string default 'application/json'
exportinge_responsetype t_delete_model_result
raisingzcx_ibmc_service_exception

Delete model

Deletes a custom translation model.
Parameters
i_model_id Model ID of the model to delete.
e_response Service return value of type T_DELETE_MODEL_RESULT
Class-based Exceptions
zcx_ibmc_service_exception Exception being raised in case of an error.
public instanceget_appname redefinition 
public instance
get_document_status
importingi_document_idtype string
i_accepttype string default 'application/json'
exportinge_responsetype t_document_status
raisingzcx_ibmc_service_exception

Get document status

Gets the translation status of a document
Parameters
i_document_id The document ID of the document.
e_response Service return value of type T_DOCUMENT_STATUS
Class-based Exceptions
zcx_ibmc_service_exception Exception being raised in case of an error.
public instance
get_model
importingi_model_idtype string
i_accepttype string default 'application/json'
exportinge_responsetype t_translation_model
raisingzcx_ibmc_service_exception

Get model details

Gets information about a translation model, including training status for custom models. Use this method to poll the status of your customization request. A successfully completed training request has a status of `available`.
Parameters
i_model_id Model ID of the model to get.
e_response Service return value of type T_TRANSLATION_MODEL
Class-based Exceptions
zcx_ibmc_service_exception Exception being raised in case of an error.
public instanceget_request_prop redefinition 
public instanceget_sdk_version_date redefinition 
public instance
get_translated_document
importingi_document_idtype string
i_accepttype string optional
exportinge_responsetype file
raisingzcx_ibmc_service_exception

Get translated document

Gets the translated document associated with the given document ID
Parameters
i_document_id The document ID of the document that was submitted for translation.
i_accept The type of the response: application/powerpoint, application/mspowerpoint, application/x-rtf, application/json, application/xml, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.presentation, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.oasis.opendocument.spreadsheet, application/vnd.oasis.opendocument.presentation, application/vnd.oasis.opendocument.text, application/pdf, application/rtf, text/html, text/json, text/plain, text/richtext, text/rtf, or text/xml. A character encoding can be specified by including a `charset` parameter. For example, 'text/html;charset=utf-8'.
e_response Service return value of type FILE
Class-based Exceptions
zcx_ibmc_service_exception Exception being raised in case of an error.
public instance
identify
importingi_texttype string
i_contenttypetype string default 'text/plain'
i_accepttype string default 'application/json'
exportinge_responsetype t_identified_languages
raisingzcx_ibmc_service_exception

Identify language

Identifies the language of the input text.
Parameters
i_text Input text in UTF-8 format.
e_response Service return value of type T_IDENTIFIED_LANGUAGES
Class-based Exceptions
zcx_ibmc_service_exception Exception being raised in case of an error.
public instance
list_documents
importingi_accepttype string default 'application/json'
exportinge_responsetype t_document_list
raisingzcx_ibmc_service_exception

List documents

Lists documents that have been submitted for translation
Parameters
e_response Service return value of type T_DOCUMENT_LIST
Class-based Exceptions
zcx_ibmc_service_exception Exception being raised in case of an error.
public instance
list_identifiable_languages
importingi_accepttype string default 'application/json'
exportinge_responsetype t_identifiable_languages
raisingzcx_ibmc_service_exception

List identifiable languages

Lists the languages that the service can identify. Returns the language code (for example, `en` for English or `es` for Spanish) and name of each language.
Parameters
e_response Service return value of type T_IDENTIFIABLE_LANGUAGES
Class-based Exceptions
zcx_ibmc_service_exception Exception being raised in case of an error.
public instance
list_languages
importingi_accepttype string default 'application/json'
exportinge_responsetype t_languages
raisingzcx_ibmc_service_exception

List supported languages

Lists all supported languages for translation. The method returns an array of supported languages with information about each language. Languages are listed in alphabetical order by language code (for example, `af`, `ar`). In addition to basic information about each language, the response indicates whether the language is `supported_as_source` for translation and `supported_as_target` for translation. It also lists whether the language is `identifiable`.
Parameters
e_response Service return value of type T_LANGUAGES
Class-based Exceptions
zcx_ibmc_service_exception Exception being raised in case of an error.
public instance
list_models
importingi_sourcetype string optional
i_targettype string optional
i_defaulttype boolean optional
i_accepttype string default 'application/json'
exportinge_responsetype t_translation_models
raisingzcx_ibmc_service_exception

List models

Lists available translation models.
Parameters
i_source Specify a language code to filter results by source language.
i_target Specify a language code to filter results by target language.
i_default If the `default` parameter isn't specified, the service returns all models (default and non-default) for each language pair. To return only default models, set this parameter to `true`. To return only non-default models, set this parameter to `false`. There is exactly one default model, the IBM-provided base model, per language pair.
e_response Service return value of type T_TRANSLATION_MODELS
Class-based Exceptions
zcx_ibmc_service_exception Exception being raised in case of an error.
public instance
translate
importingi_requesttype t_translate_request
i_contenttypetype string default 'application/json'
i_accepttype string default 'application/json'
exportinge_responsetype t_translation_result
raisingzcx_ibmc_service_exception

Translate

Translates the input text from the source language to the target language. Specify a model ID that indicates the source and target languages, or specify the source and target languages individually. You can omit the source language to have the service attempt to detect the language from the input text. If you omit the source language, the request must contain sufficient input text for the service to identify the source language.

You can translate a maximum of 50 KB (51,200 bytes) of text with a single request. All input text must be encoded in UTF-8 format.
Parameters
i_request The translate request containing the text, and either a model ID or source and target language pair.
e_response Service return value of type T_TRANSLATION_RESULT
Class-based Exceptions
zcx_ibmc_service_exception Exception being raised in case of an error.
public instance
translate_document
importingi_filetype file
i_filenametype string
i_file_content_typetype string optional
i_model_idtype string optional
i_sourcetype string optional
i_targettype string optional
i_document_idtype string optional
i_contenttypetype string default 'multipart/form-data'
i_accepttype string default 'application/json'
exportinge_responsetype t_document_status
raisingzcx_ibmc_service_exception

Translate document

Submit a document for translation. You can submit the document contents in the `file` parameter, or you can specify a previously submitted document by document ID. The maximum file size for document translation is
* **2 MB** for service instances on the Lite plan
* **20 MB** for service instances on the Standard plan
* **50 MB** for service instances on the Advanced plan
* **150 MB** for service instances on the Premium plan

You can specify the format of the file to be translated in one of two ways:
* By specifying the appropriate file extension for the format.
* By specifying the content type (MIME type) of the format as the `type` of the `file` parameter.

In some cases, especially for subtitle file formats, you must use either the file extension or the content type. For more information about all supported file formats, their file extensions and content types, and how and when to specify the file extension or content type, see [Supported file formats](https://cloud.ibm.com/docs/language-translator?topic=language-translat or-document-translator-tutorial#supported-file-formats).

**Note:** When translating a previously submitted document, the target language must be different from the target language of the original request when the document was initially submitted.
Parameters
i_file The contents of the source file to translate. The maximum file size for document translation is
* **2 MB** for service instances on the Lite plan
* **20 MB** for service instances on the Standard plan
* **50 MB** for service instances on the Advanced plan
* **150 MB** for service instances on the Premium plan

You can specify the format of the file to be translated in one of two ways:
* By specifying the appropriate file extension for the format.
* By specifying the content type (MIME type) of the format as the `type` of the `file` parameter.

In some cases, especially for subtitle file formats, you must use either the file extension or the content type.

For more information about all supported file formats, their file extensions and content types, and how and when to specify the file extension or content type, see [Supported file formats](https://cloud.ibm.com/docs/language-translator?topic=language-translat or-document-translator-tutorial#supported-file-formats).
i_filename The filename for file.
i_file_content_type The content type of file.
i_model_id The model to use for translation. For example, `en-de` selects the IBM-provided base model for English-to-German translation. A model ID overrides the `source` and `target` parameters and is required if you use a custom model. If no model ID is specified, you must specify at least a target language.
i_source Language code that specifies the language of the source document. If omitted, the service derives the source language from the input text. The input must contain sufficient text for the service to identify the language reliably.
i_target Language code that specifies the target language for translation. Required if model ID is not specified.
i_document_id To use a previously submitted document as the source for a new translation, enter the `document_id` of the document.
e_response Service return value of type T_DOCUMENT_STATUS
Class-based Exceptions
zcx_ibmc_service_exception Exception being raised in case of an error.