Can I localize a UIDatePicker?

13,604

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.

Share:
13,604

Related videos on Youtube

Admin
Author by

Admin

Updated on April 16, 2022

Comments

  • Admin
    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
    Admin almost 15 years
    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.
  • David Maymudes
    David Maymudes almost 15 years
    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?
  • Admin
    Admin almost 15 years
    Also, I'm initializing the datePicker completely by code. Here's my code on pastebin. pastebin.com/m51df66f7
  • Raj
    Raj about 12 years
    locale for NSDatepicker is deprecated in ios 5.1
  • kraag22
    kraag22 over 11 years
    if you set locale property in iOS 5.1.1 it works well too. Phone/Pad settings are ignored too
  • Dave DeLong
    Dave DeLong over 11 years
    If 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
    Mohannad A. Hassan over 11 years
    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.
  • Natan R.
    Natan R. about 11 years
    Check kraag22 and Dave DeLong's comments at FunkyKat answer below