I found that after a couple of days of successfully working and debugging localized applications on the Simulator, it (or the Xcode deployment process) fell into a state in which, if the simulator was installed in one of my supported local languages, it will work when launched with the following stack:
3 CoreFoundation 0x01780e6a +[NSException raise:format:] + 58 4 UIKit 0x008050fa -[UINib instantiateWithOwner:options:] + 2024 5 UIKit 0x00806ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168 6 UIKit 0x0060c17a -[UIApplication _loadMainNibFile] + 172 7 UIKit 0x0060ccf4 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 8 UIKit 0x00617617 -[UIApplication handleEvent:withNewEvent:] + 1533 9 UIKit 0x0060fabf -[UIApplication sendEvent:] + 71 10 UIKit 0x00614f2e _UIApplicationHandleEvent + 7576 11 GraphicsServices 0x01e13992 PurpleEventCallback + 1550
The failure occurs because UIApplication does not load the MainWindow.nib file:
Application termination due to a non-displayable exception 'NSInternalInconsistencyException', reason: 'Failed to load NIB bundled:' NSBundle /.app> (loaded) 'with the name' MainWindow '
When localizing the application, you have several options. You can do one (or both) of the following:
- Locate each Xib file that is downloaded based on the language on the device. Thus, your localized user interface is fully configured from Interface Builder.
- You can configure the Localizable.strings file for each target and access them from the code.
I chose later because I wanted all my localized strings to be in one place (so that this can be translated right away). This means that I do not have any xib files in the language directories in my project (fr.lproj, zh-Hant.lproj, etc.). Instead, I have en.lproj full of all my xib files (nib files after they were created) and language directories containing the corresponding translated Localizable.strings files.
As I said, this works fine for a couple of days. Today (and I donβt know exactly what), the application on the simulator started crashing at startup. Installing the application on the device worked fine, and the App on the simulator in English mode worked fine.
After a big filling, I realized that the simulator was crashing because it was looking for its nib files in a language-specific directory (fr.lpro, sz-Hant.lproj, ja.lproj depending on the language settings).
So, it looks like the Simulator is in a state where it is not looking for the default language directory (en.lproj) after it has failed to find the nib in the language-specific directory.
I worked on the problem by going to the application directory for the simulator (based on the above exception message):
/Users/.../Library/Application Support / iPhone Simulator / 4.3 / Application //. application
Then go to the language-specific subdirectory and copy all the nib files from en.lproj to this directory.
By copying the files manually, the simulator loads the language-specific nib files (which are actually just copies of the files in the en.lproj directory), and everything works fine.
So my questions are:
- Is this just a bug in the simulator? So the big NO to this
- Has anyone else had this problem? Yes
- Is this the result of some obscure Xcode settings that I accidentally switched? No, not like that
Update
Having discovered today that this issue is not limited to the simulator, this is happening on the device. Thus, the workaround described above (copying feathers from the default language directory to the target language directory) obviously does not work on the phone.
I tried McCygnus to suggest a fix (remove all localizations for my xibs, which moves them back to the root directory), and this sorted it for me. Therefore, I assume that the localization system checks the current language directory, and then the root, it will not return to your default language.