1

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

1
  • I think you could share a demo ,which can reproduce this issue. Commented Aug 21, 2017 at 8:05

1 Answer 1

1

Your resource should be set with Embedded.

Change the option in this following image.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.