This post was originally published at In-app translations in Android Marshmallow

Posted by, Barak Turovsky, Product Lead, Google Translate

Google Translate is used by more than 500 million people every month, translating more than 100 billion words every single day.

Beginning this week, Android mobile users who have the Translate app installed will be able to translate in 90 languages right within some of their favorite apps on any device running the newest version of Android’s operating system (Android 6.0, Marshmallow).

image

Translating a TripAdvisor review from Portuguese

image

Composing a Whatsapp message in Russian

Android apps that use Android text selection behavior will already have this feature enabled, so no extra steps need to be taken. Developers who created custom text selection behavior for their apps can easily implement this feature by following the below steps:

Scan via the PackageManager through all packages that have the PROCESS_TEXT intent filter (for example: com.google.android.apps.translate – if it installed) and add them as MenuItems into TextView selections for your app

  1. To query the package manager, first build an intent with the action

  2. Then retrieve the supported activities

  3. add an item for each retrieved activity and attach an intent to it to launch the action

    The label for each item can be retrieved with:

    The intent for each item can be created reusing the filter intent that you defined before and adding the missing data:

    Adding the translation option to your apps text selection menu (if you don’t use default Android text selection behavior) is easy and takes just a few extra lines of code. And remember, when a user is composing a text to translate, your app you should keep the selection when the Translate app is triggered.

    With this new feature, Android Translate app users users will be able to easily translate right from within participating apps. We will be adding more documentation and sample code on this feature in the upcoming weeks.

    image image

Link: 

This post was originally published at In-app translations in Android Marshmallow