Software Projects

Running the Apertium Translator on Android: Offline Machine Translation on a Mobile Device

Posted in Uncategorized by rmt on September 26, 2012

A few days ago I put together an Android app that runs the Apertium open source rule-based translation system.

For his excellent 2012 Google Summer of Code project, Mikel Artexte has converted several of the Apertium language pairs into standalone, self-contained Jar files that have no outside dependencies. The end result is a set of cool little embeddable modules that do real language translation on mobile devices without requiring a network connection at all.

One of the challenges I ran into while making this app was that the default Proguard settings cause the translation system to crash at runtime. To avoid this, I tried a whole bunch of settings and finally found a set of Proguard directives that preserve the Apertium offline translation, avoiding the crashing:

https://gist.github.com/3792747

# Preserve Apertium offline translation
-dontwarn com.sun.org.apache.bcel.internal.**
-dontwarn java.awt.**
-dontwarn javax.swing.**
-dontwarn javax.tools.**
-dontwarn javax.xml.stream.**
-dontwarn org.apertium.ApertiumGUI
-keepattributes InnerClasses
-keep class org.apertium.**
-keepclassmembers class * {
    public *; protected *; private *;
}

Together, these settings preserve the translation-related classes packaged in the Apertium Jar files, saving them from Proguard’s obfuscation process that leads to crashing. These Proguard settings can be added on top of the default Android Proguard optimizations by adding the following line to the project.properties file:

proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard.cfg

With these settings in place, the translations work correctly, with the optimized translation results being returned after about 5000ms for a short phrase on my phone.

Overall, I’m pleased with the Android offline translation app results, particularly because these translations work without requiring a network connection. Another advantage is that this system can do translations for a few languages that are currently unsupported by Google Translate and Bing Translator.

UPDATE (Jan. 1, 2013)
A new version of the offline translation app is available.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s