If you want to connect with Android users across different countries and cultures, you’ll need to localize your app to support multiple languages. This process starts with Android internationalization (i18n), which lays the groundwork for seamless localization.
Internationalizing your Android app means designing it to accommodate multiple languages without engineering changes. This will make your app feel familiar to users from another region or culture, increasing usability and opening the door to new markets. The process only needs to be done once, saving you time and money on each subsequent localization.
This step-by-step guide will walk you through the process of internationalizing and localizing your Android app. You’ll learn how to prepare your app, handle dynamic content, and test across various languages and locales.
How to prepare for Android app localization
Internationalization prepares your Android app for localization. This process establishes a strong foundation within Android Studio to ensure your app supports multiple languages and regions. Here’s how to get started:
-
Install Android Studio
Start by downloading and installing Android Studio. Android Studio is the official development environment for Android, providing everything you need to internationalize, localize, and test your app.
-
Create a new Android project
Open Android Studio and create a new project. The “Empty Activity” template offers a simple starting point.
Then, configure your project settings like so:
- Name: Enter your app name (e.g., “LocalizedApp”).
- Package name: Use a unique identifier like “com.example.localizedappi18n.”
- Language: Select Kotlin (recommended) or Java.
- Minimum SDK: Set the lowest Android version your app will support.
Then, confirm your choices to generate the project structure.
-
Add UI elements with flexible layouts
When adding UI elements, design with localization in mind. Languages like German often require more space than English, whereas Chinese characters are more compact. Avoid setting fixed widths for text elements, as longer translations in some languages may exceed the container size.
Consider using tools like ConstraintLayout to allow UI elements to adjust position and size dynamically based on the length of the translated text.
Here’s an XML example:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome_message"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here, the TextView is used to display a string resource (e.g., a welcome message). By using wrap_content for the width, the element automatically resizes to fit the length of the translated text instead of being restricted by a fixed dimension. In addition, the ConstraintLayout keeps the TextView properly positioned within the screen, regardless of text length or screen size.
Creating a flexible layout from the start makes your app look great regardless of the language in which it’s localized.
-
Prepare for localization with externalized text
The final step to prepare your Android app for localization requires you to store all user-facing text in a separate resource file instead of hardcoding it. With a centralized resource file like strings.xml, you won’t need to manually replace text scattered across your code.
Here’s how to do it:
- Locate the “res/values/” folder in your project directory.
- Open the “strings.xml” file (if it doesn’t exist, create one).
- Add your text to the file using a name-value pair:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="welcome_message">Welcome to my app!</string>
</resources>
Go back to the activity_main.xml file and update the TextView to reference the string resource:
<TextView
android:text="@string/welcome_message"
Organizing your project this way will internationalize your Android app, allowing you to easily delineate the content that needs to be localized into a different language.
How to localize an Android app in 4 steps
Now that you’ve prepared your Android app, it’s time to go over the step-by-step localization process, from setting up language-specific resources to dynamically changing the Android app locale.
-
Expand strings.xml for localization
In the preparation stage, you created a strings.xml file to manage all the text in your Android app. Now, it’s time to expand this by creating language-specific versions of the file for each supported language.
First, create new folders for each target language in your project’s res directory. Use a folder name that includes the appropriate language code (e.g., “res/values-es/” for Spanish and “res/values-fr/” for French).
Copy your default strings.xml file into each folder. Then, manually translate the text for each language. For example, the default English file might say:
<TextView
<string name="hello_world">Hello, World!string>
The Spanish version in “values-es/strings.xml” would be:
<TextView
<string name="hello_world">¡Hola, Mundo!string>
Once you create these language-specific XML files, Android automatically chooses the correct version of strings.xml based on the user’s device language settings.
-
Handle plurals for accurate translations
Plurals are tricky because every language handles them differently. For example, “one item” is singular in English, but every other number is plural, whether “zero items” or “two hundred items.” However, languages like Russian, Welsh, and Czech use more specific rules for plurals based on the number.
Here’s how to define pluralized strings in strings.xml for English:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<plurals name="item_count">
<item quantity="one">%d item</item>
<item quantity="other">%d items</item>
</plurals>
</resources>
This accounts for the following quantity values:
- One: Used for singular forms (e.g., one item).
- Other: Used for plural forms (e.g., zero items, two items, three items).
English only requires “one” and “other,” but other languages have more classifications. To manage this, Android provides a tag in strings.xml. Android supports tags for zero, one, two, few, many, and other. Here are examples of languages that use each tag:
- Arabic employs a special grammatical agreement for zero.
- Russian treats any number ending in “1” differently unless it ends in “11.”
- Welsh uses a distinct pluralization when there are two of something.
- Languages like Czech and Maltese distinguish between small numbers and large ones.
- Chinese makes no distinctions.
Here’s how to retrieve and format the pluralized string in Kotlin:
val itemCount = 3
val message = resources.getQuantityString(R.plurals.item_count, itemCount, itemCount)
In this code, R.plurals.item_count is the plural resource ID. The first itemCount selects the plural string based on the plural rules of the device’s locale, and the second itemCount replaces the %d placeholder.
For example, here are the outputs for English:
- For itemCount = 1: “1 item”
- For itemCount = 3: “3 items”
-
Use placeholders for dynamic values
Apps often display personalized or dynamic content, like a user’s name or the number of notifications they have. Instead of hardcoding this content, you can use placeholders in your strings, like so:
<resources>
<string name="welcome_message">Welcome, %1$s! You have %2$d new messages.</string>
</resources>
工作原理如下:
- %1$s is a placeholder for a string (like a name).
- %2$d is a placeholder for a number (like the message count).
When the app runs, these placeholders are dynamically replaced with values input from the user and their dynamic data.
-
Add contextual hints
Translators don’t always know how a string is used in your app. For example, a word like “menu” could mean a dropdown list, a restaurant’s food list, or a settings page. To avoid confusion, you can add comments directly in your strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- This string is used as a label for the navigation menu →
<string name="menu_label">Menu</string>
<!-- This string is used for the settings button in the app →
<string name="settings_label">Settings</string>
</resources>
These notes tell the translator the word “menu” refers to a navigation feature in the app, not a restaurant menu.
Testing localization in Android
Testing your localized Android app is crucial to ensure it works across various languages and regions. By testing on emulators and real devices, you can catch issues and deliver an app that feels natural and functional for worldwide users.
Why test on real devices?
Real devices provide the closest simulation of how users will interact with your app. They show you how translated text looks on an actual phone screen—whether it’s too long or cut off.
Why test with emulators?
Emulators are a practical way to test your app across numerous configurations. They let you quickly switch between languages and regions to check translations, layout adjustments, and user interface behavior.
Combining both methods allows you to maintain optimal functionality and user experience across multiple languages and locales.
How to use Smartling for Android localization
Smartling takes the complexity out of Android localization. With AI-powered tools, seamless Android XML file integrations, and a team of expert translators, Smartling offers multiple services to streamline the entire translation process from start to finish and automate manual workflows.
Your business can leverage Smartling’s automation systems and data-driven insights to localize faster and maintain brand consistency across global markets, outpacing your competitors while providing an unparalleled user experience.
Ready to localize smarter, not harder? Download our free eBook, “10 Strategies to Boost Translation Efficiency.” You’ll learn how to improve translation speed, quality, and cost with actionable strategies and real-world examples.
If you want to connect with Android users across different countries and cultures, you’ll need to localize your app to support multiple languages. This process starts with Android internationalization (i18n), which lays the groundwork for seamless localization.
Internationalizing your Android app means designing it to accommodate multiple languages without engineering changes. This will make your app feel familiar to users from another region or culture, increasing usability and opening the door to new markets. The process only needs to be done once, saving you time and money on each subsequent localization.
This step-by-step guide will walk you through the process of internationalizing and localizing your Android app. You’ll learn how to prepare your app, handle dynamic content, and test across various languages and locales.
How to prepare for Android app localization
Internationalization prepares your Android app for localization. This process establishes a strong foundation within Android Studio to ensure your app supports multiple languages and regions. Here’s how to get started:
-
Install Android Studio
Start by downloading and installing Android Studio. Android Studio is the official development environment for Android, providing everything you need to internationalize, localize, and test your app.
-
Create a new Android project
Open Android Studio and create a new project. The “Empty Activity” template offers a simple starting point.
Then, configure your project settings like so:
- Name: Enter your app name (e.g., “LocalizedApp”).
- Package name: Use a unique identifier like “com.example.localizedappi18n.”
- Language: Select Kotlin (recommended) or Java.
- Minimum SDK: Set the lowest Android version your app will support.
Then, confirm your choices to generate the project structure.
-
Add UI elements with flexible layouts
When adding UI elements, design with localization in mind. Languages like German often require more space than English, whereas Chinese characters are more compact. Avoid setting fixed widths for text elements, as longer translations in some languages may exceed the container size.
Consider using tools like ConstraintLayout to allow UI elements to adjust position and size dynamically based on the length of the translated text.
Here’s an XML example:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome_message"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here, the TextView is used to display a string resource (e.g., a welcome message). By using wrap_content for the width, the element automatically resizes to fit the length of the translated text instead of being restricted by a fixed dimension. In addition, the ConstraintLayout keeps the TextView properly positioned within the screen, regardless of text length or screen size.
Creating a flexible layout from the start makes your app look great regardless of the language in which it’s localized.
-
Prepare for localization with externalized text
The final step to prepare your Android app for localization requires you to store all user-facing text in a separate resource file instead of hardcoding it. With a centralized resource file like strings.xml, you won’t need to manually replace text scattered across your code.
Here’s how to do it:
- Locate the “res/values/” folder in your project directory.
- Open the “strings.xml” file (if it doesn’t exist, create one).
- Add your text to the file using a name-value pair:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="welcome_message">Welcome to my app!</string>
</resources>
Go back to the activity_main.xml file and update the TextView to reference the string resource:
<TextView
android:text="@string/welcome_message"
Organizing your project this way will internationalize your Android app, allowing you to easily delineate the content that needs to be localized into a different language.
How to localize an Android app in 4 steps
Now that you’ve prepared your Android app, it’s time to go over the step-by-step localization process, from setting up language-specific resources to dynamically changing the Android app locale.
-
Expand strings.xml for localization
In the preparation stage, you created a strings.xml file to manage all the text in your Android app. Now, it’s time to expand this by creating language-specific versions of the file for each supported language.
First, create new folders for each target language in your project’s res directory. Use a folder name that includes the appropriate language code (e.g., “res/values-es/” for Spanish and “res/values-fr/” for French).
Copy your default strings.xml file into each folder. Then, manually translate the text for each language. For example, the default English file might say:
<TextView
<string name="hello_world">Hello, World!string>
The Spanish version in “values-es/strings.xml” would be:
<TextView
<string name="hello_world">¡Hola, Mundo!string>
Once you create these language-specific XML files, Android automatically chooses the correct version of strings.xml based on the user’s device language settings.
-
Handle plurals for accurate translations
Plurals are tricky because every language handles them differently. For example, “one item” is singular in English, but every other number is plural, whether “zero items” or “two hundred items.” However, languages like Russian, Welsh, and Czech use more specific rules for plurals based on the number.
Here’s how to define pluralized strings in strings.xml for English:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<plurals name="item_count">
<item quantity="one">%d item</item>
<item quantity="other">%d items</item>
</plurals>
</resources>
This accounts for the following quantity values:
- One: Used for singular forms (e.g., one item).
- Other: Used for plural forms (e.g., zero items, two items, three items).
English only requires “one” and “other,” but other languages have more classifications. To manage this, Android provides a tag in strings.xml. Android supports tags for zero, one, two, few, many, and other. Here are examples of languages that use each tag:
- Arabic employs a special grammatical agreement for zero.
- Russian treats any number ending in “1” differently unless it ends in “11.”
- Welsh uses a distinct pluralization when there are two of something.
- Languages like Czech and Maltese distinguish between small numbers and large ones.
- Chinese makes no distinctions.
Here’s how to retrieve and format the pluralized string in Kotlin:
val itemCount = 3
val message = resources.getQuantityString(R.plurals.item_count, itemCount, itemCount)
In this code, R.plurals.item_count is the plural resource ID. The first itemCount selects the plural string based on the plural rules of the device’s locale, and the second itemCount replaces the %d placeholder.
For example, here are the outputs for English:
- For itemCount = 1: “1 item”
- For itemCount = 3: “3 items”
-
Use placeholders for dynamic values
Apps often display personalized or dynamic content, like a user’s name or the number of notifications they have. Instead of hardcoding this content, you can use placeholders in your strings, like so:
<resources>
<string name="welcome_message">Welcome, %1$s! You have %2$d new messages.</string>
</resources>
工作原理如下:
- %1$s is a placeholder for a string (like a name).
- %2$d is a placeholder for a number (like the message count).
When the app runs, these placeholders are dynamically replaced with values input from the user and their dynamic data.
-
Add contextual hints
Translators don’t always know how a string is used in your app. For example, a word like “menu” could mean a dropdown list, a restaurant’s food list, or a settings page. To avoid confusion, you can add comments directly in your strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- This string is used as a label for the navigation menu →
<string name="menu_label">Menu</string>
<!-- This string is used for the settings button in the app →
<string name="settings_label">Settings</string>
</resources>
These notes tell the translator the word “menu” refers to a navigation feature in the app, not a restaurant menu.
Testing localization in Android
Testing your localized Android app is crucial to ensure it works across various languages and regions. By testing on emulators and real devices, you can catch issues and deliver an app that feels natural and functional for worldwide users.
Why test on real devices?
Real devices provide the closest simulation of how users will interact with your app. They show you how translated text looks on an actual phone screen—whether it’s too long or cut off.
Why test with emulators?
Emulators are a practical way to test your app across numerous configurations. They let you quickly switch between languages and regions to check translations, layout adjustments, and user interface behavior.
Combining both methods allows you to maintain optimal functionality and user experience across multiple languages and locales.
How to use Smartling for Android localization
Smartling takes the complexity out of Android localization. With AI-powered tools, seamless Android XML file integrations, and a team of expert translators, Smartling offers multiple services to streamline the entire translation process from start to finish and automate manual workflows.
Your business can leverage Smartling’s automation systems and data-driven insights to localize faster and maintain brand consistency across global markets, outpacing your competitors while providing an unparalleled user experience.
Ready to localize smarter, not harder? Download our free eBook, “10 Strategies to Boost Translation Efficiency.” You’ll learn how to improve translation speed, quality, and cost with actionable strategies and real-world examples.
If you want to connect with Android users across different countries and cultures, you’ll need to localize your app to support multiple languages. This process starts with Android internationalization (i18n), which lays the groundwork for seamless localization.
Internationalizing your Android app means designing it to accommodate multiple languages without engineering changes. This will make your app feel familiar to users from another region or culture, increasing usability and opening the door to new markets. The process only needs to be done once, saving you time and money on each subsequent localization.
This step-by-step guide will walk you through the process of internationalizing and localizing your Android app. You’ll learn how to prepare your app, handle dynamic content, and test across various languages and locales.
How to prepare for Android app localization
Internationalization prepares your Android app for localization. This process establishes a strong foundation within Android Studio to ensure your app supports multiple languages and regions. Here’s how to get started:
-
Install Android Studio
Start by downloading and installing Android Studio. Android Studio is the official development environment for Android, providing everything you need to internationalize, localize, and test your app.
-
Create a new Android project
Open Android Studio and create a new project. The “Empty Activity” template offers a simple starting point.
Then, configure your project settings like so:
- Name: Enter your app name (e.g., “LocalizedApp”).
- Package name: Use a unique identifier like “com.example.localizedappi18n.”
- Language: Select Kotlin (recommended) or Java.
- Minimum SDK: Set the lowest Android version your app will support.
Then, confirm your choices to generate the project structure.
-
Add UI elements with flexible layouts
When adding UI elements, design with localization in mind. Languages like German often require more space than English, whereas Chinese characters are more compact. Avoid setting fixed widths for text elements, as longer translations in some languages may exceed the container size.
Consider using tools like ConstraintLayout to allow UI elements to adjust position and size dynamically based on the length of the translated text.
Here’s an XML example:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome_message"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here, the TextView is used to display a string resource (e.g., a welcome message). By using wrap_content for the width, the element automatically resizes to fit the length of the translated text instead of being restricted by a fixed dimension. In addition, the ConstraintLayout keeps the TextView properly positioned within the screen, regardless of text length or screen size.
Creating a flexible layout from the start makes your app look great regardless of the language in which it’s localized.
-
Prepare for localization with externalized text
The final step to prepare your Android app for localization requires you to store all user-facing text in a separate resource file instead of hardcoding it. With a centralized resource file like strings.xml, you won’t need to manually replace text scattered across your code.
Here’s how to do it:
- Locate the “res/values/” folder in your project directory.
- Open the “strings.xml” file (if it doesn’t exist, create one).
- Add your text to the file using a name-value pair:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="welcome_message">Welcome to my app!</string>
</resources>
Go back to the activity_main.xml file and update the TextView to reference the string resource:
<TextView
android:text="@string/welcome_message"
Organizing your project this way will internationalize your Android app, allowing you to easily delineate the content that needs to be localized into a different language.
How to localize an Android app in 4 steps
Now that you’ve prepared your Android app, it’s time to go over the step-by-step localization process, from setting up language-specific resources to dynamically changing the Android app locale.
-
Expand strings.xml for localization
In the preparation stage, you created a strings.xml file to manage all the text in your Android app. Now, it’s time to expand this by creating language-specific versions of the file for each supported language.
First, create new folders for each target language in your project’s res directory. Use a folder name that includes the appropriate language code (e.g., “res/values-es/” for Spanish and “res/values-fr/” for French).
Copy your default strings.xml file into each folder. Then, manually translate the text for each language. For example, the default English file might say:
<TextView
<string name="hello_world">Hello, World!string>
The Spanish version in “values-es/strings.xml” would be:
<TextView
<string name="hello_world">¡Hola, Mundo!string>
Once you create these language-specific XML files, Android automatically chooses the correct version of strings.xml based on the user’s device language settings.
-
Handle plurals for accurate translations
Plurals are tricky because every language handles them differently. For example, “one item” is singular in English, but every other number is plural, whether “zero items” or “two hundred items.” However, languages like Russian, Welsh, and Czech use more specific rules for plurals based on the number.
Here’s how to define pluralized strings in strings.xml for English:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<plurals name="item_count">
<item quantity="one">%d item</item>
<item quantity="other">%d items</item>
</plurals>
</resources>
This accounts for the following quantity values:
- One: Used for singular forms (e.g., one item).
- Other: Used for plural forms (e.g., zero items, two items, three items).
English only requires “one” and “other,” but other languages have more classifications. To manage this, Android provides a tag in strings.xml. Android supports tags for zero, one, two, few, many, and other. Here are examples of languages that use each tag:
- Arabic employs a special grammatical agreement for zero.
- Russian treats any number ending in “1” differently unless it ends in “11.”
- Welsh uses a distinct pluralization when there are two of something.
- Languages like Czech and Maltese distinguish between small numbers and large ones.
- Chinese makes no distinctions.
Here’s how to retrieve and format the pluralized string in Kotlin:
val itemCount = 3
val message = resources.getQuantityString(R.plurals.item_count, itemCount, itemCount)
In this code, R.plurals.item_count is the plural resource ID. The first itemCount selects the plural string based on the plural rules of the device’s locale, and the second itemCount replaces the %d placeholder.
For example, here are the outputs for English:
- For itemCount = 1: “1 item”
- For itemCount = 3: “3 items”
-
Use placeholders for dynamic values
Apps often display personalized or dynamic content, like a user’s name or the number of notifications they have. Instead of hardcoding this content, you can use placeholders in your strings, like so:
<resources>
<string name="welcome_message">Welcome, %1$s! You have %2$d new messages.</string>
</resources>
工作原理如下:
- %1$s is a placeholder for a string (like a name).
- %2$d is a placeholder for a number (like the message count).
When the app runs, these placeholders are dynamically replaced with values input from the user and their dynamic data.
-
Add contextual hints
Translators don’t always know how a string is used in your app. For example, a word like “menu” could mean a dropdown list, a restaurant’s food list, or a settings page. To avoid confusion, you can add comments directly in your strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- This string is used as a label for the navigation menu →
<string name="menu_label">Menu</string>
<!-- This string is used for the settings button in the app →
<string name="settings_label">Settings</string>
</resources>
These notes tell the translator the word “menu” refers to a navigation feature in the app, not a restaurant menu.
Testing localization in Android
Testing your localized Android app is crucial to ensure it works across various languages and regions. By testing on emulators and real devices, you can catch issues and deliver an app that feels natural and functional for worldwide users.
Why test on real devices?
Real devices provide the closest simulation of how users will interact with your app. They show you how translated text looks on an actual phone screen—whether it’s too long or cut off.
Why test with emulators?
Emulators are a practical way to test your app across numerous configurations. They let you quickly switch between languages and regions to check translations, layout adjustments, and user interface behavior.
Combining both methods allows you to maintain optimal functionality and user experience across multiple languages and locales.
How to use Smartling for Android localization
Smartling takes the complexity out of Android localization. With AI-powered tools, seamless Android XML file integrations, and a team of expert translators, Smartling offers multiple services to streamline the entire translation process from start to finish and automate manual workflows.
Your business can leverage Smartling’s automation systems and data-driven insights to localize faster and maintain brand consistency across global markets, outpacing your competitors while providing an unparalleled user experience.
Ready to localize smarter, not harder? Download our free eBook, “10 Strategies to Boost Translation Efficiency.” You’ll learn how to improve translation speed, quality, and cost with actionable strategies and real-world examples.
If you want to connect with Android users across different countries and cultures, you’ll need to localize your app to support multiple languages. This process starts with Android internationalization (i18n), which lays the groundwork for seamless localization.
Internationalizing your Android app means designing it to accommodate multiple languages without engineering changes. This will make your app feel familiar to users from another region or culture, increasing usability and opening the door to new markets. The process only needs to be done once, saving you time and money on each subsequent localization.
This step-by-step guide will walk you through the process of internationalizing and localizing your Android app. You’ll learn how to prepare your app, handle dynamic content, and test across various languages and locales.
How to prepare for Android app localization
Internationalization prepares your Android app for localization. This process establishes a strong foundation within Android Studio to ensure your app supports multiple languages and regions. Here’s how to get started:
-
Install Android Studio
Start by downloading and installing Android Studio. Android Studio is the official development environment for Android, providing everything you need to internationalize, localize, and test your app.
-
Create a new Android project
Open Android Studio and create a new project. The “Empty Activity” template offers a simple starting point.
Then, configure your project settings like so:
- Name: Enter your app name (e.g., “LocalizedApp”).
- Package name: Use a unique identifier like “com.example.localizedappi18n.”
- Language: Select Kotlin (recommended) or Java.
- Minimum SDK: Set the lowest Android version your app will support.
Then, confirm your choices to generate the project structure.
-
Add UI elements with flexible layouts
When adding UI elements, design with localization in mind. Languages like German often require more space than English, whereas Chinese characters are more compact. Avoid setting fixed widths for text elements, as longer translations in some languages may exceed the container size.
Consider using tools like ConstraintLayout to allow UI elements to adjust position and size dynamically based on the length of the translated text.
Here’s an XML example:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome_message"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here, the TextView is used to display a string resource (e.g., a welcome message). By using wrap_content for the width, the element automatically resizes to fit the length of the translated text instead of being restricted by a fixed dimension. In addition, the ConstraintLayout keeps the TextView properly positioned within the screen, regardless of text length or screen size.
Creating a flexible layout from the start makes your app look great regardless of the language in which it’s localized.
-
Prepare for localization with externalized text
The final step to prepare your Android app for localization requires you to store all user-facing text in a separate resource file instead of hardcoding it. With a centralized resource file like strings.xml, you won’t need to manually replace text scattered across your code.
Here’s how to do it:
- Locate the “res/values/” folder in your project directory.
- Open the “strings.xml” file (if it doesn’t exist, create one).
- Add your text to the file using a name-value pair:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="welcome_message">Welcome to my app!</string>
</resources>
Go back to the activity_main.xml file and update the TextView to reference the string resource:
<TextView
android:text="@string/welcome_message"
Organizing your project this way will internationalize your Android app, allowing you to easily delineate the content that needs to be localized into a different language.
How to localize an Android app in 4 steps
Now that you’ve prepared your Android app, it’s time to go over the step-by-step localization process, from setting up language-specific resources to dynamically changing the Android app locale.
-
Expand strings.xml for localization
In the preparation stage, you created a strings.xml file to manage all the text in your Android app. Now, it’s time to expand this by creating language-specific versions of the file for each supported language.
First, create new folders for each target language in your project’s res directory. Use a folder name that includes the appropriate language code (e.g., “res/values-es/” for Spanish and “res/values-fr/” for French).
Copy your default strings.xml file into each folder. Then, manually translate the text for each language. For example, the default English file might say:
<TextView
<string name="hello_world">Hello, World!string>
The Spanish version in “values-es/strings.xml” would be:
<TextView
<string name="hello_world">¡Hola, Mundo!string>
Once you create these language-specific XML files, Android automatically chooses the correct version of strings.xml based on the user’s device language settings.
-
Handle plurals for accurate translations
Plurals are tricky because every language handles them differently. For example, “one item” is singular in English, but every other number is plural, whether “zero items” or “two hundred items.” However, languages like Russian, Welsh, and Czech use more specific rules for plurals based on the number.
Here’s how to define pluralized strings in strings.xml for English:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<plurals name="item_count">
<item quantity="one">%d item</item>
<item quantity="other">%d items</item>
</plurals>
</resources>
This accounts for the following quantity values:
- One: Used for singular forms (e.g., one item).
- Other: Used for plural forms (e.g., zero items, two items, three items).
English only requires “one” and “other,” but other languages have more classifications. To manage this, Android provides a tag in strings.xml. Android supports tags for zero, one, two, few, many, and other. Here are examples of languages that use each tag:
- Arabic employs a special grammatical agreement for zero.
- Russian treats any number ending in “1” differently unless it ends in “11.”
- Welsh uses a distinct pluralization when there are two of something.
- Languages like Czech and Maltese distinguish between small numbers and large ones.
- Chinese makes no distinctions.
Here’s how to retrieve and format the pluralized string in Kotlin:
val itemCount = 3
val message = resources.getQuantityString(R.plurals.item_count, itemCount, itemCount)
In this code, R.plurals.item_count is the plural resource ID. The first itemCount selects the plural string based on the plural rules of the device’s locale, and the second itemCount replaces the %d placeholder.
For example, here are the outputs for English:
- For itemCount = 1: “1 item”
- For itemCount = 3: “3 items”
-
Use placeholders for dynamic values
Apps often display personalized or dynamic content, like a user’s name or the number of notifications they have. Instead of hardcoding this content, you can use placeholders in your strings, like so:
<resources>
<string name="welcome_message">Welcome, %1$s! You have %2$d new messages.</string>
</resources>
工作原理如下:
- %1$s is a placeholder for a string (like a name).
- %2$d is a placeholder for a number (like the message count).
When the app runs, these placeholders are dynamically replaced with values input from the user and their dynamic data.
-
Add contextual hints
Translators don’t always know how a string is used in your app. For example, a word like “menu” could mean a dropdown list, a restaurant’s food list, or a settings page. To avoid confusion, you can add comments directly in your strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- This string is used as a label for the navigation menu →
<string name="menu_label">Menu</string>
<!-- This string is used for the settings button in the app →
<string name="settings_label">Settings</string>
</resources>
These notes tell the translator the word “menu” refers to a navigation feature in the app, not a restaurant menu.
Testing localization in Android
Testing your localized Android app is crucial to ensure it works across various languages and regions. By testing on emulators and real devices, you can catch issues and deliver an app that feels natural and functional for worldwide users.
Why test on real devices?
Real devices provide the closest simulation of how users will interact with your app. They show you how translated text looks on an actual phone screen—whether it’s too long or cut off.
Why test with emulators?
Emulators are a practical way to test your app across numerous configurations. They let you quickly switch between languages and regions to check translations, layout adjustments, and user interface behavior.
Combining both methods allows you to maintain optimal functionality and user experience across multiple languages and locales.
How to use Smartling for Android localization
Smartling takes the complexity out of Android localization. With AI-powered tools, seamless Android XML file integrations, and a team of expert translators, Smartling offers multiple services to streamline the entire translation process from start to finish and automate manual workflows.
Your business can leverage Smartling’s automation systems and data-driven insights to localize faster and maintain brand consistency across global markets, outpacing your competitors while providing an unparalleled user experience.
Ready to localize smarter, not harder? Download our free eBook, “10 Strategies to Boost Translation Efficiency.” You’ll learn how to improve translation speed, quality, and cost with actionable strategies and real-world examples.
If you want to connect with Android users across different countries and cultures, you’ll need to localize your app to support multiple languages. This process starts with Android internationalization (i18n), which lays the groundwork for seamless localization.
Internationalizing your Android app means designing it to accommodate multiple languages without engineering changes. This will make your app feel familiar to users from another region or culture, increasing usability and opening the door to new markets. The process only needs to be done once, saving you time and money on each subsequent localization.
This step-by-step guide will walk you through the process of internationalizing and localizing your Android app. You’ll learn how to prepare your app, handle dynamic content, and test across various languages and locales.
How to prepare for Android app localization
Internationalization prepares your Android app for localization. This process establishes a strong foundation within Android Studio to ensure your app supports multiple languages and regions. Here’s how to get started:
-
Install Android Studio
Start by downloading and installing Android Studio. Android Studio is the official development environment for Android, providing everything you need to internationalize, localize, and test your app.
-
Create a new Android project
Open Android Studio and create a new project. The “Empty Activity” template offers a simple starting point.
Then, configure your project settings like so:
- Name: Enter your app name (e.g., “LocalizedApp”).
- Package name: Use a unique identifier like “com.example.localizedappi18n.”
- Language: Select Kotlin (recommended) or Java.
- Minimum SDK: Set the lowest Android version your app will support.
Then, confirm your choices to generate the project structure.
-
Add UI elements with flexible layouts
When adding UI elements, design with localization in mind. Languages like German often require more space than English, whereas Chinese characters are more compact. Avoid setting fixed widths for text elements, as longer translations in some languages may exceed the container size.
Consider using tools like ConstraintLayout to allow UI elements to adjust position and size dynamically based on the length of the translated text.
Here’s an XML example:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome_message"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here, the TextView is used to display a string resource (e.g., a welcome message). By using wrap_content for the width, the element automatically resizes to fit the length of the translated text instead of being restricted by a fixed dimension. In addition, the ConstraintLayout keeps the TextView properly positioned within the screen, regardless of text length or screen size.
Creating a flexible layout from the start makes your app look great regardless of the language in which it’s localized.
-
Prepare for localization with externalized text
The final step to prepare your Android app for localization requires you to store all user-facing text in a separate resource file instead of hardcoding it. With a centralized resource file like strings.xml, you won’t need to manually replace text scattered across your code.
Here’s how to do it:
- Locate the “res/values/” folder in your project directory.
- Open the “strings.xml” file (if it doesn’t exist, create one).
- Add your text to the file using a name-value pair:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="welcome_message">Welcome to my app!</string>
</resources>
Go back to the activity_main.xml file and update the TextView to reference the string resource:
<TextView
android:text="@string/welcome_message"
Organizing your project this way will internationalize your Android app, allowing you to easily delineate the content that needs to be localized into a different language.
How to localize an Android app in 4 steps
Now that you’ve prepared your Android app, it’s time to go over the step-by-step localization process, from setting up language-specific resources to dynamically changing the Android app locale.
-
Expand strings.xml for localization
In the preparation stage, you created a strings.xml file to manage all the text in your Android app. Now, it’s time to expand this by creating language-specific versions of the file for each supported language.
First, create new folders for each target language in your project’s res directory. Use a folder name that includes the appropriate language code (e.g., “res/values-es/” for Spanish and “res/values-fr/” for French).
Copy your default strings.xml file into each folder. Then, manually translate the text for each language. For example, the default English file might say:
<TextView
<string name="hello_world">Hello, World!string>
The Spanish version in “values-es/strings.xml” would be:
<TextView
<string name="hello_world">¡Hola, Mundo!string>
Once you create these language-specific XML files, Android automatically chooses the correct version of strings.xml based on the user’s device language settings.
-
Handle plurals for accurate translations
Plurals are tricky because every language handles them differently. For example, “one item” is singular in English, but every other number is plural, whether “zero items” or “two hundred items.” However, languages like Russian, Welsh, and Czech use more specific rules for plurals based on the number.
Here’s how to define pluralized strings in strings.xml for English:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<plurals name="item_count">
<item quantity="one">%d item</item>
<item quantity="other">%d items</item>
</plurals>
</resources>
This accounts for the following quantity values:
- One: Used for singular forms (e.g., one item).
- Other: Used for plural forms (e.g., zero items, two items, three items).
English only requires “one” and “other,” but other languages have more classifications. To manage this, Android provides a tag in strings.xml. Android supports tags for zero, one, two, few, many, and other. Here are examples of languages that use each tag:
- Arabic employs a special grammatical agreement for zero.
- Russian treats any number ending in “1” differently unless it ends in “11.”
- Welsh uses a distinct pluralization when there are two of something.
- Languages like Czech and Maltese distinguish between small numbers and large ones.
- Chinese makes no distinctions.
Here’s how to retrieve and format the pluralized string in Kotlin:
val itemCount = 3
val message = resources.getQuantityString(R.plurals.item_count, itemCount, itemCount)
In this code, R.plurals.item_count is the plural resource ID. The first itemCount selects the plural string based on the plural rules of the device’s locale, and the second itemCount replaces the %d placeholder.
For example, here are the outputs for English:
- For itemCount = 1: “1 item”
- For itemCount = 3: “3 items”
-
Use placeholders for dynamic values
Apps often display personalized or dynamic content, like a user’s name or the number of notifications they have. Instead of hardcoding this content, you can use placeholders in your strings, like so:
<resources>
<string name="welcome_message">Welcome, %1$s! You have %2$d new messages.</string>
</resources>
工作原理如下:
- %1$s is a placeholder for a string (like a name).
- %2$d is a placeholder for a number (like the message count).
When the app runs, these placeholders are dynamically replaced with values input from the user and their dynamic data.
-
Add contextual hints
Translators don’t always know how a string is used in your app. For example, a word like “menu” could mean a dropdown list, a restaurant’s food list, or a settings page. To avoid confusion, you can add comments directly in your strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- This string is used as a label for the navigation menu →
<string name="menu_label">Menu</string>
<!-- This string is used for the settings button in the app →
<string name="settings_label">Settings</string>
</resources>
These notes tell the translator the word “menu” refers to a navigation feature in the app, not a restaurant menu.
Testing localization in Android
Testing your localized Android app is crucial to ensure it works across various languages and regions. By testing on emulators and real devices, you can catch issues and deliver an app that feels natural and functional for worldwide users.
Why test on real devices?
Real devices provide the closest simulation of how users will interact with your app. They show you how translated text looks on an actual phone screen—whether it’s too long or cut off.
Why test with emulators?
Emulators are a practical way to test your app across numerous configurations. They let you quickly switch between languages and regions to check translations, layout adjustments, and user interface behavior.
Combining both methods allows you to maintain optimal functionality and user experience across multiple languages and locales.
How to use Smartling for Android localization
Smartling takes the complexity out of Android localization. With AI-powered tools, seamless Android XML file integrations, and a team of expert translators, Smartling offers multiple services to streamline the entire translation process from start to finish and automate manual workflows.
Your business can leverage Smartling’s automation systems and data-driven insights to localize faster and maintain brand consistency across global markets, outpacing your competitors while providing an unparalleled user experience.
Ready to localize smarter, not harder? Download our free eBook, “10 Strategies to Boost Translation Efficiency.” You’ll learn how to improve translation speed, quality, and cost with actionable strategies and real-world examples.
Tags: Websites and Web Applications 博客