3

I build a project using XCode 4 and I was running on the simulator since now. I had noticed that the strings in System type "Edit" and "Save" buttons where in english, but everything in my simulator was set to french. I suspected a bug like the one I had in XCode 3.

But now I'm running on my pure french configured iPhone, and those buttons are still in english, and are not localised as in other apps I can use.

I noticed that in my info.plist, the "Localization native development region" was set to "en" by default. I've changed this to "Fr" or "France" in the drop down menu, but that does not chage anything.

How may I correct this to make those buttons show a localized title ?

Oliver
  • 23,072
  • 33
  • 138
  • 230

2 Answers2

7

I had basically the same question, but Black Frog's answer didn't really help me. I did some research and this is what I found out:

The localization is primarily based on the bundle. With info.plist you can add localizations that aren't in the bundle, but you can't remove localizations that are present in the bundle.

The preferred way to add a French localization in Xcode 4 is to do the following:

  1. Open project in Xcode >= 4.0.2
  2. Click on project file
  3. Select item under Project title on the right
  4. Check Localizations table.
  5. Select the localization you want to duplicate (English)
  6. Click + and select the language you want you're app to use (French)

If you don't wan't to support English there are two additional steps:

  1. Select the localization you want to remove (English)
  2. Click - and delete the files

Special thanks to Nekto who helped me figure this out.

Community
  • 1
  • 1
Erik B
  • 40,889
  • 25
  • 119
  • 135
1

You have to create localized version of your nib files. Or you can set the text of each button/label to a localized string in view load.

Black Frog
  • 11,595
  • 1
  • 35
  • 66
  • @Black Frog : Do you answer my question ? Why should I have to localize a NIB to make a system button adapt its text to the iPhone language. I would have made a standard button in that case. If you don't answer the question, please update or I will vote down. – Oliver May 01 '11 at 01:23
  • @Oliver Thankfully I read your comment before I hit "Post Your Answer" for my very educated guess. – Matthias Bauch May 01 '11 at 03:55
  • @Oliver, if you create your system button at runtime using [nitWithBarButtonSystemItem:target:action:](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIBarButtonItem_Class/Reference/Reference.html#//apple_ref/occ/instm/UIBarButtonItem/initWithBarButtonSystemItem:target:action:) it will properly localized the string. – Black Frog May 01 '11 at 11:59
  • @Black Frog : I've created a button like you says with `UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(save)]; self.navigationItem.rightBarButtonItem = doneButton;` and its title on my iPhone is "Done"... Not localized. – Oliver May 01 '11 at 12:13
  • 1
    @Oliver, log the following information `[[NSBundle mainBundle] preferredLocalizations]` and let me know what you get. – Black Frog May 01 '11 at 12:20
  • @Black Frog : it returns "en". In my Info.plist, i had "Localization native development region". I tried to change it to "France". In my app directory, I have by default a en.lproj directory that contains Main.xib, InfoPlist.strings and the first ViewController xib created by the project template. All the other files are outside this en.lproj directory (by default) – Oliver May 01 '11 at 12:29
  • @Oliver, have you changed language in the iOS simulator? Or do want the system button to display French on a English device? Because the app is going to default to whatever language is on the device. – Black Frog May 01 '11 at 12:48
  • @Black Frog : everything is set to french (any reference to english in the simulator is deleted from prefs). But I know there is a bug for this on the simulator. So I'm testing on a pure french iPhone. That is configured to french language/localisation/timezone/keyboard/... And still display those system buttons in english. – Oliver May 01 '11 at 13:06
  • @Black Frog : Strangefully, you were right. Localising the project solves the problem, but I don't see why ? Looks like a bug. – Oliver May 04 '11 at 23:49