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/UiTranslationManager#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/view/translation/UiTranslationManager#inhmethods)

# UiTranslationManager

*** ** * ** ***

` public final class UiTranslationManager `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

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

<br />

*** ** * ** ***

<br />

The `https://developer.android.com/reference/android/view/translation/UiTranslationManager` class provides ways for apps to use the ui translation function in framework.

The UI translation provides ways for apps to support inline translation for the views. For example the system supports text translation for `https://developer.android.com/reference/android/widget/TextView`. To support UI translation for your views, you should override the following methods to provide the content to be translated and deal with the translated result. Here is an example for `https://developer.android.com/reference/android/widget/TextView`-like views:

    public class MyTextView extends View {
        public MyTextView(...) {
            // implements how to show the translated result in your View in
            // ViewTranslationCallback and set it by setViewTranslationCallback()
            setViewTranslationCallback(new MyViewTranslationCallback());
        }

        public void onCreateViewTranslationRequest(int[] supportedFormats,
                Consumer
           requestsCollector) {
           // collect the information that needs to be translated
           ViewTranslationRequest.Builder requestBuilder =
                        new ViewTranslationRequest.Builder(getAutofillId());
           requestBuilder.setValue(ViewTranslationRequest.ID_TEXT,
                            TranslationRequestValue.forText(etText()));
           requestsCollector.accept(requestBuilder.build());
        }

        public void onProvideContentCaptureStructure(
                ViewStructure structure, int flags) {
            // set ViewTranslationResponse
            super.onViewTranslationResponse(response);
        }
    }

          
If your view provides its own virtual hierarchy (for example, if it's a browser that draws the HTML using `https://developer.android.com/reference/android/graphics/Canvas` or native libraries in a different render process), you must override `https://developer.android.com/reference/android/view/View#onCreateVirtualViewTranslationRequests(long[],%20int[],%20java.util.function.Consumer<android.view.translation.ViewTranslationRequest>)` to provide the content to be translated and implement `https://developer.android.com/reference/android/view/View#onVirtualViewTranslationResponses(android.util.LongSparseArray<android.view.translation.ViewTranslationResponse>)` for the translated result. You also need to implement `https://developer.android.com/reference/android/view/translation/ViewTranslationCallback` to handle the translated information show or hide in your `https://developer.android.com/reference/android/view/View`.

## Summary

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/view/translation/UiTranslationManager#registerUiTranslationStateCallback(java.util.concurrent.Executor,%20android.view.translation.UiTranslationStateCallback)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback callback) ` Register for notifications of UI Translation state changes on the foreground Activity. |
| ` void` | ` https://developer.android.com/reference/android/view/translation/UiTranslationManager#unregisterUiTranslationStateCallback(android.view.translation.UiTranslationStateCallback)(https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback callback) ` Unregister `callback`. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` 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 https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` 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` ` 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` ` 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

### registerUiTranslationStateCallback

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

```
public void registerUiTranslationStateCallback (Executor executor, 
                UiTranslationStateCallback callback)
```

Register for notifications of UI Translation state changes on the foreground Activity. This is available to the owning application itself and also the current input method.

The application whose UI is being translated can use this to customize the UI Translation behavior in ways that aren't made easy by methods like `https://developer.android.com/reference/android/view/View#onCreateViewTranslationRequest(int[],%20java.util.function.Consumer<android.view.translation.ViewTranslationRequest>)`.

Input methods can use this to offer complementary features to UI Translation; for example, enabling outgoing message translation when the system is translating incoming messages in a communication app.

Starting from `https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU`, if Activities are already being translated when a callback is registered, methods on the callback will be invoked for each translated activity, depending on the state of translation:

- If translation is *not* paused, `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onStarted(android.icu.util.ULocale,%20android.icu.util.ULocale)` will be invoked.
- If translation *is* paused, `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onStarted(android.icu.util.ULocale,%20android.icu.util.ULocale)` will first be invoked, followed by `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onPaused()`.

<br />

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: This value cannot be `null`. Callback and listener events are dispatched through this `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 `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `UiTranslationStateCallback`: the callback to register for receiving the state change notifications. This value cannot be `null`. <br /> |

### unregisterUiTranslationStateCallback

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

```
public void unregisterUiTranslationStateCallback (UiTranslationStateCallback callback)
```

Unregister `callback`.

<br />

| Parameters ||
|---|---|
| `callback` | `UiTranslationStateCallback`: This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/translation/UiTranslationManager#registerUiTranslationStateCallback(java.util.concurrent.Executor,%20android.view.translation.UiTranslationStateCallback)`