Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Localization not working on iOS

$
0
0

I am using plugin.multilingual, and I have the translate extension in my shared project (.NET Standard)

It is working fine on Android, but on iPhone it only displays English, which is my default.

I have:
TranslateExtension.cs
AppResources.resx
AppResrouces.dk.resx

On Android, I change my phone's language to Danish, and the app shows danish text. But on iOS it doesn't. It continues to show English.

I have added english and danish to info.plist:

My translate extension:

`using System;
using System.ComponentModel;
using System.Reflection;
using System.Resources;
using Plugin.Multilingual;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace myApp.Helpers
{
[ContentProperty("Text")]
public class TranslateExtension : IMarkupExtension
{
const string ResourceId = "myApp.ResX.AppResources";

    static readonly Lazy<ResourceManager> resmgr = new Lazy<ResourceManager>(() => new ResourceManager(ResourceId, typeof(TranslateExtension).GetTypeInfo().Assembly));

    public string Text { get; set; }

    public object ProvideValue(IServiceProvider serviceProvider)
    {
        if (Text == null)
            return "";

        var ci = CrossMultilingual.Current.CurrentCultureInfo;

        var translation = resmgr.Value.GetString(Text, ci);

        if (translation == null)
        {

if DEBUG

            throw new ArgumentException(
                String.Format("Key '{0}' was not found in resources '{1}' for culture '{2}'.", Text, ResourceId, ci.Name),
                "Text");

else

            translation = Text; // returns the key, which GETS DISPLAYED TO THE USER

endif

        }
        return translation;
    }
}

}`


Viewing all articles
Browse latest Browse all 91519

Trending Articles