Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LanguageTranslatorV3

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. interfaces

API Version: 3.0.0 See: https://cloud.ibm.com/docs/language-translator

Hierarchy

  • BaseService
    • LanguageTranslatorV3

Index

Constructors

constructor

Properties

version

version: string

Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is 2018-05-01.

Static DEFAULT_SERVICE_NAME

DEFAULT_SERVICE_NAME: string = "language_translator"

Static DEFAULT_SERVICE_URL

DEFAULT_SERVICE_URL: string = "https://api.us-south.language-translator.watson.cloud.ibm.com"

Methods

createModel

  • 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.

    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.

    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

    Name Type Attribute Description
    params CreateModelParams

    The parameters to send to the service.

    Properties

    Name Type Attributes Description
    baseModelId string 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.
    forcedGlossary ReadableStream | Buffer Optional 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.
    headers OutgoingHttpHeaders Optional
    name string Optional 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.
    parallelCorpus ReadableStream | Buffer Optional 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.

    Returns Promise<Response<TranslationModel>>

deleteDocument

  • Delete document.

    Deletes a document.

    Parameters

    Name Type Attribute Description
    params DeleteDocumentParams

    The parameters to send to the service.

    Properties

    Name Type Attributes Description
    documentId string Document ID of the document to delete.
    headers OutgoingHttpHeaders Optional

    Returns Promise<Response<Empty>>

deleteModel

  • Delete model.

    Deletes a custom translation model.

    Parameters

    Name Type Attribute Description
    params DeleteModelParams

    The parameters to send to the service.

    Properties

    Name Type Attributes Description
    modelId string Model ID of the model to delete.
    headers OutgoingHttpHeaders Optional

    Returns Promise<Response<DeleteModelResult>>

disableRetries

  • disableRetries(): void
  • Disables retries.

    Returns void

enableRetries

  • enableRetries(retryOptions?: RetryOptions): void
  • Enable retries for unfulfilled requests.

    Parameters

    Name Type Attribute Description
    retryOptions RetryOptions Optional

    configuration for retries

    Returns void

getAuthenticator

  • getAuthenticator(): any
  • Get the instance of the authenticator set on the service.

    Returns any

getDocumentStatus

  • Get document status.

    Gets the translation status of a document.

    Parameters

    Name Type Attribute Description
    params GetDocumentStatusParams

    The parameters to send to the service.

    Properties

    Name Type Attributes Description
    documentId string The document ID of the document.
    headers OutgoingHttpHeaders Optional

    Returns Promise<Response<DocumentStatus>>

getHttpClient

  • getHttpClient(): AxiosInstance
  • Get the Axios instance set on the service. All requests will be made using this instance.

    Returns AxiosInstance

getModel

  • Get model details.

    Gets information about a translation model, including training status for custom models. Use this API call to poll the status of your customization request. A successfully completed training has a status of available.

    Parameters

    Name Type Attribute Description
    params GetModelParams

    The parameters to send to the service.

    Properties

    Name Type Attributes Description
    modelId string Model ID of the model to get.
    headers OutgoingHttpHeaders Optional

    Returns Promise<Response<TranslationModel>>

getTranslatedDocument

  • Get translated document.

    Gets the translated document associated with the given document ID.

    Parameters

    Name Type Attribute Description
    params GetTranslatedDocumentParams

    The parameters to send to the service.

    Properties

    Name Type Attributes Description
    documentId string The document ID of the document that was submitted for translation.
    accept Accept | string Optional 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'.
    headers OutgoingHttpHeaders Optional

    Returns Promise<Response<ReadableStream>>

identify

  • Identify language.

    Identifies the language of the input text.

    Parameters

    Name Type Attribute Description
    params IdentifyParams

    The parameters to send to the service.

    Properties

    Name Type Attributes Description
    text string Input text in UTF-8 format.
    headers OutgoingHttpHeaders Optional

    Returns Promise<Response<IdentifiedLanguages>>

listDocuments

listIdentifiableLanguages

listLanguages

  • 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

    Name Type Attribute Description
    params ListLanguagesParams Optional

    Properties

    Name Type Attributes Description
    headers OutgoingHttpHeaders Optional

    Returns Promise<Response<Languages>>

listModels

  • List models.

    Lists available translation models.

    Parameters

    Name Type Attribute Description
    params ListModelsParams Optional

    Properties

    Name Type Attributes Description
    _default boolean Optional 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.
    headers OutgoingHttpHeaders Optional
    source string Optional Specify a language code to filter results by source language.
    target string Optional Specify a language code to filter results by target language.

    Returns Promise<Response<TranslationModels>>

setEnableGzipCompression

  • setEnableGzipCompression(setting: boolean): void
  • Turn request body compression on or off.

    Parameters

    Name Type Attribute Description
    setting boolean

    Will turn it on if 'true', off if 'false'.

    Returns void

setServiceUrl

  • setServiceUrl(url: string): void
  • Set the service URL to send requests to.

    Parameters

    Name Type Attribute Description
    url string

    The base URL for the service.

    Returns void

translate

  • 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

    Name Type Attribute Description
    params TranslateParams

    The parameters to send to the service.

    Properties

    Name Type Attributes Description
    text string[] Input text in UTF-8 encoding. Submit a maximum of 50 KB (51,200 bytes) of text with a single request. Multiple elements result in multiple translations in the response.
    headers OutgoingHttpHeaders Optional
    modelId string Optional 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.
    source string Optional Language code that specifies the language of the input text. 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.
    target string Optional Language code that specifies the target language for translation. Required if model ID is not specified.

    Returns Promise<Response<TranslationResult>>

translateDocument

  • Translate document.

    Submit a document for translation. You can submit the document contents in the file parameter, or you can reference a previously submitted document by document ID. The maximum file size for document translation is

    • 20 MB for service instances on the Standard, Advanced, and Premium plans
    • 2 MB for service instances on the Lite plan.

    Parameters

    Name Type Attribute Description
    params TranslateDocumentParams

    The parameters to send to the service.

    Properties

    Name Type Attributes Description
    file ReadableStream | Buffer The contents of the source file to translate. The maximum file size for document translation is 20 MB for service instances on the Standard, Advanced, and Premium plans, and 2 MB for service instances on the Lite plan. For more information, see [Supported file formats (Beta)](https://cloud.ibm.com/docs/language-translator?topic=language-translator-document-translator-tutorial#supported-file-formats).
    filename string The filename for file.
    documentId string Optional To use a previously submitted document as the source for a new translation, enter the `document_id` of the document.
    fileContentType FileContentType | string Optional The content type of file.
    headers OutgoingHttpHeaders Optional
    modelId string Optional 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.
    source string Optional 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.
    target string Optional Language code that specifies the target language for translation. Required if model ID is not specified.

    Returns Promise<Response<DocumentStatus>>

Generated using TypeDoc