0

after many unsuccesfully attempts to sort out the XIB localization in XCode 4, I decided to post an help request here :).

1) I select a XIB file, say MyViewController.XIB.

2) I click the [+] button in the Localization area in right panel but it’s impossible to select the language. After clicking, I don't know why but another resource is selected (for example, another XIB file).

3) In XCode inferface nothing happens but in the filesystem the file MyVieController.XIB is moved (MOVED! NOT COPIED) in the en.lproj folder.

4) I add a new localization (this time I can select the language), say Italian.

5) In XCode interface now I see two “children” of MyViewController.XIB: the english one and the italian one.

6) Another strange thing is that the “main” MyViewController.XIB and its english version point to the same file (in en.lproj folder) so that any modification made in the first is automatically made in the second and viceversa.

Anyone of you has an explanation for this behaviour, that seems very odd to me?

Thanks in advance for your answers,

Marco.

  • Is there anything wrong with the behaviour, or is is just that you'd want XCode to behave differently? Because if the latter, the only answer I can think of is "Because Apple chose to implement this that way." (I.e. without there being a "neutral" locale and making you choose which locale is the default.) – millimoose Oct 19 '11 at 00:13
  • @Inerdia. First of all, thank you for your fast reply. – MarcoSciamanna Oct 19 '11 at 00:55
  • @Inerdia. I don't know exactly which is the right behaviour, because Apple documentation is not so clear and because the tutorials I read in the Internet don't seem very clear about that. But it is very strange to me that, if I want some localizations, the english localization must be always present and I can't, for example, build only a french and italian localizations. – MarcoSciamanna Oct 19 '11 at 11:28
  • So, your question is “How to make an iPhone app without an English localization?” – that's been answered several times. – millimoose Oct 19 '11 at 12:02
  • possible duplicate of [How to make Cocoa understand that my iPhone app isn't in English?](http://stackoverflow.com/questions/7175156/how-to-make-cocoa-understand-that-my-iphone-app-isnt-in-english) – millimoose Oct 19 '11 at 12:04

2 Answers2

3

I believe this behavior is intentional and consistent with best practices as far as localization is concerned.

Generally speaking, the top level of the Resources directory is only for XIB/NIBs that are not localized. Once you localize a particular XIB, it should be stored in your primary language folder and any localizations should be stored in the other language folders.

Basically, Xcode is helping you not to create a problem by moving your "main" MyViewController.XIB into the en.lproj folder (which should be whatever you have set as your native development region) as the first step to adding a new language for that file.

OS X (and iOS) are smart enough to use the default language (as specified in the CFBundleDevelopmentRegion a/k/a/ Localization native development region) when a resource doesn't exist in Resources or the currently active language.

If you want to build only French and Italian versions (no English), just make sure that you set the CFBundleDevelopmentRegion to the appropriate language code and the OS will then look in that directory for any resources that are not in the localized bundle.

Once you've set that, Xcode should (but doesn't appear to), put converted files into your requested default directory. A little digging around indicates that by editing your project.pbxproj file manually, you can set the developmentRegion to something other than English (I tested with fr), and that will make Xcode put the localized files in the right location.

gaige
  • 17,263
  • 6
  • 57
  • 68
0

I am pretty new to posting answers here, so please don't fire me if this is not the best place for this solution.

While this is not a direct answer to your question "Anyone of you has an explanation..." I feel compelled to answer your topic "XIB localization in XCode4 drives me crazy?" because I was looking for an answer to that very question, and I found that answer elsewhere.

My Problem = after localizing my XIB files in English and French, as outlined in your points 1)-5) my iPhone application would still show only English XIBs instead of French. The French XIBs were created and done properly in Xcode, and it turned out that something else, something unrelated, was causing the problem.

The following solution is borrowed from The Big Nerd Ranch Guide. I do not expect any votes here, all the credit goes to the excellent book from BNR.

There seems to be a glitch in Xcode (according to BNR, and proved to be true in my case) that sometimes Xcode ignores new resource file changes. To solve, delete the application from your iPhone, then choose Clean from the Product menu. This will ensure that the application is rebuilt from scratch. In my case, after doing this, the French XIBs loaded beautifully when expected.

Wojtek
  • 436
  • 5
  • 7