March 27 2010
ibtool "Missing object" Confusion
This week, I ran one of my ibtool ruby scripts to localize an app. During the process, it generated the following error:
The error sounds innocuous. I searched on Google for it and got literally no results. Unfortunately, the result is quite bad: a partially localized XIB/NIB. The error means ibtool has encountered a string in the strings file with an ObjectID that isn’t present in the source XIB file. In my case, I had deleted a placeholder string from an NSTextFieldCell element. When ibtool is unable to find this ObjectID in the source XIB, it stops localizing the new XIB. Not a pretty bug (rdar bug #7801770).
To show the confusing result, I reproduced this problem in a new project:
- Create a new Mac OS X app project in Xcode.
- Open Interface Builder and add a button to the main window in MainMenu.xib.
- Generate MainMenu.strings: ibtool --generate-strings-file MainMenu.strings English.lproj/MainMenu.xib.
- Open MainMenu.strings and do a search/replace "; for 1"; so that every element name is touched.
- Generate the localized XIB with a button: ibtool --strings-file MainMenu.strings --write MainMenu.with.button.xib English.lproj/MainMenu.xib.
- Open English.lproj/MainMenu.xib and remove the button. Save that.
- Generate the localized XIB with a button: ibtool --strings-file MainMenu.strings --write MainMenu.without.button.xib English.lproj/MainMenu.xib. This command should generate the error.
- Dump the strings for first localized XIB: ibtool --generate-strings-file MainMenu.with.button.strings MainMenu.with.button.xib.
- Dump the strings for second localized XIB: ibtool --generate-strings-file MainMenu.without.button.strings MainMenu.without.button.xib.
- Diff the strings files with Changes: chdiff MainMenu.with.button.strings MainMenu.without.button.strings.
- Diff the XIB files with Changes: chdiff MainMenu.with.button.xib MainMenu.without.button.xib. </ol> The problem is clearly visualized in the two screenshots below, taken from Changes. Diff'ing the XIB files shows that ibtool stops localizing the new XIB when it cannot find the missing ObjectID. Look at Changes' scrollbar marks. However, diff'ing the strings files makes it far less clear how ibtool failed. Changes' scrollbar marks are distributed across the entire file. Yet another reason to always verify the newly-created localized XIBs by comparing strings files... :)