Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localization for mobile cross platform using xamarin and issue with iOS only

I have a project in Xamarin which targets Android, iOS and windows phone. I used core (PCL library) to share common code between different platform. I added Resource files (.net resource) .Resx in my core library and to read the culture specific string i used following code snippet in one of my ViewModel:

public string GetString() 
{  
    // CommonResources is the name of my resource file   
    ResourceManager resManager = new ResourceManager(typeof(CommonResources));   
    return resManager.GetString("LoginLabel",CultureInfo.CurrentCulture); 
}

"LoginLabel" is my resource key and its value is "Sign in" (in english) and "inloggen" in dutch.

I created two resource files CommonResources for English and dutch in my PCL project. CommonResources.resx
CommonResources.nl-NL.resx

in android, iOS and windows phone, I set culture as follow:

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("nl-NL");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("nl-NL");

This works fine for Android and windows phone.

But for iOS it does not work. It always return resource string from English file. The culture is properly set and it display in debug mode. but somehow it is not able to load the resource string from the dutch resource.

So the question is, it is possible to localize string(.Net way) using PCL for all platform? anyone has any idea? Thanks in advance.

like image 360
SoftSan Avatar asked Apr 11 '14 05:04

SoftSan


People also ask

How do you develop cross-platform mobile app using Xamarin?

From the installed template > select Visual C# > Cross-Platform > Cross-Platform-App (Xamarin. Forms or Native). Then provide the name of the project (FirstNativeApp) and save location for the project and OK. Next screen shows different UI technologies available while creating a cross-platform app like Xamarin.

Can Xamarin be used for iOS?

Xamarin. Forms is an open source mobile UI framework from Microsoft for building iOS, Android, & Windows apps with . NET from a single shared codebase.

What are the reason to use Xamarin for cross-platform development?

Xamarin provides full access to native APIs and tools used across Android, iOS, and Windows platforms. Hence, it can provide nearly native design and performance for every application. This is a good reason to prefer Xamarin-based solutions to its hybrid competitors.


1 Answers

For localization on our Xamarin projects I've used the Multilingual App Toolkit (detailed here) from Microsoft and T4 templates to transform the output from the toolkit to useable formats for Android and iOS.

This tutorial has a fantastic overview of the process and it's based on this code project.

like image 89
Trent Scheffert Avatar answered Oct 12 '22 10:10

Trent Scheffert