Saturday, June 19, 2010

Localisation & Internationalisation on Android, the easy way


You often hear about Internationalisation (internationalization in US English, or i18n for short), and Localisation (Localization in US English, or L10n for short) in software development circles... ever wonder what that's all about?

Of course you do.

Definitions vary, but the basic idea is generally easily summarised:
  • Internationalisation is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes.
  • Localisation is the process of adapting internationalized software for a specific region or language by adding locale-specific components and translating text.

These two terms usually go hand-in-hand as the term 'globalisation'. See?
.. Course you do.


Each language is given a language code such as 'en-au' for Australian English, or 'en-us' for American English. These language codes are two-letter lowercase ISO language codes (such as "en") as defined by ISO 639-1.
But how do we use this? And how can we easily apply these concepts to our Android programming?

.. Good question!

Best practices in Android suggests defining all your string resources in a 'strings.xml' file (you're doing this already, right?) and placing that file in the 'res\values' folder in your project.

Localisation in Android is as simple as creating a new version of this file and folder, renaming the 'values' folder to 'values' + the language code you wish to support.

For example, all your Italian translations would be located in 'res\values-it\strings.xml', your Chinese translations in 'res\values-zh\strings.xml' as seen here:



If you don't happen to have a friend from whatever country you're trying to translate your app for, just use Google translate.

Once you're done your app is one simple step away from global domination.

All you need to do is copy those freshly translate strings back into a strings.xml file in Eclipse, and, as long as the folder the strings.xml file is located in has the name of 'values' + the language code you're wishing to support, magically any user who has their phone locale set to a locale that uses that language, your translated strings will be used.

No code changes are required.

Handy eh?

Sunday, June 6, 2010

My first App is now available on the Android market, free.


Aspect Ratio Calculator is a simple tool that makes it easy to calculate the dimensions to resize an image.

Great for graphic designers, or anyone resizing images for blogging, it's available in Spanish, Russian, Portuguese, Chinese & Italian.

.. And of course, English ;)

Sunday, April 25, 2010

Book Review: Professional Android 2 Application Development

Professional Android 2 Application Development (Wrox Programmer to Programmer)

Written by an Android authority, this up-to-date resource shows you how to leverage the features of Android 2 to enhance existing products or create innovative new ones.

Serving as a hands-on guide to building mobile apps using Android, the book walks you through a series of sample projects that introduces you to Android's new features and techniques.

It is perhaps one of the most in-depth Android books available, and is also very regularly updated, currently covering Android SDK 2.1 r1.


The Book's author, Reto Meier is a software developer who has been involved in Android since the initial release in 2007. He is an Android Developer Advocate at Google.

Monday, April 19, 2010

Writing Real-Time Games for Android - Google I/O 2009



Do vertex arrays keep you up at night? Do you have nightmares involving frame rates and event loops? If so, this session might have the cure for your condition.

Chris Pruett will discuss the game engine that he developed, using it as a case study to explain the common pitfalls and best practices for building graphics-intensive applications. You'll learn how to properly pipeline game and rendering code, manage drawing surfaces, and incorporate 2D and 3D graphics cleanly.

Tuesday, April 13, 2010

Some notes about Android Context



Context is an interface to global information about an application environment. It's an abstract class whose implementation is provided by the Android system.

Context allows access to application-specific resources and classes, as well as calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.

All the widgets receive a Context parameter in their constructor. In a regular Android application, you usually have two kinds of Context, Activity and Application. It's usually an Activity Context that the developer passes to classes and methods that need a Context.

Basically the Application context is associated with the Application and will always be the same throughout the life cycle of your app, where as the Activity context is associated with the activity and could possible be destroyed many times as the activity is destroyed during screen orientation changes and such.

In particular you should be careful when dealing with anything that deals with the GUI that requires a Context. For example, if you pass the application Context into the LayoutInflator you will get an Exception. It's good practice to use an Activity's Context within that Activity, and the Application Context when passing a context beyond the scope of an Activity to avoid memory leaks.

Here's a quick snippet showing how you can find both the Activity Context and the Application Context:


public class MyActivity extends Activity {
public void aMethod() {
Context actContext = this; /*returns the Activity Context since Activity extends Context.*/

Context appContext = getApplicationContext(); /*returns the context of the single, global Application object of the current process. */

Button btnGoToFirstAct = (Button) findViewById(R.id.btnGoToAct1);
Context vwContext = btnGoToFirstAct.getContext(); /*returns the context of the View. */



When run in the debugger, you can see the results of this:


 Notice that the vwContext in this case also returns the Activity Context.



Hope that helps answer some questions. Drop me a message in the comments if you have anything to add.