# Class Translator.Session

java.lang.Object
com.codename1.ai.language.Translator.Session

All Implemented Interfaces:
  `AutoCloseable`

Enclosing class:
  `Translator`

public static final class Translator.Session extends Object implements AutoCloseable

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.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Closes the session.
  `AsyncResource<String>`
  `translate(String text, String sourceLanguage, String targetLanguage)`
  Translates text without recreating the native backend.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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` - source text; `null` is treated as empty
      `sourceLanguage` - supported BCP-47 source language tag
      `targetLanguage` - 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.
    Specified by:
      `close` in interface `AutoCloseable`