Skip to content
DeveloperMemos

How to Localize an App in Android

Kotlin, Localization, Android Studio2 min read

If you're creating an Android app that will be used by people from different countries or regions, it's important to make sure that the app is available in their language and culture. By localizing your app, you can provide a better user experience for your users, and increase your chances of success in the global market.

In this post, we'll go through the steps to localize an Android app using Kotlin and Android Studio.

Step 1: Add Support for Multiple Languages

The first step in localizing your Android app is to add support for multiple languages. You can do this by adding the appropriate resource files to your project.

  1. Open your app's project in Android Studio.
  2. In the Project view, navigate to the app > res folder.
  3. Right-click on the res folder and select New > Android Resource Directory.
  4. In the Resource type dropdown, select values.
  5. In the Available qualifiers section, select Locale and click the >> button to move it to the Chosen qualifiers section.
  6. Select the languages you want to support and click OK.

This will create a new folder for each language you selected, with a file called strings.xml inside. This file will contain all of the localized strings for your app.

Step 2: Translate Your Strings

Once you've added support for multiple languages, you need to translate the strings in your app into each of the supported languages.

  1. Open your app's strings.xml file for the default language (usually values/strings.xml).
  2. Copy the contents of this file to the corresponding strings.xml files in the other language folders.
  3. Translate the strings in each file to the appropriate language.

For example, if you have a string called welcome_message in your default strings.xml file, you would copy this string to the strings.xml files in the other language folders, and translate it into the appropriate language.

1<resources>
2 <string name="welcome_message">Welcome to my app!</string>
3</resources>

Step 3: Load the Correct Strings at Runtime

Now that you've translated your strings, you need to make sure that the correct strings are loaded at runtime based on the user's language and culture.

  1. In your code, use the getString() method to retrieve each string from the strings.xml file.
  2. Android will automatically load the correct version of the string based on the user's language and culture.

For example, if you have a TextView in your layout with the ID welcome_message_textview, you can set its text like this:

1val welcomeMessageTextView = findViewById<TextView>(R.id.welcome_message_textview)
2val welcomeMessage = getString(R.string.welcome_message)
3welcomeMessageTextView.text = welcomeMessage

Conclusion

Localizing your Android app is an important step in making it accessible to users from different countries and regions. By following the steps outlined in this post, you can easily add support for multiple languages and cultures to your app, and provide a better user experience for your users.