Android runs on many devices in many regions. To reach the most users, your application should handle text, audio files, numbers, currency, and graphics in ways appropriate to the locales where your application will be used.
Localization is more than just the translation of the strings in your application in other languages. It also involves displaying data, such as dates and times, in the right format for your users. Even if you only want an English version of your application it’s good to know what localization involves.
To localize an application for a language or for a specific country and language, you need to include the resources for that locale in the /res folder of your application. This usually includes string resources in the /res/values folder, but it can also include other types of resources, such as images and layouts.
The Android SDK identifies the various alternative resources with configuration qualifiers, which are then used to name the folder containing those resources. The configuration qualifier for the locale is the language code, optionally followed by the country code. So, the localized string resources for your application must be in the /res/values-<language code> or /res/values-<language code>-r<country code> folder.
Android loads text and media resources from the project’s “res” directory. Android can select and load resources from different directories, based on the current device configuration and locale.
For example, if the code loads a string called “R.string.apptitle”, Android will choose the correct value for that string at runtime by loading the appropriate strings.xml file from a matching “res/values” directory.
In order to have a multilingual Android app you need to provide Android with the localized resource files.
If the locale is “en”, Android will look for a value of “R.string.title” by searching the files in the following order:
When it manages to find the string in the resource file, it uses that value and stops searching. This means that the default language acts as a fall-back option and when translation exists, it’s used instead. It also means that you should either localize everything or nothing, as seeing half translated applications is usually worse than apps that are not translated at all.
While you are supporting multiple languages, you should consider below as a best practice while defining the strings. Always declare the string in strings.xml only.
<string name="note_name">Enter your Name</string>
When referring it in xml, use @strings notation.
<TextView ... android:text="@string/note_name" />
When defining the string through java code, use R.string
Be the first to comment.