Language Localization in Android with Example (original) (raw)

Last Updated : 23 Jul, 2025

**Language Localization is a process of changing the application context into multiple languages based on the requirements. Android is an overall operating system that runs on millions of devices worldwide and among various groups. Since the diversity range is enormous, a feature that facilitates local languages adds an advantage to any Android application. Implementation of such a feature requires the need to handle text, audio files, numbers, currency, and graphics appropriately for the locals where our application is used. Through this article, we want to show the implementation of a feature that changes the context language (if explicitly declared) through an Android application. A Sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the **Kotlin language.

1__RgbOh5VABi5es1ALdvD4A-ezgifcom-crop-(1)

Step by Step Implementation of Language Localization in Android

To make an application that changes the contextual language upon the device's preferences in Android, follow the following steps:

**Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select **Kotlin as the programming language.

**Step 2: Create a folder values-hi to store the custom messages

**Step 3: Create a strings.xml file

**Step 4: Add the custom message values to string.xml (regular) and string.xml (hi)

Add a custom message to the pre-existing as well as the newly created strings.xml file. The **entities of both the file must be the same, context may differ. Below is the code for the **strings.xml file.

strings.xml `

GFG | LanguageLocalization This application tests if the language localization works on the device

`

Below is the code for the **strings.xml (hi) file.

strings.xml(hi) `

GFG | भाषा स्थानीयकरण यह एप्लिकेशन परीक्षण करता है कि भाषा स्थानीयकरण डिवाइस पर काम करती है या नहीं।

`

**Step 5: Working with the activity_main.xml file

Now go to the **activity_main.xml file which represents the UI of the application. Create a TextView that would display the custom message. Below is the code for the **activity_main.xml file.

activity_main.xml `

<!--TextView to display the custom message-->
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:gravity="center"
    android:text="@string/custom_message"
    android:textAlignment="center"
    android:textSize="30sp" />

`

**Step 6: Working with the MainActivity.kt file

No changes are made to the **MainActivity.kt file. Keep the **MainActivity.kt file unchanged.

MainActivity.kt `

import androidx.appcompat.app.AppCompatActivity import android.os.Bundle

class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } }

`

**Output: Run on Emulator

**Note : To access the full android application of Language Localization check this repository: Language Localization in Android