Support multi-language in Android

Support multi-language in Android

It’s always a good practice to extract UI strings from your app code and keep them in an external file. Android makes this easy with a resources directory in each Android project.
If you created your project using the Android SDK Tools (read Creating an Android Project), the tools create a res/ directory in the top level of the project. Within this res/ directory are subdirectories for various resource types. There are also a few default files such as res/values/strings.xml, which holds your string values.

Create Locale Directories and String Files

To add support for more languages, create additional values directories inside res/ that include a hyphen and the ISO language code at the end of the directory name. For example, values-es/ is the directory containing simple resources for the Locales with the language code “es”. Android loads the appropriate resources according to the locale settings of the device at runtime. For more information, see Providing Alternative Resources.
           This is the sample code for support multi-language in android applications.Please follow the simple steps to create multi-language support applications.

It supports multi-languages like French, Dutch, Italian, Japanese, Hindi.Likewise, we can create localized strings to any language all texts, inputs.

CLICK HERE for more details.

Step 1:
In res folder below create the five values folder named values-de,values-fr,values-hi,values-it,values-ja inside that folder create strings.xml

values-de/strings.xml :(Dutch)

<string name="welcome">Welkom!</string>
    <string name="Username">e-mail adres</string>
    <string name="password">wachtwoord</string>
    <string name="Login">Login</string>
    <string name="SignIn">inloggen</string>
    <string name="forgot_password">wachtwoord vergeten?</string>

values-fr/strings.xml:(French)

<string name="welcome">Accueil !</string>
    <string name="Username">adresse e-mail</string>
    <string name="password">mot de passe</string>
    <string name="Login">connexion</string>
    <string name="SignIn">se connecter</string>
    <string name="forgot_password">mot de passe oublié?</string>

values-hi/strings.xml :(Hindi)

<string name="welcome">स्वागतम</string>
   <string name="Username">ईमेल पता</string>
   <string name="password">पासवर्ड</string>
   <string name="Login">लॉगिन</string>
   <string name="SignIn">साइन इन</string>
   <string name="forgot_password">भूल गया पासवर्ड ?</string>

Step 2
Create the activity_main.xml and copy the below code.

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@+id/RelativeLayout1″
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background=”#4682B4″
android:orientation=”vertical” >
<LinearLayout
android:id=”@+id/TopLayout”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentLeft=”true”
android:layout_alignParentRight=”true”
android:layout_alignParentTop=”true”
android:background=”#778899″
android:gravity=”center”
android:orientation=”horizontal”
android:weightSum=”10″ >

<TextView
android:id=”@+id/Logintitle”
android:layout_width=”match_parent”
android:layout_height=”60dp”
android:gravity=”center”
android:text=”@string/Login”
android:textAppearance=”?android:attr/textAppearanceLarge”
android:textColor=”#FFFFFF”
android:textSize=”20dp”
android:textStyle=”bold” />
</LinearLayout>

<LinearLayout
android:id=”@+id/linearLayout1″
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_alignBottom=”@+id/loginEmail”
android:layout_alignParentLeft=”true”
android:layout_marginBottom=”37dp”
android:gravity=”right”
android:orientation=”horizontal” >

<TextView
android:id=”@+id/txtEmailid”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_weight=”1.03″
android:text=”@string/Username”
android:textAppearance=”?android:attr/textAppearanceMedium”
android:textStyle=”bold” />

</LinearLayout>

<EditText
android:id=”@+id/loginEmail”
android:layout_width=”match_parent”
android:layout_height=”40dp”
android:layout_alignParentLeft=”true”
android:layout_centerVertical=”true”
android:ems=”10″
android:inputType=”textEmailAddress”
android:textStyle=”bold” >

<requestFocus />
</EditText>

<TextView
android:id=”@+id/forgotPassword”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentRight=”true”
android:layout_below=”@+id/linearLayout1″
android:layout_marginTop=”23dp”
android:autoLink=”all”
android:linksClickable=”true”
android:text=”@string/forgot_password”
android:textStyle=”bold” />

<Button
android:id=”@+id/submit”
style=”?android:attr/buttonStyle”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_alignParentLeft=”true”
android:layout_below=”@+id/forgotPassword”
android:text=”@string/SignIn”
android:textStyle=”bold” />

<TextView
android:id=”@+id/welcome”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_above=”@+id/linearLayout1″
android:layout_alignParentLeft=”true”
android:layout_alignParentRight=”true”
android:layout_below=”@+id/TopLayout”
android:layout_centerHorizontal=”true”
android:text=”@string/welcome”
android:gravity=”center”
android:textColor=”#483D8B”
android:textAppearance=”?android:attr/textAppearanceMedium”
android:textSize=”24sp”
android:textStyle=”bold” />

</RelativeLayout>

Step 3
Create the MainActivity.java and copy the below code.

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class MainActivity extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);

}
}

Screenshots

Support multi-language in Android

 

Support multi-language in Android
Download

2 thoughts on - Support multi-language in Android

Leave a Reply

Your email address will not be published. Required fields are marked *