I am developing a Xamarin.Forms app (portable class library project) with Visual Studio 2013 CE. First I'm focusing the iOS version.
Now I'm thinking about how to make the app multilingual.
I just read the offical Xamarin documentation about it but i realized that this solution only takes the system language of the target device.
In the portable class library I have a Resources folder with three languages: German (default), English and French.
Resource.resx
Resource.en-US.resx
Resource.fr-FR.resx
Resource.Designer.cs
public static class Settings
{
public static Dictionary<String, CultureInfo> Languages = new Dictionary<String, CultureInfo> { { "German", new CultureInfo("de-DE") }, { "English", new CultureInfo("en-US") }, { "French", new CultureInfo("fr-FR") } };
public static CultureInfo CurrentCulture = Languages["German"];
public static CultureInfo CurrentUiCulture = Languages["German"];
public static void ChangeCurrentCultureInfo(CultureInfo cultureInfo)
{
Resource.Culture = cultureInfo;
}
}
Settings.CurrentCulture = Settings.Languages["English"];
Settings.ChangeCurrentCultureInfo(Settings.CurrentCulture);
Finally i got an answer of the Xamarin support.
The solution i was thinking about works. In the PCL i just have the static Settings class
which stores the different CultureInfo
objects. In addition I defined a method for changing the current culture and the language of the resources file.
public static void ChangeCurrentCultureInfo(CultureInfo cultureInfo)
{
CurrentCulture = cultureInfo;
Resource.Culture = CurrentCulture;
}
It was important to set the default language in the App()
constructor before I initialize the main page. Now i got a listview with all supported languages with one tapped event which calls the ChangeCurrentCultureInfo
method.
Nevertheless i want to thank Andy Hopper for providing his solution!
Regards