How manually change locale of UIDatePicker in iOS? - 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.

Related

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.

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

How does waze change objects location with their localization?

The first image is when the language is set to Hebrew, the second is in English. Look at the word " Thanks: " in the image. How Waze managed to change the location of the word to a Right To Left language? With regular localization
Thanks:x
should have been
תודות:X
That's just one example. Waze does that a lot.
Waze supports iOS 4.3 and later so AutoLayout is out of the question. With regular localization I know you can change the content of the word but location? that's a first.
Can I set an if iphone language is English then change the layout to..? (if so that's a lot of ifs.."
Thanks
Frankly, I do not know if there is any standarized way of doing that.
But I see several options:
1. Using localized .xib files or even full storyboards.
2. Changing that programmatically. Get the current localization and add some IFs to the view controller and re-arrange the items. If this is in a custom UITableViewCell subclass then overwrite the layoutSubViews (or so) and change the layout accoring to the locale settings. If you layout it within cellForRowAtIndexPath then apply the localization there.

iOS - Change Language for UIDatePicker by locale

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]

Resources