Tag Archives: android

Use Android’s Resource-Switching Mechanism For Language Localization & More

To begin with, let’s see what are resources in an Android project. All kinds of static data, such as text strings, layouts and pictures, are considered as resources. And indeed, they are very important, without them any application is useless. But resources may vary based on many situations and the device’s configurations. Luckily, handling resources is quite easy with Android’s resource-switching mechanism, that is, the device automatically sets and loads he appropriate resources depending on the configurations.

exit_sortieFor example, the default language for an app is English and the developer also wants to make the app available in French. Doing the translation for the app is as easy as placing another strings.xml file in res/values-fr folder. When a device that is configured in French tries to open the app, Android will detect there is a strings.xml for French locale and will use values from that file.

Important Note:

Default resources must always be made available, otherwise the app will crash if it is launched in another locale. Locale or alternative resources can be a subset of the default resources, but not vice versa. As an example, maybe you want to translate all texts in your app to French except for the app’s title. then, you need not include the title in the strings.xml file for French locale and Android will load the default title together with French text for everything else.

When creating a resource directory for alternative resources, it is important that we follow the naming scheme specified on the android developer’s website for providing alternative resources.

Side Note:

Changing locale on an emulator for Android is possible with the Custom Locale application or by using the adb shell command:

setprop persist.sys.language [language code];setprop persist.sys.country [country code];stop;sleep 5;start

(Source: http://developer.android.com/guide/topics/resources/localization.html)

Setup Your Android Development Environment Quickly With Android Developer Tools Bundle

Experienced Android app developers probably know what a pain it was to setup a development environment for Android. But now, with the ADT (Android Developer Tools) Bundle, setting up your development environment is a breeze. Seriously. You just need to download the appropriate bundle for your platform (Windows, Mac or Linux), unzip and launch Eclipse. That’s it.

Two minutes, you would have already created a simple Android app with some text on it and images in it. The bundle also includes all the components to create an emulator and launch your app, if you don’t have a device.

Of course, if you prefer to develop your Android apps on another version of Eclipse, you would have to set up everything manually. Have a look on the Android developer’s website for more information.