iOS - Change Language for UIDatePicker by locale - ios

I'm creating the app in "Herbrew" language. (Language of IPhone can be anything, but my app runs only in Herbrew).
In iOS for UIDatePicker, we have a property "locale" which will change the language that it is displaying. But in iOS5, the property is deprecated. How can I achieve it now?

Unfortunately, you cannot achieve this, not even with the calendar trick described by Martin Ulrich.
I've struggled with the same problem myself and after a long research, I found out the bitter truth: the only way to change the localization of the UIDatePicker is to change the device's language.
If the user will have the app's language as Hebrew, everything will be alright. If not, there's nothing you can do, except maybe create your own date picker. Sorry

You can set the calendar property of the UIDatePicker to [NSCalendar currentCalendar]

Related

UIDatepicker display future years with ' ---'

iOS UIDatepicker shows '---' for future years. How to achive this in iOS. It will show only till current year and after that it shows '---'. I seen this when we adding any contact in our iPhone contact app, where there is field to addBirth. You can see that.
Please see screen shot.
The UIDatePicker doesn't have option for this.
Available Picker modes: time, date, dateAndTime, countDownTimer.
You can set maximumDate value, so that date after that can't be selected using UIDatePicker.
If you need to fulfil the exact need, you have to create custom UIPickerView with multiple component and Manage all things. NB: This could be messy.

Changing locale of UIDatePicker in Countdown Timer mode

I have UIDatePicker in CountdownTimer mode and need to change the wording of hours and min to German locale. I tried both, to set locale to German (Germany) in storyboard and in code, but both failed and the app still shows default english words for hours and min.
timePicker.locale = Locale(identifier: "de")
When I configure locale on UIDatePicker in Date and Time mode, it correctly respects German locale and displays the date in german format. Any idea why locale does not change in Countdown timer mode? Thank you.
Thanks to Why UIActivityViewController doesn't display localized cancel string? post the solution also resolved the issue of localizing UIDatePicker in countdown timer mode, at least on iOS 11. Thank you.
Add this row into your info.plist:
And it also helps to correctly localize Cancel button of the system share sheet: UIActivityViewController - how to change the cancel button text.
I am mentioning here reply from APPLE that i got upon Technical support on this specific issue but unfortunately there is no support to this feature yet.
When running in the count down mode, UIDatePicker showns the hours and minutes to count down. In this context, the “hours” and “minutes” are not a format, thus not covered by locale;
Thing is that they did not mention any time line for support of this feature.

How manually change locale of UIDatePicker in iOS?

How manually change locale in UIDatePicker control?
I have UIDatePicker and language selection inside my App which is independent from standard localisation in iOS (I mean from general settings of the device). I need to change NSLocale of the UIDatePicker from code.
How to do that?
Remark: on several places I've read that this can not be done - it is correct?
only way to change the localization of the UIDatePicker is to change the device's language as I know.

Possible to hide a button on particular language in iOS with base localization?

I'm new to localization. I've got my app mostly converted, but I have a case where a button only appears in the US English version of the app, but no other languages. Is this possible using main.strings and localizable.strings?
Jakub Vano's answer is pretty useful, but also you can set that string with a special value as "notToShow" and do this
if ([NSLocalizedString(#"MyString", nil) isEqual:#"notToShow"]){
//hide button
}
If we are talking code, you can check current locale via
[[NSLocale currentLocale] localeIdentifier]
and show / hide button accordingly. If you are using storyboard / xib, you can have separate interface for each localization.

Simulating UIDatePicker date pick for testing

I'm using a combination of XCTest and OCMock for testing and I'd like simulate a user selecting a date from a UIDatePicker. Is there any way of doing this other than setting the date property?
If you want to create a UIDatePicker for selecting the date then The following tutorials will help you.
https://stackoverflow.com/a/11198489/2869784
http://www.techotopia.com/index.php/Using_the_iOS_7_UIPickerView_and_UIDatePicker_Components

Resources