I am trying to implement I18N / Localization for Xamarin.Forms as described here: https://developer.xamarin.com/guides/xamarin-forms/advanced/localization/ - however even though I set the language on my device to french and have a Resx File for french, there's always the default translation returned. I already tried deactivating fast deployment (as recommended on the forementioned website), but no success so far.
In this line:
var translation = ResMgr.Value.GetString(Text, ci);
the value ci is fr-CH, the returned string however is the default language and not French
// You exclude the 'Extension' suffix when using in Xaml markup
[ContentProperty("Text")]
public class TranslateExtension : IMarkupExtension
{
readonly CultureInfo ci;
const string ResourceId = "ResxI18N.Resx.Resources";
private static readonly Lazy<ResourceManager> ResMgr = new Lazy<ResourceManager>(() => new ResourceManager(ResourceId
, typeof(TranslateExtension).GetTypeInfo().Assembly));
public TranslateExtension()
{
if (Device.OS == TargetPlatform.iOS || Device.OS == TargetPlatform.Android)
{
ci = DependencyService.Get<ILocalize>().GetCurrentCultureInfo();
}
}
public string Text { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Text == null)
return "";
var translation = ResMgr.Value.GetString(Text, ci);
if (translation == null)
{
}
return translation;
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:i18n="clr-namespace:ResxI18N.Helpers;assembly=ResxI18N"
xmlns:local="clr-namespace:ResxI18N" x:Class="ResxI18N.ResxI18NPage">
<Label Text="{i18n:Translate Welcome}" VerticalOptions="Center" HorizontalOptions="Center" />
The full example can be found here: https://github.com/hot33331/ResxI18N
