2 Aug

Android Localization

Share Button

This is a very basic tutorial for building multi language app supporting Hindi, French, and English etc. Android supports millions of users over 190+ countries, so it is always good to localize the app as much as possible if you need to make a global presence. While localizing, we need identify the texts that is supposed to be localized.

In the main_activity.xml, we have this string ‘Hello’ that can be displayed in local languages – Hindi, French.

<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”

    xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent”

    android:layout_height=”match_parent” android:paddingLeft=”@dimen/activity_horizontal_margin”

    android:paddingRight=”@dimen/activity_horizontal_margin”

    android:paddingTop=”@dimen/activity_vertical_margin”

    android:paddingBottom=”@dimen/activity_vertical_margin” tools:context=”.MainActivity”>

 

 

    <TextView

        android:layout_width=”wrap_content”

        android:layout_height=”wrap_content”

        android:layout_marginBottom=”40dp”

        android:layout_centerHorizontal=”true”

        android:layout_centerVertical=”true”

        android:text=”@string/hello”

        android:textSize=”45dp”

        android:textStyle=”bold” />

 

</RelativeLayout>

Create a directory value-hi(country code). In this example, I have written the Hindi version of Hello.

 

<resources>

    <string name=”app_name”>LocalizationExample</string> 

    <string name=”hello”>नमस्कार</string>

    <string name=”action_settings”>Settings</string>

</resources>

 

That’s it, Run the app. Go to System Settings –>Languages & Input. Choose language. Now the app shows the localized texts.

image

Share Button