public static final class Translator.Session
- Object
- 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
textString- source text;
nullis treated as empty sourceLanguageString- supported BCP-47 source language tag
targetLanguageString- 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.