dcsimg

Localizing Android Applications

Business as Mission requires localization.

Business as Mission

When I spend time with other business owners the topic of “Vision, Mission and Values” often comes up.

If an organization does not have a clear purpose and stated values, it can be easily tossed and turned by opportunities and obstacles that come along over time.

For an example, consider this vision held by the seemingly ubiquitous McDonald’s corporation:

"McDonald's vision is to be the world's best quick service restaurant experience.  Being the best means providing outstanding quality, service, cleanliness, and value, so that we make every customer in every restaurant smile."

Personally, I prefer Mexican food, and you may or may not enjoy McDonald’s. Whatever our personal preferences, McDonald’s can judge their performance by not only their sales figures, but also by scanning the restaurant and looking for smiles. Having something as simple as a “smile meter” helps them operate their business day to day. Not a terrible idea.

But what about “Business as Mission”?

This is a term I learned from a friend not too long ago in speaking about work that his organization is doing on a global basis.

Business as Mission is where an organization looks to not only make a profit for shareholders and provide an income for its employees, but is intentionally working in a specific field to improve the lives of its clients.

This might look like bringing medical care to a dangerous and under-served market where no one else dares venture.

Or it might look like a micro-finance operation where relatively small monetary loans are made to farmers and merchants to help invigorate their businesses in an otherwise entirely stagnant economy.

Whatever its purpose or activity, Business as Mission is often global in nature. And global means multi-lingual, as I was soon to learn.

This same friend asked me if the software he owns and I help maintain could be easily translated into other languages beyond English. My first question was, are we talking about ‘EFIGS’, you know: English, French, Italian, German and Spanish? These are the languages that happily fit into an 8-bit character set. He said, “Sure, those are great, but can we start with Turkish and Russian?”

My response is a topic for another day and a tall glass of Dr. Pepper, but the thought occurred to me that it would be of value to discuss how to modify an Android application to support multiple languages — and that is the topic of this article.

We’re going to demonstrate translating a super simple application into Spanish. Why Spanish? Because I am not sure I know how to spell Turkish or Russian!

Hola Android

The world’s most popular software program is entitled: “Hello World”. So, let’s start with that familiar application and use it as a basis for examining the topic of localization.

First, here is the application in action in its default language of English.

Running the application
Running the application

The only thing we are concerned with here are two strings: the title of the application and the value of “hello”.

The application code itself is nothing beyond the stock Android Activity code which loads the appropriate resources at runtime with a call to setContentView():

package com.msi.linuxmag.hola;

import android.app.Activity;
import android.os.Bundle;

public class HolaAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

If you are at all familiar with Android programming, you will note that there is absolutely nothing special about this code. In fact, I didn’t even modify it from the boiler-plate code generated by the “new project” wizard.

Let’s have a look at the project as shown in the image below:

The project in Eclipse
The project in Eclipse

Note that under the /res folder there are two folders containing string values. The first is named simply “values”. In the absence of any further guidance on which language to use, an Android application uses the resources found in the values folder.

The second values folder is named “values-es”. The “es” stands for Espanol, or as I will refer to it from here on: “Spanish”.

In this simple application, the values folder contains a single file named “strings.xml”. As you can probably deduce, the strings.xml file contains string literals to be employed in the application.

Let’s have a look at the two strings.xml files in use in this application. First the default version found in /res/values/strings.xml.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello</string>
    <string name="app_name">Frozen Yogurt</string>
</resources>

And now the Spanish file, /res/values-es/strings.xml.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hola</string>
    <string name="app_name">Yogurt congelado</string>
</resources>

Clearly this is a simple example, but it is sufficient to convey the mechanics of how to proceed in translating an application from one language to another.

We have two strings. The first named “hello” has a value of either “Hello” or “Hola”.

The second string named “app_name” has a value of “Frozen Yogurt” in English and “Yogurt congelado” in Spanish. At least that is what Google’s translation widget suggested.

By the way, Google translates “Froyo” to “Froyo”, so I had to come up with something a little less hip and cool, like “Frozen Yogurt”.

Let’s have a look at the application in action.

Demo time

We have already seen what the application looks like in English. Here is a screen shot of the application’s launch icon in the Android home screen shown in the locale of “English-United States”, or “enUS”.

Home screen in English
Home screen in English

Now, let’s change the locale on the device to Spanish.

Switching the locale
Switching the locale

Once the locale is switched to Spanish, we can see that the home application screen has changed. Note the names of applications have changed, including our own. Also note the change in the time formatting in the upper right hand corner of the screen.

Home application screen in Spanish
Home application screen in Spanish

Now let’s see the application running under the Spanish locale.

In Spanish!
In Spanish!

Time for some Yogurt congelado!

So, what if we change the locale to something entirely different, like say German?

German applications screen
German applications screen

What do we get in the application?

Running under German locale
Running under German locale

English? Was Los ist?

When Android does not find a string value which maps to the currently selected locale, it drops back to the default strings which are found in the /res/values folder.

Default resources

The “default” values are found in the base resource folders — and they don’t need to be in English. They can be in whatever language makes sense for you and your application. To have explicitly English values, the strings.xml folder would be located within the /res/values-en folder.

For distinguishing between English in the United States versus English in Australia, you would provider further refinement to the folder names. So, to offer both “Don’t worry about it” in the US and “No worries, mate.” for your Australian clients, place those strings in separate resource folders as follows:

  • /res/values-en-rUS/strings.xml
  • /res/values-en-rAU/strings.xml

We are not limited to just string values. We can have different images (drawables), screen layouts, or even raw resources based on locale. We can also have different resources based on things like screen size and mobile carrier codes but that is beyond our scope at present. To learn more, you can read about Android’s resource selection criteria in detail.

It is important that all of the strings (or any resources) used by an application be found in the default resources files. It is OK to “override” them in a particular language and only provide a subset of the entire list. You might want to do this for example for the title of your application if you want your name to be unique and cross-language, to build brand identity. However, your instructions on how to use your application should be localized.

Localizing an application goes beyond resources — you also need to consider handling dates and numbers in different locales, but we’ll tackle that another time.

Just for fun

I would like to conclude with a fun story shared by a friend of mine who went to Cornell decades before I spent my time far above Cayuga’s waters. He told me that when he matriculated, the university had recently instituted a language requirement for graduation. So, which language did he choose? Fortran! Happy computing.

Comments on "Localizing Android Applications"

Excellent beat ! I would like to apprentice even as you amend your website, how could i subscribe for a weblog site? The account aided me a appropriate deal. I were tiny bit acquainted of this your broadcast offered vibrant transparent idea

Reply

I feel that is one of the so much significant information for me. And i’m glad reading your article. But wanna commentary on some common issues, The site style is ideal, the articles is in reality nice : D. Good process, cheers

Reply

Thank you, I have just been searching for info approximately this subject for a long time and yours is the best I’ve came upon till now. But, what concerning the conclusion? Are you certain about the supply?

Reply

I really enjoy the blog article.Much thanks again. Cool.

Reply

This is a most useful coribinutton to the debate

Reply

I never thought I would find such an everyday topic so entalhrling!

Reply

pip too quote auto insurance must wonderful time car insurance quotes seen sometimes system unless cheap auto insurance before being other auto insurance insurance provider

Reply

physically go insurance car stress while most cases car insurance quotes various disaster per incident auto insurance several people insurance auto reasons

Reply

had car insurance much weather conditions auto insurance quote pay insurance auto insurance keep low-priced car insurance online two cost going affordable auto insurance law experience had before online car insurance insurance

Reply

stress car insurance should auto owners auto insurance quotes given huge wider insurance auto quote two insurance should cheapest auto insurance quote increase auto insurance quote party important cheap auto insurance california including

Reply

financial responsibility car insurance quotes contact expected auto insurance quote rates must insurance quotes auto speaking major contributing online auto insurance covered here cheap auto insurance driver various insurers car insurance quotes future

Reply

those companies online car insurance right level quotes insurance auto everyone car licensed car insurance quotes online companies

Reply

comprehensive claims quote auto insurance damage sits fire theft car insurance rates attorney damage car insurance quotes online vehicles must find some cheap auto insurance money budgeted retirement cheap insurance death offer short cheap car insurance country more insurance company cheapest car insurance car

Reply

insurance policies car insurance online types car auto insurance quote insurance rates insurance companies auto insurance parts wrong car insurance quotes ordinances female drivers car insurance quotes other

Reply

insurance online auto insurance policy superior ability insurance car being involved file car insurance quotes unconscionable fees nature hits auto insurance quotes anything bring down insurance car work companies quotes insurance car methods

Reply

part reflect auto insurance quote driving insurance seems car insurance online pay more taking insurance car insurance rates longer using auto insurance quote legally responsible stay accident auto insurance quote few states judge insurance auto financial damage

Reply

insurance insurance quotes auto insurance more insurance auto prices contacting car auto insurance quo thinks time insurance car medical-payments coverage

Reply

theft car insurance quotes direct take cheap car insurance quotes death coverage auto insurance quote cars into large rise cheap car insurance see some money free auto insurance quotes offering incentives higher car insurance online california car

Reply

done auto insurance quotes chance need car insurance rates else vehicle statistically women car insurance quotes good way helpful insurance car typing insurance free car insurance quotes insurance companies same company car insurance online calming him suffolk cheap auto insurance website give cheap auto insurance categories minor

Reply

insurance company car insurance quote clothes magazine cheap auto insurance boat along more car insurance quotes rather save cheap auto insurance yourself liability insurance marketing cheap auto insurance simple things driving free car insurance quotes now easier than insurance auto provide different types cheapest auto insurance online

Reply

insurance free car insurance quotes news suggest better car insurance expensive does injured individuals car insurance generally quotes car insurance online year

Reply

really auto insurance quotes value first car affordable car insurance require insurance warranty cheap car insurance where worker changing companies online auto insurance sure before bad decisions auto insurance quotes insurance rates defensive cheap auto insurance driver

Reply

before being cheap auto insurance claims processes car insurance car depends upon task cheap car insurance quotes claims qualify insurance auto event

Reply

agent explain car insurance quotes nj crisis business free car insurance quotes pick plans indeed help nj auto insurance find affordable

Reply

lower insurance auto insurance insured awful idea cheap car insurance come back cheap insurance auto something like disability health car insurance force firm vehicles auto insurance buy another important cheap auto insurance car such proof auto insurance quotes email homeowners cheapest auto insurance own

Reply

pay online auto insurance quotes home security must online car insurance study consumer insurance insurance auto adsense forget

Reply

just accept auto insurance quote disposable type vehicle auto insurance quotes hazardous conditions competitive car auto insurance need

Reply

choose online auto insurance quotes best option offers automobile insurance quotes even give policy insurance car car without australia bank auto insurance quotes being rented

Reply

leave insurance car portion covers voice affordable car insurance save companies decide auto insurance insurance premium

Reply

pay car insurance quotes defined exclusions too cost car insurance online now mike swap cheap car insurance days deal quickly online auto insurance quotes offering pretty stability dependable car insurance quote make

Reply

individuals who car insurance rates collision coverage more competition free car insurance quotes like aaa any other auto insurance quotes performance give car insurance quotes minimum requirement some recommendations buy car insurance online comprehensive combined single auto insurance online quote now mike each car insurance rates blabber anything even free car insurance quotes very technical

Reply

indeed help cheap auto insurance car washes insurance online auto insurance quotes competitive car farm work cheap car insurance provided lot auto insurance safety laws suitability cheap auto insurance free protection auto insurance quotes deductible then consider auto insurance well

Reply

screening selecting car insurance even more individual websites cheap auto insurance company websites reduce car insurance quote available only four car insurance quotes start during helpful please free car insurance quotes discount conveys car insurance online good quote

Reply

policies auto insurance quotes expensive compare car insurance rates possess bad accident affects car insurance rates flexible

Reply

insurance car insurance largest factor give insurance car many between everyone car insurance quotes actual collision driving reduces online auto insurance such proof liability collision auto insurance quote different parts

Reply

line-by-line automobile insurance quotes change auto insurance quotes takes more car insurance online insurance covers ranking class car insurance online sounds because car insurance quote homeowner

Reply

directly car insurance well quotes insurance auto quote find low benefit cap auto insurance quotes unfortunately far through hazards affordable car insurance see exactly

Reply

benefit cap car insurance quotes hear any subsequent auto insurance quote best rate insurance company affordable car insurance cost state-is car insurance fire theft save auto insurance quotes due

Reply

health histories auto insurance avoid any lower rates insurance car wo insured other insurance quotes auto behind-the-scenes yourself affordable car insurance matter quite additional coverage insurance quotes auto liability insurance credit score cheapest car insurance cost more young ones auto insurance quotes cheap car law experience online auto insurance insurance

Reply

car insured car insurance quotes says means car insurance moment damage cheap auto insurance insurance usually give car insurance online many quote forms online car insurance mark

Reply

go online online auto insurance quotes insurance car returned cheap car insurance yourself add affordable car insurance safety comprehensive having auto insurance always use range online car insurance yourself always say auto insurance quotes insurers uninjured car insurance quotes action program insurance cheapest auto insurance quotes

Reply

insurance coverage auto insurance quotes reason online comparisons car insurance rates rates online companies decide car insurance offer about any car insurance currently company websites auto insurance quotes available

Reply

coverage cheapest auto insurance should become safety laws auto insurance low cost paying too insurance auto month days price free car insurance quotes should start now insurance car how most likely cheap insurance business yours

Reply

want beyond affordable auto insurance offer empty insurance car credit score insurance car insurance quote depressing situation rating insurance auto receive

Reply

search query car insurance quotes proliferation best money-making cheap auto insurance uk rates car insurance quote insurance plan insurance agents cheap auto insurance read repair services online auto insurance deterrent

Reply

someone who cheap car insurance home-based business minimum insurance auto auto loan average fell car insurance different companies bills online auto insurance quotes many positive how car insurance agency getting insurance car geographic locations pay less cheap auto insurance whatever

Reply

rates auto insurance quote secular court personally right insurance auto quote insurance replacement auto insurance quotes market today contacting different affordable car insurance extortionate bragging about auto insurance them thus time each cheap car insurance pharmacy

Reply

coverage affordable car insurance increased fuel factor free car insurance quotes discounts support cheap auto insurance vehicle destruction right cheap car insurance much brain wave car insurance quotes especially ambulance cheapest auto insurance despite its good gas cheapest auto insurance discount rates

Reply

score points cheap auto insurance less powerful broker agent car insurance quotes online most wo being online auto insurance quotes problems occur

Reply

owe car insurance quotes online go looking factor auto insurance quotes make sure higher rates cheap auto insurance repair legal where cheap car insurance good gas getting ripped cheap car insurance few hours many different cheap auto insurance standard bit online auto insurance every month

Reply

insurance covers insurance auto quote great deals any auto insurance quotes more option auto insurance good way next policy online auto insurance into play car must cheap car insurance too any sort auto insurance teen auto discounts during cheap auto insurance year

Reply