I'm trying to localize a UIDatePicker. Apple's docs say that it should autodetect the current locale, yet the language stays the same, no matter what language I select. What do I have to do?
5 Answers
The locale property (and all other country specific format properties for that matter) defaults to the value returned by currentLocale, which in turns depends on the iphone's country settings, not the language settings. You need to set the appropriate country in the iphone general settings.

- 1,985
- 13
- 19
-
2locale for NSDatepicker is deprecated in ios 5.1 – Raj Jun 19 '12 at 06:40
-
Check kraag22 and Dave DeLong's comments at FunkyKat answer below – Natan R. Apr 08 '13 at 13:37
NSLocale in UIDatePicker is back since iOS 6. Phone settings in iOS 6 are ignored and used en_US locale by default, so you must set locale in code

- 3,233
- 1
- 23
- 20
-
1if you set locale property in iOS 5.1.1 it works well too. Phone/Pad settings are ignored too – kraag22 Oct 25 '12 at 13:53
-
2If you create a `UIDatePicker` programmatically, it'll be initialized with `[NSLocale currentLocale]`. If you're creating it in a xib, then make sure the value of the "Locale" attribute is "Default", and *not* "English (United States)". – Dave DeLong Nov 17 '12 at 00:48
From my experience, in iOS5 UIDatePicker seems to ignore the set locale and use the locale provided from the general settings. But it should work fine in iOS6.

- 1,650
- 1
- 13
- 24
-
Yes, I did. It was an application developed entirely for Arabic. I set the locale from the storyboard and **viewDidLoad** and the date picker 's locale was English, under iOS5, as the simulator's settings were. However, it worked for iOS6 just from the storyboard without setting it from **viewDidLoad**. Sorry for the late reply, I just saw your comment. – Mohannad A. Hassan Nov 25 '12 at 14:01
the UIDatePicker has a locale property; if you don't set it it should default to the user's preferred locale. When you say "no matter what language I select" what do you mean--are you trying to change the locale programmatically, or are you changing the device's default locale using the Settings page?

- 5,664
- 31
- 34
-
I'm referring to the International setting in Preferences. I have everything else set up to be an NSLocalizedString, and it all translates wonderfully. However, say I set the language to French in Preferences. My UIDatePicker will not display months in French. I have not set the locale at all, so I figured that this should display the correct locale. However, it's not. – Jul 20 '09 at 02:07
-
how are you initializing the date picker? are you leaving the locale and calendar properties set to nil, or are you setting them to something? – David Maymudes Jul 20 '09 at 20:21
-
Also, I'm initializing the datePicker completely by code. Here's my code on pastebin. http://pastebin.com/m51df66f7 – Jul 21 '09 at 00:56
To show the picker with the current language setted in the device, use this:
@property (weak, nonatomic) IBOutlet UIDatePicker *pickerView;
[_pickerView setLocale:[[NSLocale alloc] initWithLocaleIdentifier:[[NSLocale currentLocale] localeIdentifier]]];

- 446
- 5
- 13