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

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.

Related

Localization in Arabic

I am currently working on Localization. I have my app in English and Arabic. When I change the Language to Arabic all object goes to right, but there are few objects that i want them to be in left. Could please tell how to disable that function on a specific object?
Try setting the semanticContentAttribute property for the particular view to forceLeftToRight
someView.semanticContentAttribute = .forceLeftToRight
You can find more about it semanticContentAttribute in apple docs

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.

Creating Right to Left user interface for iOS

As per apple documentation
"iOS doesn’t automatically mirror controls, so if you want this behaviour for an iOS app, subclass the control and override the drawing methods."
I want to mirror my whole UI when the user selects the language as Arabic or hebrew in the home screen. i was searching for tutorials and documentation for the same but nothing helps.
Please find what i have done till now:
am using Xcode 6.1 and the app targets from iOS 7 to iOS 8.1.
Autolayout is enabled and am not using left or right constraints. am using only leading or trailing constraints.
Base internationalisation is enabled in project settings also have added the languages in localization. but when am running the app in device and set device language and region to arabic i cant get the mirrored UI. Do i have to do anything in code to get the mirrored UI?
What is the best way to support RTL based UI? How to subclass control and override drawing methods?
Please use this link to get the sample screenshot of my app.
I just found a easy way from Apple documentations instead of having 2 storyboards for RTL and LTR languages.
First of all enable Base internationalisation in project settings
Add your language - in my case i have added arabic and hebrew
xCode will localize your stroy boards and you can see different storyboard strings for different languages
Change the texts for your labels in the newly created strings file. In my case i changed in arabic and hebrew string files
Use AutoLayout for designing the whole UI.
Don't use Left or right constraints. Instead of use only leading and trailing constraints
Add the below code in your main function and run the app in simulator
NSArray* languages = [NSArray arrayWithObjects:#"ar", nil];
[[NSUserDefaults standardUserDefaults] setObject:languages forKey:#"AppleLanguages"];
Your app now will work for RTL language with mirrored UI without having 2 storyboards.
Note : if you are not setting the autolayout constraints correctly it wont work. However because of the new screens you have to learn to use auto layout.
in Swift
let languages = ["ar"]
UserDefaults.standard.set(languages, forKey: "AppleLanguages")

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.

Change language for a loaded tabbarController in ios

I want to change the language of the loaded tabbar controller from the app when the user selects the language from the tableview
You should rather use the language the user applied to the whole OS. (link)
Apple provides a nice macro called NSLocalizedString, you might want to check that out.
Example:
// Localizable.strings (German)
"Edit" = "Bearbeiten";
// code
label.text = NSLocalizedString(#"Edit", nil);

Resources