Android Localisation and Why You Should Care.

You’ve created an app, and its starting to trend, in fact, its probably getting international recognition. Your popular app is stable and bug-free. The new design is just stellar, but does your app support languages other than English?

If your answer is anything but “yes,” you need to act on it before it’s too late. As the internet is making the world a smaller place, assuming that everyone will use your app in English is just inconsiderate. Internationalization is important in order to reach the global market.

Image result for cell phone language choices

App localization (l10n for the nerdy folk) is the adaptation of an internationalized app to fit a specific language or culture. It isn’t just displaying your strings in a different language. It also involves using the correct formats for data like dates, times and quantities.

In this blog series, I’m writing about localizing Android apps in three parts:

  1. String resources
  2. Common mistakes people make while localizing
  3. Tools to aid app localization

This part will focus on string resources — what they are, how to define them and use them in your code.

We’ve spent the last few years building an Android app for the most remote, rugged parts of the world. Here are our learnings on how to build apps for the “next billion”.

What Are String Resources?

Hard-coding text and assets directly into code will make app localization difficult, if not impossible. Android SDK solves this by using resources. Resources are text strings, layouts, sounds, graphics, and any other static data that your Android app needs.

An app can include multiple sets of resources, each customized for a different device configuration. When a user runs the app, Android automatically selects and loads the resources that best match the device. Export all your strings into res/values/strings.xml to make localizing strings easier.

Image result for android sdk

To provide alternate values for your resources, use multiple resource directories with configuration qualifiers like res/values-fr-FR/strings.xmlfor French as spoken in France. The localized string resources for your application must be in theres/values-<language code>or res/values-<language code>-<country code>folder. (More on why it is better include the country qualifier later in this series.)

Here is an example of your default string resources in res/values/strings.xml. We usually supply resources here in the en-USlocale.

<?xml version="1.0" encoding="utf-8"?>                       <resources>
<string name="hello_world">Hello world!</string>
<string name="hello_name">Hello %s!</string>
</resources>

An alternate version of the above resource file in French as spoken in France will be placed in /res/values-fr-FR/strings.xml.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello_world">Bonjour le monde!</string>
<string name="hello_name">Bonjour %s!</string>
</resources>

Using String Resources in Layouts

To use your resources in layout XMLs, call that resource using its resource type, which in this case is @string. Android will automatically select the appropriate resource for the selected configuration. So, @string/hello_worldwill show up as “Bonjour le monde!” when the locale is set by the user to fr-FR, and “Hello world!” will be displayed otherwise.

Here is an example of a TextView using a string resource:

<TextView
android:id="@+id/hello_world_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

Using String Resources in Code

The identifiers of all our string resources can be referenced in code using R.string. Just like @string.hello_world in layouts, R.string.hello_worldwill be used in code.

val helloTextView = findViewById<TextView>(R.id.hello_world_textview)
// Shows "Bonjour le monde!" in French
//and "Hello world!" in other languages
helloTextView.setText(R.string.hello_world)

The above code gives the same result as using android:text in your XML.

You can format your resource strings just like we do String.format(). You use Context.getString() for this purpose.

val userName: String = "Adwait"

val helloTextView = findViewById<TextView>(R.id.hello_world_textview)
// Shows "Bonjour Adwait!" in French
//and "Hello Adwait!" in other languages
helloTextView.setText(getString(R.string.hello_world, userName))

We all don’t speak the same language. App localization opens up your app to a larger audience, which translates into increased sales and increases the chances of your app becoming a worldwide hit.

Resources are just one part of localizing your app. Stay tuned for the next blog in this series, which will help you not break language and avoid common app localization mistakes!


Smart Mobile devices make communication so much simpler. Having a mobile application for your business is the first step to allowing smooth communication between you and your customers. We create/produce applications that cater for iOS and Android supported mobiles be it a tablet or a mobile phone we will be able to cater for you. Visit www.whereisthebeef.co.za for more information.

Leave a Reply