A localizable resource is content, such as images and sound files, which is specific to a locale. In this recipe, we will learn how to load and display resources based on the user's localization preferences.
Create a new Single View Application in Xamarin Studio and name it LocalizableResourcesApp
. Add a label and a UIImageView
on the view of LocalizableResourcesAppViewController
. Two different images will also be needed, one for each locale. The images of USA and Spain are used in this example.
Perform the following steps:
Add two folders for the English and Spanish locales to the project (
en.lproj
andes.lproj
).Add one image in each folder. Make sure that the filename for the images is the same within both the folders.
Enter the following code in the
LocalizableResourcesAppViewController
class:public override void ViewWillAppear (bool animated) { base.ViewWillAppear (animated); this.lblLocale.Text = NSLocale.PreferredLanguages[0]; this...