Mobile software development is rarely limited to creating code in one language. In the modern world, a successful product must be understandable to the user, regardless of his geographic location. That is why the question of how to translate an Android application becomes a critical step before release on Google Play. Localization is not just a mechanical replacement of text, but an adaptation of the interface to the cultural and linguistic characteristics of the target audience.

Often, novice developers are faced with the fact that text strings are โ€œhardwiredโ€ directly into the code of an activity or fragment. This approach is gross architectural mistakewhich makes supporting the application almost impossible. If you want your creation to be seen by users from different countries, you must immediately lay down the correct resource structure. This will save you hours of manual work in the future and will allow you to automate the process of introducing new languages.

In this article we will analyze all aspects of localization: from organizing the file structure to the nuances of testing the finished translation. We'll look at the standard Android SDK tools as well as third-party string management solutions. You will learn how to avoid common mistakes related to text length and grammatical forms that can break the layout of your interface on devices with small screens.

Preparing the structure of resources and strings

The foundation of any localization in the ecosystem Android is a file strings.xml. By default, it is located in the folder res/values and contains all the text elements of the application in the main language (usually English). To add support for another language, you do not need to create new files manually - just create a special directory with a language qualifier.

For example, for the Russian language a folder is created res/values-ru, inside which there is a copy of the file strings.xml, but with translated tag values <string>. The Android system will automatically pull up the required file depending on the language settings on the user's device. This mechanism works at the operating system level and is the most effective way to manage content.

It is important to maintain strict identity of resource names (attribute name) in all language files. If in the main file the line has the name app_name, then in the file for the German language it must be called exactly the same, otherwise the application will crash when trying to access a non-existent resource. Use consistent naming systemfor example, prefixes btn_ for buttons or lbl_ for labels.

โš ๏ธ Attention: Never hardcode text directly into layouts (XML layout files) or Java/Kotlin code. Always use a link to the resource in the format @string/name_resource. Direct text input blocks the ability to translate and complicates project support.

๐Ÿ’ก

Use the Android Localizationer plugin for Android Studio. It allows you to view all rows in tabular form and quickly fill in the gaps for different languages, without opening each XML file separately.

Working with formatting and variables

When translating, there is often a need to insert dynamic data, such as the user name, the number of messages or the price of a product. Android uses format strings for this. You must leave special markers in the text, which the system will replace with real values โ€‹โ€‹during app execution. The syntax looks like %1$s for strings or %1$d for numbers.

However, the order of words in different languages โ€‹โ€‹can be radically different. In the English sentence "You have 5 messages" the number is in the middle, but in Russian "You have 5 messages" it is in a different place. If you simply translate the text without taking into account the position of the marker, the application will insert the data incorrectly. To solve this problem, Android provides positional arguments.

Welcome, %1$s! Your balance: %2$d rub.

Using numbering (%1$, %2$) allows the translator to change the order of variables in a sentence without breaking the logic of the code. This is a critical point for quality localization. Ignoring this rule will result in a number being displayed instead of the username in the interface, which will cause confusion among clients.

What is escaping special characters?

If the translation text contains an apostrophe (') or quotation marks, they must be escaped with a backslash (\') or placed in double quotes, otherwise the compiler will generate a project build error.

Plurals and grammatical forms

One of the most difficult tasks in localization is working with plurals. There are only two forms in English: singular and plural (one/other). In Russian there are three of them: singular, plural and a form for the number zero or ending in 1 (but not 11). In Arabic, the situation is even more complicated - there are six plural forms. Android provides a powerful resource mechanism that allows you to describe all the necessary grammatical forms. You create a separate resource in

Android provides a powerful resource mechanism <plurals>, which allows you to describe all the necessary grammatical forms. You create a separate resource in strings.xml, where you list options for zero, one, few, many, other. The system itself will select the desired form depending on the transmitted number.

  • ๐Ÿ”น one: Used for number 1 (for example, "1 file").
  • ๐Ÿ”น few: For numbers ending in 2, 3, 4 (except 12, 13, 14) - "2 files", "5 files".
  • ๐Ÿ”น many: For numbers ending with 0, 5-9, 11-14 - โ€œ0 filesโ€, โ€œ11 filesโ€.
  • ๐Ÿ”น other: Fallback form for other cases or languages โ€‹โ€‹with a simple structure.

Do not try to implement inflection logic programmatically through statements if/else in Activity code. This will make the code dirty and unportable. All logic must remain in resources. When calling such a resource from code, you use the getQuantityString()method, passing the number of elements there.

โš ๏ธ Attention: Grammar rules change. What works for Russian will not work for Polish or Czech. Always check the official Android documentation for region-specific plural qualifiers.

๐Ÿ“Š Which language is the most difficult to work with when localizing?
Arabic (right to left)
Chinese (characters)
German (long words)
Russian (cases)
Japanese

Adaptation of the interface to the length of the text

After translating the text, you may find an unpleasant surprise: the buttons have moved out, the text has been cut off with ellipses or overlapped with other elements. This happens because the length of the translated phrase may differ from the original by 30-50%. For example, German words are often significantly longer than English ones, while Chinese characters are often shorter.

To avoid layout breakdowns, use flexible layouts. Instead of a fixed width (android:layout_width="200dp"), use wrap_content or restrictions in ConstraintLayout. This will allow interface elements to stretch to fit the text. It is also useful to provide shortened versions of strings for small screens.

The table below shows examples of typical text expansion problems when translating from English:

Language Original (EN) Translation Coefficient growth
German Settings Einstellungen +60%
French Save Enregistrer +90%
Russian Delete Delete +20%
Spanish Continue Continuar +15%

For critical elements where space is limited (such as tabs in the bottom navigation bar), create separate string resources with the suffix _short. In your code or layout, you can switch between the full and short version depending on available screen space or pixel density.

๐Ÿ’ก

Always test your app on an emulator with the smallest screen resolution and longest language (such as German) to ensure the interface doesn't break.

Support for right-to-left (RTL) languages

Localization for Arabic, Hebrew or Urdu requires not only translation of the text, but also a mirror image of the entire interface. This is called support RTL (Right-to-Left). If you simply translate the lines, the application will look unnatural: the back buttons will point to the right, and the progress bars will fill in the wrong direction.

Starting with Android 4.2 (API level 17), the system supports automatic rotation of the interface. To activate this function, you need to add the attribute android:supportsRtl="true" to the file AndroidManifest.xml inside the tag <application>. After this, most standard widgets automatically adapt.

However, if you use a rigid binding to the cardinal directions (for example, layout_alignParentLeft), the interface will break. It is necessary to replace all attributes Left/Right with Start/End. For example, marginLeft turns into marginStart. This tells the system: โ€œstep back from the beginning of the container,โ€ where the beginning depends on the direction of the letter.

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="16dp"

android:text="@string/greeting" />

Checking the operation of the RTL mode is possible directly in the developer settings on a physical device or in the emulator. Forcefully enable the "Force RTL layout direction" mode to see how your application looks for a user from Saudi Arabia, even if your system language is Russian.

โš ๏ธ Attention: Icons with a semantic direction (arrows, transport icons) also need to be mirrored. The back arrow in the Arabic interface should point to the right. Graphic resources are placed in the folder drawable-ldrtl.

Automation tools and testing

Manually managing thousands of lines in XML files is a recipe for errors and chaos. For professional development, it is recommended to use specialized localization platforms, such as Crowdin, Phrase or Lokalise. They integrate with a code repository (Git) and allow translators to work in a convenient web interface without touching the code.

Such services automatically download new lines from the project and upload finished translations back in the form of a Pull Request. This speeds up the process significantly and allows the use of machine translation followed by human editing. In addition, they help find duplicate lines and control the length of text.

  • ๐Ÿš€ Fastlane: A tool for automating the assembly and uploading of screenshots for different locales in the Google Play Console.
  • ๐Ÿ” Lint: Built-in Android Studio analyzer that finds unloaded lines and formatting errors.
  • ๐ŸŒ Pseudo-locale: Special test language in Android, which replaces text with pseudo-Latin with accents, helping to find places where the text does not fit.

The final stage should always be real testing on devices. Emulators do not always correctly display fonts or keyboard behavior in specific languages. Ask native speakers to check the application, as they will notice semantic errors that the automatic translator missed.

โ˜‘๏ธ Checklist before releasing a localized version

Done: 0 / 5

Frequently asked questions (FAQ)

How to force change the language in the application without changing the system language?

Starting with Android 7.0 (Nougat), you can change the language within the application through the system settings. For older versions or custom implementation, you need to create your own class ContextWrapperthat will override the method attachBaseContext and install the necessary one Locale before loading resources.

Where to store translations if there are too many of them for strings.xml?

If the volume of text is huge (for example, a directory or news), storing everything in resources is ineffective - this will increase the size of the APK. In this case, the text is loaded dynamically from the server (JSON/API) or stored in a local database (Room/SQLite), and only static interface elements remain. strings.xml only static interface elements remain.

Why does the application crash after translation with the error ResourcesNotFoundException?

Most likely, you added a new language, but forgot to translate a specific string that is used in the code. If there is no resource in values-ru with the same name as in values, the system will not be able to find it. Check that the set of keys (name) is identical in all files.

How to translate the names of elements in the menu (Menu items)?

Menu items in a folder res/menu also use the attribute android:title. Just provide a link to the string resource there @string/menu_item_name, as for regular text views. A separate file for the menu is not required.

Do you need to translate the names of files or paths to pictures?

No, the names of files in the folder res/drawable or res/raw are not translated. If pictures contain text (for example, banners with inscriptions), create separate sets of images for different languages using folder qualifiers, for example drawable-ru for the Russian version of the picture.