VISUAL STUDIO   Windows Mac

Part 5 - Application Localization and String Resources

PDF for offline use
Related Links:

Let us know how you feel about this

Translation Quality


0/250

last updated: 2017-03

Application localization is the act of providing alternate resources to target a specific region or locale. For example, you might provide localized language strings for various countries, or you might change colors or layout to match particular cultures. Android will load and use the resources appropriate for the device's locale at runtime time without any changes to the source code.

For example, the image below shows the same application running in three different device locales, but the text displayed in each button is specific to the locale that each device is set to:

Examples of three different locales

In this example, the contents of a layout file, Main.axml looks something like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<Button  
   android:id="@+id/myButton"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
android:text="@string/hello"
   />
</LinearLayout>

In the example above, the string for the button was loaded from the resources by providing the resource ID for the string:

Resource strings for three languages

Resource strings for three languages

Localizing Android Apps

Read the Introduction to Localization for tips and guidance on localizing mobile apps.

The Localizing Android Apps guide contains more specific examples on how to translate strings and localize images using Xamarin.Android.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.