Localization not working on iOS

SteveRussellSteveRussell Member ✭✭✭
edited May 2018 in Xamarin.Forms

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;
    }
}

}`

Answers

  • SteveRussellSteveRussell Member ✭✭✭

    Anyone?

  • SuatKorkmazSuatKorkmaz USMember ✭✭✭

    Did you get it working?

  • SteveRussellSteveRussell Member ✭✭✭
    Yes. Everything was fine, it was just that, annoyingly, the code for Danish on iOS is ‘da’ so I have to have 2 resources for Danish, AppResources.dk.resx (android) and AppResources.da.resx (ios)

    Not sure if you’re trying to get Danish specifically to work, but this worked for me
Sign In or Register to comment.