Especially beginners who have just started with Android development often ask themselves the following question: How can I easily publish Android apps in multiple languages? There are good reasons to do this. While many people in the world today speak English, sometimes you want to make your apps available in other languages as well. This process is also known as localization.
Let’s take myself as an example. Many of my apps are primarily of interest to an English-speaking audience. But I myself am from Germany, so of course I also speak German and can add this language. That’s why it makes sense for me to offer apps in (at least) two languages. Other developers also want to publish their Android apps in different languages like Spanish, French or Chinese.
Some beginners believe that they need to publish different apps in the Play Store for different languages. In other words, they want to develop several apps that actually all do the same thing, just in different languages. Although this would be possible, it is very time-consuming and troublesome.
There is a much easier way to create Android apps in multiple languages. In this article, I will show you how this localization of multilingual apps works.
The easy way to develop Android apps in multiple languages
To localize the app, we do not need to create multiple apps. This process works in Android Studio within an app and there within the xml files in the values folder.
Customize texts in Android via the strings.xml file
Texts and individual words that appear in the app are put in the file called strings.xml during Android development. The text can also be specified directly in the activity using android:text=”Hello World”. However, this is not recommended. If I do this, it is not directly an error, but a message appears in Android Studio that the strings.xml file is better suited for this.
The strings.xml file contains the texts in the default language of the app. This is usually English. However, if, for example, a developer only wants to offer an app in French, the texts are simply written to this file in French. A second folder for a second language is then not required. If an app is monolingual, the app is only displayed to the user in this language. So if the app is in French, but the user is Spanish-speaking, the app will only be displayed in French.
Second strings file for Android Apps in different languages
If I now want to add a second language for my app, I have to create a second strings.xml file. This is quite easy in Android Studio. The file can be found in the overview on the left-hand side (by default).
You can now right-click on the folder named values, select new and then Values Resource File (first entry).
Enter strings at the top under File Name. Under Available qualifiers, select Locale and click on the button with the two arrows pointing to the right (>>). A list with many different languages will now show up.
I have selected German for this example. You can select the language of your choice if you want to develop multilingual apps in Android. Two files called strings.xml are now displayed in Android Studio:
An entry in the strings file always begins with <string name=””> and ends with </string>. The name between the quotation marks serves as a placeholder and is not displayed in the app. It is important for the developer to be able to access the string within the layout files. Between the two tags is the text that will also appear in the app.
Each entry that is in the standard strings file must also be in each of the files for the other languages. It is best to simply copy the xml code from one file into the other and translate the words into the other language. In my case, the comparison of the two files looks like this:
I can now create a TextView in the layout file. I do not insert the text directly, but via the strings.xml file.
Language changes depending on the default language of the device
If this is my only layout, I already have an executable app. In the virtual device in Android Studio, I had set English as the default language, so the app looks like this at startup:
The user can now change the language in the smartphone settings. As a rule, the native language was set as the default language when the phone was first set up. For me, this would be German. If I now set the language to German in the settings and then return to the app, I see the following screen:
The app has therefore read the phone’s language from the settings and used this information to decide which of the two strings.xml files to read the string from.
If you now want to use more than two languages for your Android app, simply create an additional strings file for each language. This is by far the easiest way to develop Android apps in different languages.
Customize multilingual texts in Android via code (not recommended)
There is also the option of controlling the switch to a different language in Android via the code (Java or Kotlin). This is considered bad practice and is also more complex, especially if there is a lot of text and a lot of languages. Nevertheless, I would like to briefly explain how it works. Because sometimes the text may change while the app is running. It is then advisable to address and change it via the code.
The code for the app above would look like this, for example:
Of course, this is not a particularly long and complicated code. However, I would then have to perform such a query for each text. This makes the variant much more complex overall if I have a lot of text. The other variant using the strings file to develop multilingual Android apps is simpler.
Change images via drawable or mipmap folder for multilingual Android Apps
In addition to texts, you may also want to use different images in the app for different languages. This may sound strange at first, but there can be several reasons for this. Two of them are
- The user’s national flag should also be displayed in the app.
- There are images that contain text. In this case, the text should also be displayed in the user’s native language.
In principle, we proceed here in the same way as above with the strings. Instead of the strings.xml file, we create a second drawable folder (this also works with the mipmap folder). To do this, we can right-click on the res folder in Android Studio, then select new and then Android Resource Directory.
Under Resource type, I select drawable and then select the language in the same way as above for the strings.
The drawable folder is normally located under C:\Users\Computer_Name\AndroidStudioProjects\App_Name\app\src\main\res. You only need to replace Computer_Name and App_Name with the name of your computer and app. Alternatively, you can right-click on the Drawable folder in Android Studio and then select Open In > Explorer.
I now have two folders:
For our example, I will now place a USA flag in the normal drawable folder and a German flag in the drawable-de folder. It is important that both images have the same file name. I simply named them flag.jpg.
Now we proceed in the same way as with the strings, only with an ImageView instead of a TextView.
The original app now looks like this:
If I then change the language back to German in the smartphone settings and go back to the app, I get the following screen:
Settings for different countries instead of languages are also possible
So there is a very simple way to set images in different languages in the Android app. It is only time-consuming to assign different images to the individual folders if we have an app with many different languages.
You may have noticed that a US flag appears in the app above if English has been recognized as the language. However, there are of course many other countries that have English as their native language. For example, this applies to countries in the United Kingdom, Ireland, Canada or Australia. The same applies to Spanish, French or German, which are not only spoken in Spain, France or Germany.
If you go back to the screenshot for creating a second strings file, you will see that you can select more than just the language. You can also select different countries under Specific Region Only. In this way, for example, you could address differences between American English and British English in your Android App.
Localization is also possible in other files
Other files can also be localized in this way by entering several languages. I’ll take my NBA Quiz multilingual app as an example. There are questions in English and German. I have entered the questions and answers in a file called arrays.xml, which is also located in the values folder.
The following image shows a comparison of the English and German arrays.xml file for question 200.
These files are created in the same way as the strings files, i.e. with the Locale property.
Multiple Play Store entries for Android apps with different languages
You may now be wondering what the entry in the Google Play Store looks like if you have developed an Android app in multiple languages. In the Google Play Store, the developer can add a longer description or screenshots for different screen sizes in addition to the name of the app or the app icon.
There is also a standard entry in the Play Store. Like the apps, this entry is often in English. If, for example, a Spanish-speaking user views the app in the Play Store, the texts are automatically translated into Spanish. The developer does not have to do anything for this.
However, every user will also see the screenshots in this standard entry if this is the only entry available. If there are texts in the screenshots, the Spanish-speaking user will only see the English texts in this example.
However, the developer can change this by adding a separate Play Store entry for each language of the app. The text can then be translated there (if the automatic translation is not good enough) and other screenshots can be uploaded.
To do this, click Grow users > Store presence > Store listings in the menu on the left-hand side of the Google Play Console. Then click on the Create custom listing button at the top right. In the new window, you can then select Country/region or user state under Target audience.
Conclusion on the localization of Android apps
I hope it has become clear that creating Android apps in multiple languages is not particularly difficult. Using the strings file and possibly the drawable or mipmap folder is relatively simple and not very time-consuming. It only becomes more time-consuming if the app is to appear in many different languages. But it is still much easier than creating five different Android apps with five different languages.
0 Comments