Automatic app translation for Android

Szymon Klimaszewski
5 min readDec 10, 2017

--

Localization

Localisation is one of crucial factors, which drastically influences organic growth of your application. However managing several languages comes with a cost that small applications can’t afford. In the result, small applications resign from additional languages and the big ones are focused only on the languages with the largest user group.

So why Android doesn’t have feature like Google Chrome to automatically translate the app?

Well, it does now!

Use automatic app translation!

stringX is an Android SDK, which generates translated string resources to over 100 supported languages. Simple integration and simple translation process!

Example

In Blood Pressure app, stringX increased session time of users, which native language hadn’t been supported before. In other words, user with automatically translated app is engaged as much as user whose native language is supported! Needless to say, session time and user engagement are the key factors, which influence app earnings and growth.

First version of stringX has been introduced in August, then second version (available now) has been introduced in October.

How to

Let’s see how stringX has been integrated into Blood Pressure app. It has 16 natively supported languages, each one provided by volunteers. Sounds fantastic, however each update is very troublesome, because at least 16 users have to be reached for help with new translations. After all it ended up with translations from Google Translate. Now with stringX all those problems are gone and extra 86 languages are supported!

Integrating stringX library

  1. Make sure you have jcenter maven repository in your config.

In root of your project build.gradle

allprojects {
repositories {
jcenter()
}
}

2. Add stringX dependency in your module’s build.gradle

dependencies {
...
compile 'io.stringx.sdk:stringx:1.1.1'
}

3. Configure stringX

  • Implement Translatable interface in your class extending Application
  • in onCreate() method initialise stringX
  • call setAutoTranslatedLanguages to define Languages that you are will translate in stringX app
  • call setSupportedLanguages to define languages that your app already supports and don't need automatic translation
  • call addStrings to provide app string class, which will be used to fetch resources. Keep in mind that R.string.class will contain all merged string resources of your app and any library you use
  • call excludeStrings to remove strings that you don't need to translate, eg. from support library.
  • call build to apply all the changes and build options, which will be used to configure stringX
Options options = new Options.Builder(this, English)
.setSupportedLanguages(English, French, German, Spanish, Hungarian, Italian, Polish, Portuguese, Russian, Ukrainian, Slovak, Chinese_Simplified, Chinese_Traditional, Arabic, Dutch, Greek)
.setAutoTranslatedLanguages(Language.values())
.addStrings(R.string.class)
.excludeString(R.string.app_name, R.string.default_web_client_id, R.string.firebase_database_url, R.string.gcm_defaultSenderId, R.string.google_api_key, R.string.google_app_id, R.string.google_crash_reporting_api_key, R.string.google_storage_bucket, R.string.project_id, R.string.google_play_url, R.string.create_backup, R.string.pdf, R.string.url_facebook, R.string.url_googlePlus, R.string.url_help, R.string.url_play, R.string.url_short, R.string.e_mail, R.string.firebase_database_url, R.string.google_app_id, R.string.google_api_key, R.string.google_storage_bucket)
.excludeStrings(com.google.android.gms.R.string.class)
.excludeStrings(android.support.design.R.string.class)
.excludeStrings(android.support.v7.appcompat.R.string.class)
.excludeStrings(android.R.string.class)
.build();
stringX = new StringX(options);

Example Application class:

public class BloodPressureApplication extends Application implements Translatable {

private StringX stringX;

@Override
public void onCreate() {
super.onCreate();
initTranslation();
}

private void initTranslation() {
Options options = new Options.Builder(this, English)
.setSupportedLanguages(English, French, German, Spanish, Hungarian, Italian, Polish, Portuguese, Russian, Ukrainian, Slovak, Chinese_Simplified, Chinese_Traditional, Arabic, Dutch, Greek)
.setAutoTranslatedLanguages(Language.values())
.addStrings(R.string.class)
.addStrings(com.szyk.extras.R.string.class)
.excludeString(R.string.app_name, R.string.default_web_client_id, R.string.firebase_database_url, R.string.gcm_defaultSenderId, R.string.google_api_key, R.string.google_app_id, R.string.google_crash_reporting_api_key, R.string.google_storage_bucket, R.string.project_id, R.string.google_play_url, R.string.create_backup, R.string.pdf, R.string.url_facebook, R.string.url_googlePlus, R.string.url_help, R.string.url_play, R.string.url_short, R.string.e_mail, R.string.firebase_database_url, R.string.google_app_id, R.string.google_api_key, R.string.google_storage_bucket)
.excludeStrings(com.google.android.gms.R.string.class)
.excludeStrings(android.support.design.R.string.class)
.excludeStrings(android.support.v7.appcompat.R.string.class)
.excludeStrings(android.R.string.class)
.build();
stringX = new StringX(options);
}

public StringX getStringX() {
return stringX;
}
}
  • In your activity’s onResume call StringX.get(this).onResume(this) to show pop-up for user.
@Override
protected void onResume() {
super.onResume();
StringX.get(this).onResume(this);
}
This is what Korean user will see

Now the app is configured the way that for all languages except (English, French, German, Spanish, Hungarian, Italian, Polish, Portuguese, Russian, Ukrainian, Slovak, Chinese_Simplified, Chinese_Traditional, Arabic, Dutch, Greek) a pop-up will be shown asking user whether to switch to translated version, if not then default( in this case English) will be used.

Translating app

App is properly configured and can be discovered by stringX app, which will collect translations from the cloud and store them to your account, so that you can re-use each translation for any other app.

Translation can be done in few simple steps.

  1. Install stringX app

2. Before you start you can preview all resources, which will be translated basing on stringX configuration.

Resources preview

3. Next simply pick languages you wish to translate to. All languages are recommended as you will target users, for who most of the apps most likely are not translated, except yours!

Languages picker

4. Finally hit Translate button and wait till the translations are finished. It may take a while basing on how many languages you have chosen.

Apps visible to to stringX

Preparing build

Once your translations are done you can export them by hitting the Export button. What happens now is zipping all stringx.xml resources for each selected languages to proper language folder and provide to download using eg. Google Drive or simply email.

Finally unzip the file you just received and paste in all the folders to your project eg. $Project_root/app/src/main/res/

Follow project site on facebook or visit official site for more info.

--

--