iphone uidatepicker localization - iphone

I facing a problem with localization in iphone date picker.I want the date picker to show dates only in English, but now it takes the language which is set to the region in iphone settings.I tried various things which was not useful like the below.
setting the locale setting in the nib file of the uidatepicker.
setting the locale through code
NSLocale* locale = [[NSLocale alloc] initWithLocaleIdentifier:#"en_GB"];
[datePicker setLocale:locale];
[datePicker setCalendar:[locale objectForKey:NSLocaleCalendar]];
This did not work.If any one has good ideas to resolve the issue please help

I think this is a known issue. The date picker seems to rely on the current user's country settings which you cannot change from code. In fact, I don't know what the locale property is there for. It simply does nothing.

Related

Weird timezone issue with Tapku library

I have a strange issue with Tapku Calendar control library.
It was showing me wrong date information, so I replaced all timezones from
[NSTimeZone timeZoneForSecondsFromGMT:0]
to
[NSTimeZone systemTimeZone]];
All works well till here.
However, when I changed timezone in the file called
NSDate + CalendarGrid.m,
at that point my calendar selection of dates was disabled.
No touches are being detected on calendar.
I have done all this step by step and found this issue in NSDate+CalendarGrid.m file.
I have already spent lot of hours finding this.
Please help in how to fix this weird issue.
Thanks in advance.
I don't know about the touches Disabled Problem, But for fixing the wrong date information problem, what you can do is change the following line in viewDidLoad
[self.monthView selectDate:[NSDate date] month];
to
[self.monthView selectDate:[NSDate date]];
Hope it helps

init] returning date an hour in the past?

When I call
NSDate *now = [[NSDate alloc] init];
in order to get the current date and time, I check it with:
NSLog(#"Date now: %#", now);
the date outputted is one hour in the past.
2010-10-08 12:04:38.227
MiniBf[1326:207] Now: 2010-10-08
11:04:38 GMT
Is my time zone set incorrectly somewhere perhaps?
Thanks!
Michael
I've seen that behavior on the DatePicker running on iOS 4.1 devices while on iOS 4.0 and previous it does not happen. I can't confirm it is actually the same bug.
But I suggest you check whether is related with the acknowledged by Apple bug regarding dates/summer time/4.1 by running that code on < 4.1. Then you will need to decide whether to hack a fix for that particular version/dates or wait for the next release of the SDK to fix it and not support 4.1 devices...
The bug I'm talking about I believe only happens while passing dates within the summer time period (2010: 28th March - 31st October)
Use NSDateFormatter to localize the date:
NSLog(#"%#",[NSDateFormatter localizedStringFromDate:[NSDate date] dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle]);
Use NSDate *now = [NSDate date];
I am using it and giving me perfect result.
Maybe your timezone is wrong in your iPhone simulator. Press the home button, go to settings.app and correct it ;)

UIDatePicker Localizatiion Problem

How to Localized UIDatePicker according to language selection from the application.
UIDatePicker has locale property so how to use please give idea.
Thank You.
I know nscalendar has different calendaridendifiers for different locales maybe there is a way to set the pickers calendar source?
So yeah I just checked the docs and there are properties you can set for a calendar a locale etc. Just use that by default it uses nil which is defaults to the users current locale as it's calendar source.

UIDatePicker - Problem Localizing

I've created a UIDatePicker in my app and I also have support for several languages. My UIDatePicker is created in Interface Builder, and I have created a seperate localization XIB so I can customize my UIDatePicker.
Setting the "Locale" option in IB appears to do nothing. Attempting to change my DatePicker programatically with Locale and NSCalender also do nothing via the following code:
NSLocale * locale = [[NSLocale alloc] initWithLocaleIdentifier:#"es_ES"];
datePicker.locale = locale;
datePicker.calender = [locale objectForKey:NSLocaleCalender];
This results in an english picker.
Here's the really weird thing though. The word for "Today" is translated. As seen in the attached screenshot. (OK I'm not allowed to post images. But imagine a Date & Time picker with "May" in English and "Today" written "Ajourd'hui".
Based on what I've read, adding the UIDatePicker programatically doesn't seem to help much.
After further investigation, this is actually not handled by the language setting of the iPhone. The UIDatePicker is automatically localized based on the "Region Format" setting and not the language. This is odd because the dates are localized, so you would think the localization of the picker would be linked to the iDevice's language not the Region Format.
Anyway, to simulate the localized DatePicker in the Simulator:
Exit your app, go to Settings.
Select General
Select International
Select the bottom option, Region Format.
Change to the desired region.
Relaunch your app and see the new UI Picker!
As of iOS 6 UIDatePicker no longer looks at the device's settings for locale information. You must may set the NSLocale manually or it will use the default locale.
See this answer: https://stackoverflow.com/a/12975871/1128896
A simple solution:
datePicker.locale = [NSLocale currentLocale];
Updated
While the locale can now be set on UIDatePicker, by default it is set to 'Default' instead of any particular language. 'Default' will check the device's locale, and set itself to that. (see Dave DeLong's comment below). Therefore, most new projects shouldn't be impacted by this change.
If you are working with older projects, migrating to iOS 6, you may find that the UIDatePickers which are created in xibs have their locale defaulted to 'English' or another language instead of 'Default'. (I've found all of my old projects, pre iOS6, followed this behavior). To fix this, simply change the locale to 'Default' in IB.
What I am given to understand is that the UIDatePicker automatically shows in the locale the device is set as. I'm not sure how to override it, but it seems like you probably shouldn't override it.
From my experience the "Today" is following the settings you have in your info.plist. For some reasons they've forgotten to adapt this.
You can set the Date picker localization like this(I am using a language manager) in code.
func configurePickers() {
let languageID = AppLanguageManager.shared.currentLanguage
let loc = Locale(identifier: languageID)
[outgoingPicker, backPicker].forEach {
$0?.locale = loc
$0?.minimumDate = Date()
}
}
From interface builder, you also can set date picker localization:

Can I localize a UIDatePicker?

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?
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.
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
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.
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?
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]]];