Android Localization: An Advanced Guide for Transifex Native

Petros Douvantzis
November 22, 2021
5 min read

Android is the leading mobile operating system in the world. According to Statista, Android possesses more than 70% of the global market share. That’s why Android localization becomes so important. Users tend to prefer apps that have their text, numbers, dates, currency etc localized for their region.

Android Studio provides the developers with a lot of tools to handle Android localization, as long as some simple principles are followed. Strings should be placed in a string resource file such as `strings.xml`. Placing hard-coded strings in layout files or in code should be avoided. Android Studio will even warn you if you try to do this. Localizing the strings involves creating separate `strings.xml` files and placing them in subdirectories named by the respective locales. The file can be edited by hand or via Android Studio’s Translations Editor.

These `strings.xml` files can be copied, translated and moved back to the project. Even though this looks fairly straightforward, complexity rises significantly when new strings are added or deleted by multiple developers of your team while ordering and managing translations “by hand”. Another issue with this approach is that updating existing translations or adding support for a new locale requires issuing a new app update.

This post will explain how integrating Transifex Native in your app will improve your Android localization workflow.

Over-the-air Translation Delivery

Using over-the-air translation delivery, teams can update the translated strings without issuing a new application update.

When using the Transifex Native SDK, you can also bundle the latest translations in the app just before issuing an update.

It is up to you to control when the app will fetch the latest translations from Transifex using the asynchronous fetchTranslations method. When the SDK has downloaded the latest translations, they are available on the next application launch.

Let’s see all that in plausible scenario from start to finish:

  • Developers of the “Awesome” app push the strings from Android Studio to Transifex via the transifex.jar command line tool.
  • The localization team translates the pushed strings.
  • Developers use the pull command of transifex.jar, to download and store those translations in “txstrings.json” files, which are then bundled in the app.  The SDK will attempt to load the stored translations from these files. 
  • The developer team adds a call to the fetchTranslations method in the application launch, so that the application can update the cached translations.
  • The team releases a new version on Google Play or on another store. Soon after the release, the support team identifies a couple of missing or incorrect translations.
  • Without having to re-bundle those translations and issue a new update, the team can just add the missing translations and fix the incorrect ones from the Transifex web interface. The application will then automatically download and update said translations and will serve them on the next application launch! 

Note: As of May 2022, Transifex Native comes with automatic CDS cache invalidation, which means that translations should be pushed automatically to the app without developer involvement.

Pushing Source Strings to and Pulling Translations from Transifex

Τhe Transifex Native SDK, is accompanied by a command-line tool which allows Android developers to interface with Transifex CDS directly, without needing to deal with the multiple “strings.xml” files.

Pushing Source Strings

Using the push command of the command-line tool, you can have the tool parse your project’s source strings and send them to Transifex.

First, you can build or download transifex.jar following the instructions found on the repository. You can then enter the root directory of your project from the command line and execute a command similar to the one below:

java -jar /path/to/transifex.jar push -t <transifex_token> -s <transifex_secret> -m <app_module_name>

The push command behavior can be controlled via a number of different arguments. You can learn more about the arguments here or by executing the following:

java -jar /path/to/transifex.jar help push

Pulling Translations

As mentioned above, you can also use the command-line tool to download (or pull) the translations from Transifex into your Android Studio project. The pull command is as follows:

java -jar /path/to/transifex.jar pull -t <transifex_token> -m <app_module_name> -l <locale>

For a full argument list of the pull command, you can execute the following:

java -jar /path/to/transifex.jar help pull

The pull command requires a list of the translated locales that will be downloaded from Transifex and your app’s module name. The tool places the downloaded translations to your module’s “asset” folder, whose contents are automatically bundled in the app and can be accessed by the Transifex SDK at runtime.

Handling Pluralization in the Transifex UI

The Transifex Native SDK for Android also supports pluralization out of the box. The command-line tool will parse any “plurals” found in your source strings and push them to Transifex. At the same time, the SDK will properly render the translated pluralization strings in the Android application.

This feature minimizes the risk of incorrect translations due to the different pluralization rules of each locale, as the team will handle all of the pluralization translations directly within the user-friendly Transifex web interface.

The above Android localization guide covers the most important features that Transifex Native Android SDK offers. Leveraging those features for your team will streamline the localization process and reduce the possibility of having localization errors end up in your released app. If you’re looking to localize your iOS app, you may want to check this guideFor more information on the Transifex Android SDK, refer to our documentation or YouTube playlist

Petros Douvantzis
FacebookgithubGoogle+Fill 88Twitter