lmirosevic
lmirosevic

Reputation: 16317

Can you programmatically get access to the standard localised strings in Cocoa Touch?

Some iOS controls have localised strings built in by Apple. The "Done", "Edit", "Back" bar button items are some examples. Is there a way to access these strings?

I am making a UIActionSheet with standard "Delete" or "Cancel" options, just like when you delete a contact in the Contacts app.

Is there a way to reference these strings in code? If not, is there somewhere I can at least get these strings (like extracting them from the resources of an Apple app)? It would save extra localisation work and would ensure consistency with the platform.

Upvotes: 18

Views: 2948

Answers (2)

myell0w
myell0w

Reputation: 2200

It's possible to access the localised strings from the UIKit bundle with this snippet:

static NSString * UIKitLocalizedString(NSString *string)
{
    NSBundle *UIKitBundle = [NSBundle bundleForClass:[UIApplication class]];
    return UIKitBundle ? [UIKitBundle localizedStringForKey:string value:string table:nil] : string;
}

Full credit goes to 0xced (Usage in XCDFormInputAccessoryView)

Upvotes: 5

Matthias Bauch
Matthias Bauch

Reputation: 90127

If iOS is like Mac OS each app carries their own Localizable.strings file. And in each strings file you have all those little strings like Done, Edit, Cancel and so on.

These are some strings I copied from the English Localizable.string file from Finder.app:

<key>AL1</key>
<string>Cancel</string>
<key>AL4</key>
<string>OK</string>
<key>AL9</key>
<string>Don’t Save</string>
<key>FF24</key>
<string>Save</string>
<key>U32</key>
<string>Yes</string>
<key>U33</key>
<string>No</string>

You get the idea. Each little string is localized in each app.

This one is from iTunes.app.

/* ===== Ask User Strings ===== */
"23987.001" = "Yes";
"23987.002" = "No";
"23987.003" = "OK";
"23987.004" = "Cancel";
"23987.005" = "Ignore";
"23987.006" = "Quit";
"23987.007" = "Don’t Quit";
"23987.008" = "Apply";
"23987.009" = "Don’t Apply";
"23987.010" = "Later";
"23987.011" = "Don’t Save";
"23987.012" = "Save";
"23987.013" = "Stop";
"23987.014" = "Continue";
"23987.015" = "Delete";
"23987.016" = "Remove";
"23987.017" = "Replace";
"23987.018" = "Don’t Replace";
"23987.019" = "Do not ask me again";

Looks a little bit more structured. Copying their files is probably not allowed though ;-)


An answer in apples devforum by Quinn (eskimo1) from Apple Developer Relations.

Some UI elements are automatically localised for you. For example, the artwork on a UIBarButtonItem. However, there's no supported way to get to the strings like "OK" and "Cancel" as they are used in a UIActionSheet. They should, however, be trivial for your localiser to cope with.

2 years old though. But newer threads have the same outcome. No way to get those strings.

Upvotes: 6

Related Questions