Localizing the Cut|Copy|Paste menu on iOS
Asked Answered
Y

6

34

Im having some issues localizing a danish app ive made. (The language, not the pastry)

I have set the CFBundleDevelopmentRegion to da_DK for danish in my info.plist, but the popup appearing for text input is still in english, even on phones running the danish OS.

enter image description here

How in Jobs name can i change this ?

The test device is a non-jailbroken iPhone 4S running iOS 5.1 with Danish as its iOS setting, and a danish itunes account associated.

I do not use .xibs for designs. all interfaces are programmed as viewcontrollers.

Yeomanry answered 27/6, 2012 at 11:16 Comment(4)
it should change when you change the phone, this is a curious caseKurtz
Truely. Have restarted the device several times, and as you see from the keyboard, the language for the iphone is danish... Curious...Yeomanry
Hehe! This is funny! Maybe you should file an incident report to Apple about this?Mcguigan
Tested on three different devices... all yield same result. :IYeomanry
L
40

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

Lamellar answered 1/7, 2012 at 13:2 Comment(2)
Hi there, +1 for goind the scientific method on this, but could you try including the missing .strings files that are missing from the git repos ? the InfoPlist.strings are missing german, turkish and danish...Yeomanry
I fixed that and added a NSLocalizedString call. I renamed the InfoPlist into Localizable.strings, the default name. I dont know, why Xcode picked another name.Lamellar
L
7

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>    
Liberalize answered 30/3, 2016 at 14:28 Comment(0)
M
3

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

Masorete answered 16/12, 2013 at 21:20 Comment(0)
G
2

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.

Gateway answered 1/7, 2012 at 14:25 Comment(0)
Y
1

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

Yachting answered 2/7, 2012 at 8:28 Comment(0)
S
-1

Search if your .xib is localized (you'll find it in the inspector on the right panel) if so go to your Project/Target-Settings press the +-Sign and select "Duplicate English to Danish" or something which means the same (I can't check the right item at the moment)

Btw it's called iPhone 4S.

Syd answered 27/6, 2012 at 12:13 Comment(6)
I do not use .xibs for designs. all interfaces are programmed as viewcontrollers.Yeomanry
as said, I'm not using interface builder. Im programatically building all my views.Yeomanry
I haven't seen any project which doesn't have a MainWindow.xib. I also didn't know that an app without it will work.Syd
Of course. the xib files are only there for visual aid when constructing views. I prefer to do it all by code.Yeomanry
I knew this, I was just wondering if it's possible to create an app without MainWindow.xib. I just read some posts and you're totally right. In this case you need to search for another language setting. I don't know any other place, where you can localize something but the CFBundleDevelopmentRegion.Syd
Me neither :] Thats why I am bewildered by this bug.Yeomanry

© 2022 - 2024 — McMap. All rights reserved.