Android/iOS app localization and internationalization is the process of adapting an application to meet the specific lingual or cultural requirements of a target market. A localized application automatically displays translated text based on the culture settings of the mobile device.
Xamarin Forms is one of the leading open-source, cross-platform app development frameworks from Microsoft for building iOS, Android, & Windows apps with .NET from a single shared codebase. However, Xamarin forms do not provide any abstract way to localize the application name.
To solve this problem, here is a step-by-step guide on how to localize the Android and iOS application names as per the device language.
In this demo, we will use Visual Studio 2022 for Windows to build a Xamarin forms application called Demo, which targets Android and iOS.
Let’s get started!
How to localize Android app
1. Go to Android Project. Here, we have to add language and region-specific value folders.
2. Add strings.xml file to value folders. This file will contain the string resources.
Add the resource tag in the XML file and then add the app_name key, which will contain the app name. Now, add the below code snippets:
The result will look like this:
Example: App name for en-rGB
3. Now update MainActivity.cs file. You will see the Activity tag at the class level in MainActivity.cs.
Since the Label tag is used to show the app name, update the label value with the newly added string key, i.e., app_name.
As seen above, referencing the app_name with @string annotation tells the OS that a value from the string file is being used. The OS will pick the value as per language and region.
4. Lastly, set the strings.xml file build action. Right-click on the strings.xml file and go to Properties. Under Properties, set the build action to AndroidResource.
5. Default language folder:
As shown in the above image, we have added a folder named ‘values’ with no language and region mentioned. This folder will act as a default. If the device language doesn’t fall into any defined criteria, it will be directed to the ‘values’ folder by default.
How to localize iOS apps
1. We will follow a similar method for iOS. Add language-specific folders within the Resource folder with an extension .Iproj.
2. Inside the .Iproj folders, add a file with the name InfoPlist.strings that will contain the localized value for the app name.
3. Define the CFBundleDisplayName Inside the InfoPlist.strings file. This key is used as the application display name in iOS. Add this to all languages supported.
Copy and paste the below code:
The result will look like this:
4. Inside the Info.plist file, add LSHasLocalizedDisplayName and set it to true.
In a different view setting, it may look like this –
5. Set up the build action for InfoPlist.strings file to BundleResource. Right-click on the InfoPlist.strings file and select properties. Under Properties, set the build action to BundleResource.
6. Lastly, point the app to consume the value provided in InfoPlist.strings files. To do so, mention the CFBundleDisplayName key and map it to $(PRODUCT_NAME).
In a different view setting, it may look like this –
Default Language Folder:
In the above image, you can observe that we have added a folder named Base.Iproj, which does not have any language and region mentioned. This folder will act as the default. If the device language doesn’t fall into any defined criteria, it will be directed to the Base.Iproj folder by default.
These are the steps for localization in Xamarin forms for the app name on iOS and Android.
Does your application deliver localized experiences? Nous Mobility Consultants enable you to integrate cross-platform localization into your mobile apps seamlessly and deliver fully localized experiences faster, enabling you to deliver cost-effective, secure, and customized enterprise mobility solutions across multiple demographics through our comprehensive app localization services.