Localization in Android

The applications that we use in Android devices can be specific to a particular language. That is where Localization comes in the role. Localization is a process that changes the string into various different languages based on user requirements. In this tutorial, we will implement it practically in our application.

Localization can be done for Dates and time as well. Localizing the string is good for the users, but, how about localizing the date and the time? Yes, it can be done too. Luckily, Android SDK includes the classes that format dates and times according to the locale. In Android SDK these date and time are handled using Date class from java.util namespace. To return the current date and time, you can use java.util.Calendar.

You can code it this way to return the Date and the Time:

Date date= Calendar.getInstance().getTime(); // this will get the date and the time
java.text.DateFormat date_format; //This will get the standard format
Date_format = android.text.format.DateFormat.getDateFormat(this);

And for Time:

java.util.Date date_today = Calendar.getInstance().getTime();
java.text.DateFormat time_format;
time_format = android.text.format.DateFormat.getTimeFormat(this);

Language Codes and Folder names:

To implement it in our application we need to first create separate ‘values’ files in the resource folder specifying the language code.

Few of the common language codes that are used in Android are mentioned below:

LanguageCodeFolder NameArabicarvalues-arBengalibnvalues-bnBulgarianbgvalues-bgChinesezhvalues-zhFrenchfrvalues-frGermandevalues-deJapanesejavalues-jaTibetanbovalues-boHindihivalues-hiTelugutevalues-tePunjabipavalues-pa

The above mentioned code and folder names would be mentioned in the strings.xml file, where the string code would be mentioned as:

  • Say for Hindi:
  • res/values-hi / Strings.xml –
<?xml version="1.0" encoding="utf-8"?>
<resources>
   <string name="app_name">स्थानीयकरण उदाहरण</string>
   <string name="hello">नमस्ते दुनिया</string>
   <string name="DataFlair">डाटा फ्लेयर</string>
   <string name="Akshita">अक्षिता ने आपको टेक्स्ट किया</string>
</resources>
  • Say for Japanese:

res/values-ja / Strings.xml –

<resources>
   <string name="DataFlair">データフレア</string>
   <string name="hello">" こんにちは世界"</string>
   <string name="Akshita">明下はあなたにテキストメッセージを送りました</string>
   <string name="app_name" translatable="false">" 私のAndroidローカリゼーション"</string>
</resources>

#android tutorials #android localization #android localization example #android localization tutorial #localization in android

Localization in Android - Step by Step Implementation
1.55 GEEK