# Translator

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Methods](https://developer.android.com/reference/android/view/translation/Translator#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/view/translation/Translator#inhmethods)  

# Translator

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/view/translation/Translator "View this page in Kotlin")\|Java

`
public


class
Translator
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|-------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.view.translation.Translator |

<br />

*** ** * ** ***

The[Translator](https://developer.android.com/reference/android/view/translation/Translator)for translation, defined by a[TranslationContext](https://developer.android.com/reference/android/view/translation/TranslationContext).

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ||
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`    | ` `[destroy](https://developer.android.com/reference/android/view/translation/Translator#destroy())`() ` Destroy this Translator.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` boolean` | ` `[isDestroyed](https://developer.android.com/reference/android/view/translation/Translator#isDestroyed())`() ` Returns whether or not this Translator has been destroyed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` void`    | ` `[translate](https://developer.android.com/reference/android/view/translation/Translator#translate(android.view.translation.TranslationRequest,%20android.os.CancellationSignal,%20java.util.concurrent.Executor,%20java.util.function.Consumer<android.view.translation.TranslationResponse>))`(`[TranslationRequest](https://developer.android.com/reference/android/view/translation/TranslationRequest)` request, `[CancellationSignal](https://developer.android.com/reference/android/os/CancellationSignal)` cancellationSignal, `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<`[TranslationResponse](https://developer.android.com/reference/android/view/translation/TranslationResponse)`> callback) ` Requests a translation for the provided[TranslationRequest](https://developer.android.com/reference/android/view/translation/TranslationRequest)using the Translator's source spec and destination spec. |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public methods

### destroy

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void destroy ()
```

Destroy this Translator.

<br />

### isDestroyed

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean isDestroyed ()
```

Returns whether or not this Translator has been destroyed.

<br />

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

**See also:**

- [destroy()](https://developer.android.com/reference/android/view/translation/Translator#destroy())  

### translate

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void translate (TranslationRequest request, 
                CancellationSignal cancellationSignal, 
                Executor executor, 
                Consumer<TranslationResponse> callback)
```

Requests a translation for the provided[TranslationRequest](https://developer.android.com/reference/android/view/translation/TranslationRequest)using the Translator's source spec and destination spec.

<br />

|                                                                                                                                                                                                                                                                                                                      Parameters                                                                                                                                                                                                                                                                                                                       ||
|----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `request`            | `TranslationRequest`:[TranslationRequest](https://developer.android.com/reference/android/view/translation/TranslationRequest)request to be translate. This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `cancellationSignal` | `CancellationSignal`: signal to cancel the operation in progress. This value may be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `executor`           | `Executor`: Executor to run callback operations This value cannot be`null`. Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/Executor), providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use[Context.getMainExecutor()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br /> |
| `callback`           | `Consumer`:[Consumer](https://developer.android.com/reference/java/util/function/Consumer)to receive the translation response. Multiple responses may be received if[TranslationRequest.FLAG_PARTIAL_RESPONSES](https://developer.android.com/reference/android/view/translation/TranslationRequest#FLAG_PARTIAL_RESPONSES)is set. This value cannot be`null`. <br />                                                                                                                                                                                                                                                           |

|                 Returns                 ||
|--------|---------------------------------|
| `void` | This value may be`null`. <br /> |

|                                                                         Throws                                                                          ||
|--------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if this Translator session was destroyed when called. |