How can I make UIBarbuttonItem localizable?
My implementation:
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(cancel)];
Originally I thought that it is automatic, because it looks easy to make it like this, but looks like not.
EDIT1: Official Apple dox says that cancel, done, edit, save buttons are localized, but not sure how to make it.
Alright, I think I know what's going on.
UIKit decides in which language to display strings, based on the value of [[NSBundle mainBundle] preferredLocalizations]
. The idea behind this is to use translated resources whenever possible, falling back to English otherwise. For example, if you don't provide the translation of your app in Finnish and Finnish is selected in Settings->General->International->Language, your app will be in English. It may be a bit more complicated (UIKit may go through all the list of languages in the order displayed in Settings.app, trying to find the first language your app has translations for), but the point stands.
The above may be too obvious to miss a crucial nuance. The language determined by the above algorithm is used for the app's whole UI. For example, if the app bundle doesn't contain sk.lproj, nothing will be displayed in Slovak. In fact, it does make sense because otherwise some parts of UI would be in Slovak, other parts, in English.
Open the compiled app's bundle to see which *.lproj folders are there. The same set, sorted according to user preferences, will be returned by [[NSBundle mainBundle] preferredLocalizations]
. All localizable strings, including system bar button items, will be displayed in one of those languages. If you don't support, for example, Russian, the whole UI will appear in another language, even if Russian is selected in Settings.app.
If this is the case with your app indeed, there are two right things and one wrong thing to do:
If you see a different behavior, there may be something wrong with the project/build/built app. For example, I noticed that when you make a file localized, its non-localized copy doesn't get deleted from the previously built app bundle.
Bump, but I think Vanya’s problem might be the “Localization native development region”/CFBundleDevelopmentRegion
entry in Info.plist. If this is set to English and no localizations are explicitly made available as Costique explains, all system strings will be non-localized. But, set it to sk and - violà.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With