title: How are XIBs loaded for localized apps?
body: <p>I found after a couple of days of successfully running and debugging localized apps on the Simulator it (or the XCode deployment process) got into a state where, if the Simulator was set to one of my supported local languages, it would crash on startup with the following stack:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>The crash is happening because the UIApplication is failing to load the MainWindow.nib file:</p>
  
  <blockquote>
    <p>Terminating app due to uncaught
    exception
    'NSInternalInconsistencyException',
    reason: 'Could not load NIB in bundle:
    'NSBundle
    /.app>
    (loaded)' with name 'MainWindow''</p>
  </blockquote>
  
  <p>When you localize an app you have a couple of options. You can do one (or both) of the following:</p>
  
  <ul>
  <li>Localize each Xib file which gets loaded based on the language on the device. So your localized UI is completely configured from Interface Builder.</li>
  <li>You can set up a Localizable.strings file for each language target and access the strings therein from code. </li>
  </ul>
  
  <p>I chose the later because I wanted all my localized strings in single place (so it can be translated all at once). What this means is that I don't have any xib files in language specific directories in my project (fr.lproj, zh-Hant.lproj etc...). Instead I have en.lproj full of all my xib files (nib files once they are built) and language specific directories containing the corresponding translated Localizable.strings files.</p>
  
  <p>As I mentioned, this has been working fine for a couple of days. Today (and I am not sure at exactly what point), the App on the Simulator started crashing on startup. Installing the App on the device worked fine and running the App on the Simulator in English mode worked fine.</p>
  
  <p>After a great deal of stuffing around, I realised that the Simulator was crashing because it was looking for its nib files in the language specific directory (fr.lpro, sz-Hant.lproj, ja.lproj depending on the language settings).</p>
  
  <p>So it seems like the Simulator is in a state where it isn't looking the default language directory (en.lproj) after it fails to find the nib in the language specific directory.</p>
  
  <p>I worked around the problem by going into the application directory for the simulator (based on the exception message above):</p>
  
  <blockquote>
    <p>/Users/.../Library/Application
    Support/iPhone
    Simulator/4.3/Applications//.app</p>
  </blockquote>
  
  <p>Then going into the language specific subdirectory and copying all the nib files from en.lproj into that directory. </p>
  
  <p>Having copied the files by hand, 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.</p>
  
  <p>So my questions: </p>
  
  <ul>
  <li>Is this just a bug in the Simulator? <strong>So a big NO to that</strong></li>
  <li>Has anyone else had this problem? <strong>Yep</strong></li>
  <li>Is this a result of some obscure XCode setting that I have accidentally toggled? <strong>Nope, doesn't look like it</strong></li>
  </ul>
  
  <p><strong>Update</strong></p>
  
  <p>Discovered today that this issue not confined to the simulator, this happens on the device. So the workaround I described above (copying the nibs from the default language directory to the target language directory), obviously doesn't work on the phone. </p>
  
  <p>I tried McCygnus's suggested fix (remove all localizations for my xibs, which moves them back into the root directory) and that sorted it for me. So I guess the localization system checks the current language directory and then the root, it won't fall back to your default language.  </p>