Developing a mobile application is only half the success, because high-quality localization is critical to enter the global market. Many novice developers postpone this stage until later, which leads to chaos in the code and difficulties with version support. Correctly setting up language resources from the very beginning of the project saves hours of work in the future and makes the application accessible to a Russian-speaking audience.

In the operating system Android the localization process is built on a system of resource files, which allows you to separate content and app code. You don't need to rewrite your application logic for each language, just create the appropriate XML files with string translations. This is a flexible system that automatically substitutes the required text depending on the language settings on the user's device.

In this article we will analyze in detail the process of adding Russian localization, from creating files to checking the result in the emulator. You'll learn about standard folder structures, coding quirks, and techniques to make a developer's life easier. Readiness for multilingualism is a sign of professionalism, and you should start this path right now.

Preparing the project resource structure

Before entering the first lines of translation, you need to make sure that the structure of your project meets the standards. Localization is based on a folder Android Studio meets standards. Localization is based on folder res, inside which all application resources are stored. This is where specialized directories are created for different languages โ€‹โ€‹and regions, which allows the system to dynamically select the desired content.

The main file with which you have to work is strings.xml. By default, it is located in the folder values and contains strings of the main language (usually English). To add the Russian language, you will need to create a new resource folder with a language qualifier. In the case of the Russian language, the code is used ru, so the new folder will be called values-ru.

โš ๏ธ Attention: Never create files manually outside the project structure or in the wrong folders. The Gradle build system may ignore resources if they are not in strictly designated places, which will lead to compilation errors or lack of translation on the device.

Creating a new language folder can be done in two ways: through the GUI or manually in the project structure. The first option is preferable for beginners, since the IDE itself will check the syntax and correctness of the naming convention. The second option is faster for experienced users who know exactly where to put the files.

๐Ÿ’ก

Use the same identifier names (keys) in all language files. This will simplify the search for missing translations and prevent the application from crashing when trying to display a non-existent string.

Creating a localization file for the Russian language

The most reliable way to add a new language is to use the built-in tools Android Studio. This ensures that all metadata will be entered correctly. Open the Project tab in the left pane and switch the view to Androidto see the logical structure, not just the files on the disk.

Find the folder res, right-click on it and select the path New โ†’ Android Resource Directory. A dialog box will open where the value Resource type . You need to go to the list valueshas already been selected in the field Available qualifiers, find there Locale and click the add button with the right arrow.

After adding the Locale qualifier, select the language in the fields that appear. For the Russian language in the list Language you need to find and select Russian or enter the code ru. The region (Region) can be left empty if you do not need specific localization for different countries (for example, the Russian language in Belarus or Ukraine may have its own characteristics, but the base code ru is universal).

  • ๐Ÿ“‚ Right-click on the folder res in the project.
  • ๐Ÿ“‚ Select menu New and then Android Resource Directory.
  • ๐Ÿ“‚ In the list of qualifiers, find and add Locale.
  • ๐Ÿ“‚ In the Language field, select ru or Russian and click OK.

After confirming the actions, a new folder will appear in the project values-ru. A file strings.xmlwill be automatically created inside it, which for now will contain only the basic XML structure. It is in this file that you will make translations, copying the structure from the main file.

โ˜‘๏ธ Checking the localization structure

Done: 0 / 4

Translating strings and working with XML

Now that the file has been created, you need to fill it with content. Open the main file strings.xml (from the values โ€‹โ€‹folder) and the file strings.xml from the folder values-ru side by side using the Split view function. Your task is to copy tags <string> from the original into a Russian file and replace the content between tags with the translation.

This is a unique identifier by which the application accesses the string. If you change the key name, the application will not be able to find the resource and will either show empty, or (in debug mode) will throw a missing resource error.

<resources>

My Application

Welcome!

Login

</resources>

When translating text, consider the context of use. Short words like "OK" or "Cancel" may require different translations depending on the situation, but basic resources usually use a universal version. Also watch the length of the lines: in Russian, words are often longer than their English counterparts, which can break the layout of buttons or text fields.

โš ๏ธ Attention: Android Studio interfaces and versions of support libraries may change. If you don't find the menu item, check the official Google documentation or use the action search (Ctrl+Shift+A), as the layout of elements is often updated in new versions of the IDE.

Pay special attention to special characters. If the translation text uses quotes (' or "), they must be escaped with a backslash (for example, \' ), otherwise the XML parser will generate a syntax error. The same goes for characters like < and >, which in XML are replaced by &lt; and &gt;.

How to handle pluralization?

The Russian language has a complex system of endings (1 file, 2 files, 5 files). For such cases, use the tag instead of , indicating options for one, few and many.

Using parameters and formatting

Often there is dynamic data in the text: username, number of messages or price. In such cases, placeholders are used in the strings, for example, %s for strings or %d for numbers. When translating, it is important to preserve the order and type of these parameters, even if grammatically in Russian they need to be rearranged.

If the order of words changes, you can use numbered arguments. For example, the original Hello %1$s, you have %2$d messages can be translated as Hello, %1$s! You have %2$d new messages. This allows you to flexibly change the structure of the sentence without breaking the logic of data substitution.

To format dates, times and numbers, it is better not to write hard strings, but to use standard Java/Kotlin methods or formatting libraries provided by the platform. However, if you need to add text explanation around a number, make sure that the word inflections match the numeral.

  • ๐Ÿ”ข Use %d for whole numbers (number, age).
  • ๐Ÿ”ข Use %s to substitute text (names, names).
  • ๐Ÿ”ข Use %f for floating point numbers (currency rates, weight).
  • ๐Ÿ”ข Escape the percentage if it is needed as a symbol: %%.

Checking the correctness of format strings in Android Studio enabled by default. If you forget an argument or get the type wrong, the IDE will highlight the error in red. These warnings cannot be ignored, as the application will crash with an error IllegalFormatException at the time of execution.

๐Ÿ’ก

Preserving the types and order of formatting arguments is critical for the stable operation of the application. An error in the qualifier will cause the application to crash on the user's screen.

Table of main localization qualifiers

In addition to the language, it is often necessary to take into account the region or other features. Below is a table with the main codes that may be needed when expanding localization beyond the simple Russian language.

Qualifier Description Example value Example folder
Language Language code (ISO 639-1) ru, en, de values-ru
Region Country code (ISO 3166-1) RU, US, BY values-ru-rRU
Script Writing script Cyrl, Latn values-ru-Cyrl
Night Night mode night values-night

The use of regional qualifiers (for example, values-ru-rBY for Belarus) allows you to clarify the translation if in the country Specific terms or formats are adopted. However, for most applications, a general language code is sufficient ru, which will cover all Russian-speaking regions.

The Android resource system has priorities. If there is no file for a specific region, the system will automatically fall back to a more general language file. Therefore, creating a basic values-ru is a mandatory foundation on which specific regional settings can already be built up.

๐Ÿ“Š Which localization method do you use more often?
Manual creation of XML
Android Localizationer plugin
Google Play Console
Third-party services (Crowdin)

Testing and debugging translation

After all the strings have been translated, you need to check the result. The easiest way is to run the application on an emulator or a real device where the system language is set to Russian. If the device has an English interface, the application will also remain in English, even if a Russian file is created.

To force verification, you can change the language in the settings of the emulator or phone itself. Go to Settings โ†’ System โ†’ Languages & input and add Russian, making it the main language. Restart the application and you should see the updated interface.

There is also a tool Android Studio there is also a tool App Links Assistant and a preview in the XML editor that allows you to switch languages โ€‹โ€‹directly in the Design view. In the bottom panel of the layout editor there is a globe button that allows you to select a language for the preview, which is very convenient for quick visual checking.

โš ๏ธ Attention: Do not forget to check the text on low-resolution screens. Russian text can be 30-40% longer than English, which will lead to words being cut off (ellipsis) or elements overlapping each other.

Pay attention to working with HTML tags inside lines. In XML resources, you can use a limited subset of HTML (for example, <b>, <i>, <u>) to highlight parts of text. This works in components TextViewbut requires proper escaping or using an annotation @string/.. with method Html.fromHtml in code.

Frequently asked questions (FAQ)

Why the application does not switch to Russian language?

Check three things: 1) The device language is really set to Russian. 2) The file is located in the folder, and not just in the folder. 3) The names of the keys (name="..") in the Russian file exactly match the original, including the case of letters. strings.xml is in the folder values-ru, not just values. 3) The names of the keys (name="..") in the Russian file exactly match the original, including the case of letters.

Is it possible to change the language within the application without changing the system language?

Yes, this is possible, but it requires additional code. You will need to create a context with the desired locale and update the Activity resources. The standard Android mechanism is tied to system settings, so to change on the fly you will have to write a custom Wrapper for Context or use libraries like AppLocale.

What to do if there is no translation for some string?

If the file values-ru is missing a key that is in the main file, Android will automatically take a string from the default language (usually English). The application will not crash, but the user will see a mixture of languages. To prevent this, you can enable the lint check MissingTranslation in the project settings.

How to escape special characters in translation?

Use a backslash before characters that have meaning in XML. For example: \' for an apostrophe, \" for a quotation mark, \\ for the slash itself. For symbols < and > use HTML- &lt; and &gt; or CDATA sections.