Can I localize a UIDatePicker?
Solution 1
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.
Solution 2
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
Solution 3
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.
Related videos on Youtube
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on April 16, 2022Comments
-
Admin about 2 years
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?
-
Admin almost 15 yearsI'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.
-
David Maymudes almost 15 yearshow are you initializing the date picker? are you leaving the locale and calendar properties set to nil, or are you setting them to something?
-
Admin almost 15 yearsAlso, I'm initializing the datePicker completely by code. Here's my code on pastebin. pastebin.com/m51df66f7
-
Raj about 12 yearslocale for NSDatepicker is deprecated in ios 5.1
-
kraag22 over 11 yearsif you set locale property in iOS 5.1.1 it works well too. Phone/Pad settings are ignored too
-
Dave DeLong over 11 yearsIf 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)". -
Mohannad A. Hassan over 11 yearsYes, 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.
-
Natan R. about 11 yearsCheck kraag22 and Dave DeLong's comments at FunkyKat answer below