Localizing the Cut|Copy|Paste menu on iOS

In the Xcode's file tree (Project Navigator) select your project. in the right hand pane select your project again. select Info and add your language.

configure i18n


I created a sample project, this is the result:

enter image description here


You can do this directly in the info.plist. Something like this:

<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleLocalizations</key>
<array>
  <string>en</string>
  <string>de</string>
  <string>es</string>
  <string>ja</string>
</array>    

Try adding/setting the "Localized resources can be mixed" flag in Info.plist to YES.


You must localize your app in Danish to make the standard UI elements appear in that language. This is to avoid having a UI with mixed languages.

If you don't use xibs, you'd usually do this by adding a Localizable.strings file to your project. In Xcode's "Add File" dialog, you can use the "Strings File" template (under "Resources") for this.

To actually localize the strings file, open the file inspector ( 1) and click the + button in the "Localization" section. You'll end up with the file being displayed as a group in the project navigator, with a sub-entry for each language.

The strings file has the format:

"Label_Text" = "Smørrebrød";

(don't forget the semicolon)

To use localized strings in your code, you can use the NSLocalizedString macro like this:

myLabel.text = NSLocalizedString(@"Label_Text", nil);

(The second parameter is for a comment. This can be useful if you use the genstrings tool to extract localizable strings from your code and give the resulting file to a professional translator.)

If you use the English strings as keys, you can leave the English version of Localizable.strings empty (but don't delete it).

Having a Localizable.strings file in the language that the user has selected will also cause standard UI elements, such as the editing menu, photo picker, and so forth, to appear in that language.


If you can't get it working the official way, as provided by @vikingosegundo, you can do this with some creative engineering (Creative as in, oh my god that is dangerous). I discovered this method when I accidentally overrode [NSBundle localizedStringForKey:value:tableName:].

1) Add a category to NSBundle with the following methods:

#import <objc/runtime.h>

+ (void) load  {
    Method original, swizzled;

    original = class_getInstanceMethod(self, @selector(localizedStringForKey:value:table:));
    swizzled = class_getInstanceMethod(self, @selector(swizzled_localizedStringForKey:value:table:));
    method_exchangeImplementations(original, swizzled);
}

- (NSString*) swizzled_localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName {

    NSLog(@"Key: %@. Value: %@", key, value);

    return [self swizzled_localizedStringForKey: key value:value table:tableName];
}

2) Where I simply log the key/value, you want to put an if ([key isEqualToString: xxx] ) block. In there, you want to catch (at least some of) the following key values: Cut, Copy[Menu], Select, Select All, Paste, Delete[Menu], Replace..., Define, Speak, Pause. These are the default values that can appear there.

3) When you have caught the value you can look up in a custom table or use hardcoded values. If you look up in a custom table make sure you have a catch in your swizzled method to avoid infinite looping in your custom table.

NB: Why do you need to swizzle? Because this over-rides all Apple text for you app. You will still want the defaults for all the other strings, so you need to swizzle to get the defaults for the strings you aren't interested in.

Good luck. Paul