Wednesday, March 23, 2011

Objective C/Xcode 4: Encoding Problem with Localizable.strings files

When compiling your Xcode project and your are using Localization in the Form of Localizable.strings and can happen that your get one of the following Build Errors.

Possible Build Errors

1.
Conversion of string failed. The string is empty. Command /Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copystrings failed with exit code 1

2.
CopyStringsFile
...
Localizable.strings:0: error: validation failed: The data couldn’t be read because it has been corrupted.

Causes


These kind of errors can happen if you copy and paste content within Xcode or from external files in your localization files. The consequence is that the encoding of the file changes to for example Western (Mac OS Roman). The Localizable.strings file should be in UTF-16 though.

Solution


1.
Like in the picture below, navigate in Xcode to the Localizable.strings location and open it so that you can see all the languages you are supporting.


2.
Left-click on the language file the causes the build error.

3.
Make sure your Utilities View is showing in Xcode. Activate on the button at mark 1 in Picture below.


4.
In the Utilities View select the File Inspector. (Small Logo that looks like Page)

5.
Under Text Settings change the encoding to UTF-16(Marked as 2 in the picture above). The Drop-Down might be grayed out but you can click on it anyways. Click on "Convert" on the Popup.

That's it your project should now compile again.

2 comments:

Patrick Chukwura said...

Awesome...this cleared the error right up.

Anonymous said...

OR you might have failed entering a ; at the end of the line...

Post a Comment