How does the new translation API work?

Asked on 2024-07-30

1 search

The new Translation API introduced at WWDC 2024 offers several features to integrate translation capabilities into your apps. Here’s a summary of how it works:

  1. Introduction:

    • The Translation API is designed to remove language barriers and leverage the machine learning models behind the Translate app. It supports iOS, iPadOS, and macOS (Meet the Translation API).
  2. Translation Options:

    • There are two main options for offering translation within your app:
      1. Simple Overlay Translation: This API shows a translation overlay with just one line of SwiftUI code. It’s easy to implement and provides a system UI for translation (Meet the Translation API).
      2. Flexible Translation API: This API allows for more complex scenarios, such as translating multiple strings at once. It uses the translation session class to handle translations asynchronously (Meet the Translation API).
  3. Language Support:

    • The API supports all languages available in the Translate app, with new support for Hindi added this year. You can check language availability programmatically using the language availability class (Meet the Translation API).
  4. Batch Translation:

    • For translating multiple strings, the API offers batch translation functions. These can either return all results at once or stream results as they become available, making the UI more responsive (Meet the Translation API).
  5. On-Device ML Models:

    • Translations are performed using on-device machine learning models. If the required language models are not already downloaded, the API will handle the download process, including showing progress to the user (Meet the Translation API).
  6. Best Practices:

    • The session also covers best practices for using the Translation API, such as using the NL language recognizer to identify the language of the text when necessary (Meet the Translation API).

For a detailed walkthrough, you can refer to the session Meet the Translation API.