Search code examples
objective-cioslocalization

How to get localized Cancel, Done and etc?


UIBarButtonItem have identifiers like Cancel, Done and some others. They are shown as text to user. If user changes language then for example Cancel button will be translated automatically. And as developer you do not need to provide localization string for this buttons. It means that Cancel, Done and other strings already localized and comes together with OS.

Is here a way to get this strings programmatically?

I do not want to add additional strings to localization files. And if it is possible to access then it would be very good.


Solution

  • Here's a little macro I created to get the System UIKit Strings:

    #define UIKitLocalizedString(key) [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] localizedStringForKey:key value:@"" table:nil]
    

    Use it like this:

    UIKitLocalizedString(@"Search");
    UIKitLocalizedString(@"Done");
    UIKitLocalizedString(@"Cancel");
    ...