Android Localization: How to Translate a Strings XML File with PTC

Making an Android app multilingual involves translating the strings.xml file, which stores all the translatable text in your app. With PTC (Private Translation Cloud), you can translate your Android app into multiple languages at once.

Translating the strings.xml file allows you to offer a more personalized experience to users across different regions. This makes it easier for people worldwide to interact with it, ultimately widening your app’s market potential.

PTC (Private Translation Cloud) uses AI and custom technology to understand your project’s context, delivering Better Than Human Translation. PTC also integrates with Git to automatically translate new text when you update your strings.xml file, keeping everything up-to-date without extra effort.

Why the strings.xml File Matters for Android Localization

The strings.xml file is key to making your Android app multilingual. Instead of hardcoding text throughout the app, you store all UI-related text in this resource file. This includes:

App Titles and Button Labels

Text like “Log In,” “Submit,” or “Settings”

Messages and Instructions

Instructions such as “Welcome”, “Enter your email”, or “Join”

Error Messages

Alerts or notifications like “Invalid password”

Other UI Text

Anything the user sees on the screen that isn’t an image or icon

Here’s a basic example of what the strings.xml file looks like:

xml
<resources>
    <string name="app_name">My App</string>
    <string name="welcome_message">Welcome to My App!</string>
    <string name="login_button">Log In</string>
    <string name="signup_button">Sign Up</string>
    <string name="error_invalid_password">Invalid password</string>
</resources>

As you can see, you need to store each piece of text as a key-value pair. The key identifies the text in the app, while the value contains the actual words that users see. For example:

  • Key: login_button — How the app knows what text to display when referencing a button
  • Value: "Log In" — The actual text users see on the button

When it’s time to translate, keys (like login_button) will stay the same across all languages. Only the values (the text users see) get translated.

How to Prepare the strings.xml File for Translation

Below, we’ll focus specifically on localization from the perspective of the strings.xml resource file. You’ll learn how to prepare your strings.xml file so it’s ready for translation using PTC. 

1. Add All User-Facing Text to the strings.xml File

Instead of hardcoding text directly into layout files, store all translatable text in strings.xml and reference it from there. Here’s an example:

  1. You have a button in your app that says “Log In”. Instead of writing the text directly in the layout, you store the text in strings.xml like this:
xml
<resources>
    <string name="login_button">Log In</string>
</resources>
  1. Then, you reference the text from strings.xml in your layout file. This makes the app easier to translate into multiple languages and lets Android automatically select the correct language version of the text based on the user’s device language settings:
xml
<Button
    android:id="@+id/loginButton"
    android:text="@string/login_button" />

2. Use Placeholders for Dynamic Content

Sometimes, your app might include dynamic content—values that change depending on user input or other factors. For example, a welcome message that includes the user’s name, like “Welcome, Sarah!

In such cases, you use placeholders to mark where the dynamic content will go. In strings.xml, placeholders are represented by special symbols like %s for strings and %d for numbers. The app replaces these placeholders with actual values when it runs.

Here’s an example of a welcome message that includes a placeholder for the user’s name:

xml
<resources>
    <string name="welcome_message">Welcome, %s!</string>
</resources>

In the app’s code, Android will replace the placeholder %s with the user’s actual name when displaying the message:

String userName = "Sarah";
String welcome = getString(R.string.welcome_message, userName);

It’s important that you keep placeholders consistent across your strings.xml file. Both translators and translation tools work better when you use the same format for placeholders in every string, whether it’s %s for a string or %d for a number.

3. Create Separate Folders for Each Language

After preparing your strings.xml file, set up separate folders in the res/ directory for each language you want to support. Android uses these folders to load the correct translations automatically.

The naming follows a standard practice where you add a language code (like -es for Spanish or -fr for French) to the values directory.

For example:

res/values/strings.xml – The default file for English (or whichever language you’re using as the source language)

res/values-es/strings.xml – The strings.xml file for Spanish

res/values-fr/strings.xml – The strings.xml file for French

Once you have your translations, you’ll place each translated strings.xml file into the appropriate folder.

4. Verify Encoding for Special Characters

After setting up the folders for each language, verify that your strings.xml file uses UTF-8 encoding to support special characters, accents, and non-Latin alphabets. Most modern development tools, like Android Studio, save files in UTF-8 by default, but it’s always a good idea to double-check:

  1. Open your strings.xml file in Android Studio or your preferred text editor.
  2. Check the file’s encoding settings to make sure it’s set to UTF-8.
  3. If needed, update the encoding to UTF-8 and save the file again.

Once you do this, you’ll have everything you need to start translating the strings.xml file with PTC.

How to Translate Your strings.xml File with PTC

With your strings.xml file ready, you can use PTC’s Free resource files translation tool to quickly and easily translate your Android app’s text. This software translation tool uses AI-powered automatic translation to translate your resource files into an unlimited number of languages.

Simply upload your source strings.xml file, select the languages for translation, and download each translated file, ready for integration into your project.

XML File in the Source Language ( English)

Translated XML File ( Spanish)

Then, just add the translated strings.xml files to the appropriate language-specific folders (e.g., res/values-es/ for Spanish, res/values-fr/ for French).

Integrating PTC into Your Git Flow for Continuous Android App Localization

PTC’s Free Resource Files Translation does a great job, a PTC subscription offers superior translation accuracy with AI that understands context. Plus, Git integration keeps your translations updated automatically as your code changes.

Here’s how the PTC integration works:

Connect to Your Git Repository

Connect PTC with your Git repository (GitHub, GitLab, or BitBucket) to automate the translation process. PTC monitors your project and detects the strings.xml files that need translation.

Set Up Your Project

PTC will ask you to tell it more about your app. It then uses the knowledge it gains about your app’s context to provide precise and Better Than Human Translation.

Enjoy Hands-Free Localization

Each time you update your strings.xml file, PTC detects changes and translates new or modified text. You can select which branches to keep updated for continuous localization.

Create a Glossary to Perfect Your Translations

Set up a custom glossary to handle specific terminology or exclude text that shouldn’t be translated. PTC will apply the glossary across all future translations and update existing translations as needed.

Take Android Localization Further with PTC

In this tutorial, you learned how to prepare your Android app for localization. Here’s a quick recap of the key steps:

  • Move all user-facing text into the strings.xml file
  • Check and keep placeholders consistent for dynamic content
  • Create separate folders for each language
  • Verify UTF-8 encoding to ensure special characters display correctly

By following these steps, you make it easy for PTC’s Free resource files translation tool to quickly and accurately translate your strings.xml file.

To take your localization even further, you can upgrade to a paid PTC subscription (coming soon!). This gives you added benefits like Git integration for automatic updates and continuous localization, ensuring your app always stays up-to-date in every supported language.

Supported Resource File Formats
Scroll to Top