public static final class Translator.Session

  1. Object
  2. Translator.Session

ImplementsAutoCloseable

Reusable owner of a native translation backend.

A session can serve multiple language pairs and retains native clients between calls. Calling close() prevents new requests and defers release until pending translations finish.

Methods

public AsyncResource<String> translate(String text, String sourceLanguage, String targetLanguage)Translates text without recreating the native backend.
public void close()Closes the session.

Inherited methods

Method details

translate

public AsyncResource<String> translate(String text, String sourceLanguage, String targetLanguage)
Translates text without recreating the native backend. Cancelling the returned resource suppresses late callbacks without closing this reusable session.

Parameters

text String
source text; null is treated as empty
sourceLanguage String
supported BCP-47 source language tag
targetLanguage String
supported BCP-47 target language tag

Returns

asynchronous translated text

Throws

IllegalStateException
if this session is closed

close

public void close()
Closes the session. This method is idempotent; native release is deferred until pending translations finish.