Forum Xamarin.iOS

internationalization xamarin mac appllication

NinineaNininea USUniversity ✭✭✭

It there anyone who implemented internationalization and localization in xamarin.mac application...

I have so many problems to do this , posted several question in stackoverflow :
http://stackoverflow.com/questions/40181574/xamarin-mac-resources-localization-doesnt-change-by-current-culture/40181988#40181988
http://stackoverflow.com/questions/40176503/xamarin-mac-multi-language-support

Generally, I followed some tutorials for cocoa mac , but it seems that doesn't work in xamarin , for example, I implemented following example :

but no result .

Posts

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    You might be running into this bug:

    https://bugzilla.xamarin.com/show_bug.cgi?id=45696

    Where if you use resx localization, we are not copying in the generated localized resources into the bundle.

    Which you can work around with:

    https://developer.xamarin.com/samples/mac/UseMSBuildToCopyFilesToBundleExample/

    If you aren't using resx files, could you attach a small example showing what you are doing.

  • The xamarin mac docs do not have much on this subject BUT is works mostly the same as Xamarin.IOS localization:
    https://developer.xamarin.com/guides/ios/advanced_topics/localization_and_internationalization/

    I use only Localizable.strings files and assign everything in code.

    Also I have my own utility function for translations that falls back to english if a string is not translated in the current language:

        static NSBundle LocStrFallbackBundle;
            public static string LocStr(string key, string comment = "")
            {
                string result = NSBundle.MainBundle.LocalizedString (key, "#NOTFOUND#", null);
                if (result == null || result == "#NOTFOUND#")
                {
                    if (LocStrFallbackBundle == null)
                        LocStrFallbackBundle = NSBundle.FromPath (NSBundle.MainBundle.PathForResource ("en", "lproj"));
    
                    result = LocStrFallbackBundle.LocalizedString (key, null, null);
                }
    
                if (result == null)
                    result = key;
                return result;
            }
    
  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Yep, it's almost the same as XI. Almost all of the docs apply.

    The only issue they might be hitting is the secondary assemblies not being copied into the app bundle (XI does not have that bug currently).

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    So there have been multiple people lately who's run into trouble with localization, so I burned some time today and write a sample.

    It hasn't landed in mac-samples yet, but you can get it from https://github.com/xamarin/mac-samples/pull/17

    It uses both resx and storyboard strings localization to translate a few items. Hopefully it'll be helpful.

Sign In or Register to comment.