locked
Did locales just get nerfed? RRS feed

  • Question

  • User35261 posted

    Using the latest version of Xamarin iOS / Xamarin Studio, if I create a test app with a single page view, add a UI Element and set the text to any of Thread.CurrentThread.CurrentUICulture, Thread.CurrentThread.CurrentCulture, or NSLocale.CurrentLocale.Identifier, build and run on a simulator or device, I will see the English/US locale (en-US or en_US). Now if I go into my device settings and change the language to something else, kill and restart the app, I would expect the locale to change as well. However, it continues to show the English/US locale. I can change the Region, and still nothing happens. I am positive this worked earlier this week. Anyone else seeing this?

    Thursday, October 23, 2014 11:59 PM

Answers

  • User21936 posted

    To set the language in code: NSUserDefaults.StandardUserDefaults.SetValueForKey(NSArray.FromNSObjects(new NSObject[]{new NSString("ru")}), new NSString("AppleLanguages"));

    Sample is Russian "ru" so replace "ru" with whatever language you want to use. I just tested this and it did display the correct language on the iOS 8.1 simulator.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, February 18, 2015 1:34 AM

All replies

  • User76633 posted

    Having the exact same issue. Can't say if this worked earlier since this is my first try with localization on Xamarin. I have set both language and locale to Swedish/Sweden in the iOS simulator but get en-US when calling: System.Globalization.CultureInfo.CurrentUICulture;

    I get the same behaviour from: NSLocale.PreferredLanguages[0]; and NSLocale.CurrentLocale.Identifier;

    Any help with this would be most welcome.

    Friday, November 7, 2014 12:56 PM
  • User25759 posted

    This is a bug in Apple's iOS 8.1 simulator. If you run this code: var test2 = NSLocale.PreferredLanguages[0]; You will get back the "es" if it is set to spanish instead of english. However the rest would be "en" because it is basing it off the computer I believe. It is a tricky one. However I tested it on an iOS 7.1 and 8.1 simulators and get different results.

    See: http://stackoverflow.com/questions/26504304/ios-8-1-simulator-localization-broken-nslocalizedstring and http://stackoverflow.com/questions/26146668/ios8-1-simulator-always-uses-us-keyboard-layout-despite-german-hardware-keyboard/26690370#26690370

    Best, James

    Friday, November 7, 2014 7:24 PM
  • User35261 posted

    James, would you mind trying it on a device? I am also seeing the same bad behavior on an actual device - in this case an ipad air on ios 7.1.

    Thanks!

    Friday, November 7, 2014 8:38 PM
  • User73303 posted

    Hi, I use System.Globalization.CultureInfo.CurrentUICulture and I had the same problem in Simulator (all iOS version) but when I deployed to a device running iOS 8.1 it works.

    Monday, November 10, 2014 3:39 AM
  • User77747 posted

    Same problem here with iOS 8 localization in the simulator. Are there any Xamarin friendly workarounds? @JamesMontemagno? I'm not clear on how to implement the workaround to which you linked in C#.

    To clarify: I'm currently troubleshooting a problem that only occurs with iOS 8 in other locales, so using the iOS 7 simulator doesn't work me, and am therefore currently limited to using the device.

    Wednesday, November 26, 2014 12:51 AM
  • User25759 posted

    Your best bet is to run it against a physical device until they fix the simulators.

    I wrote the exact same Objective-C code and ran via Xcode and got the same result as running it from C# and Xamarin Studio. This indicated to me that it was the simulator and from reading heir release notes.

    Their weird workaround is for the simulator of some sort. I haven't done swizzling before for iOS. It is an odd private API I think. I am not really positive as to what they are doing to be honest with you. I have only done something similar on Android to do odd reflection stuff.

    Wednesday, November 26, 2014 1:17 AM
  • User35261 posted

    Hi James,

    I'm guessing the device you are running against is an iOS 8 device. As I mentioned, it does not work on iOS 7 devices. Does Xamarin have a policy on how long they will support prior versions of iOS? We have large corporate customers who don't upgrade their OS until the IT department has vetted everything, which may take months.

    Thursday, December 4, 2014 12:38 AM
  • User42834 posted

    I wanted to update this thread:

    I deployed sample code to a iOS7.1 physical device and confirmed this iOS localization bug. This worked normally on iOS8.1. It seems that only the collation is being set to "de" (for example), not the rest of the properties. That could be used as a workaround, check the collation and then switch the Thread.CurrentThread.CurrentCulture to match.

    System.Globalization.CultureInfo newLang = new System.Globalization.CultureInfo ("de-DE"); Thread.CurrentThread.CurrentCulture = newLang; Thread.CurrentThread.CurrentUICulture = newLang;

    Xamarin will support previous versions of iOS for the duration that they remain targetable and supported platforms in the current version of XCode. Rest assured, we will be supporting previous versions of iOS it as long as Apple does too.

    Saturday, January 3, 2015 9:44 PM
  • User21936 posted

    To set the language in code: NSUserDefaults.StandardUserDefaults.SetValueForKey(NSArray.FromNSObjects(new NSObject[]{new NSString("ru")}), new NSString("AppleLanguages"));

    Sample is Russian "ru" so replace "ru" with whatever language you want to use. I just tested this and it did display the correct language on the iOS 8.1 simulator.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, February 18, 2015 1:34 AM
  • User38995 posted

    I don't really understand what is happening, but localization works for me on IOS10 simulators, but stopped working on IOS 8.1 ones! It worked in the past, I did not change anything in my code! So, is it also a simulator bug? Or...? Now I don't have the possibility to test it on a real device, I have only an IOS10 type with me.

    Thanks!

    Thursday, October 20, 2016 12:50 PM