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

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

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


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.


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.

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

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

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

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.

Tuesday, March 22, 2011

Objective C/Xcode 4: How to label and internationalize a Round Rect Button (UIButton) programatically

If you only support one language it is easy to go into Interface Builder and set the Label of your Round Rect Button. For localization it is not as easy though.

How to use localization for UILabels

Text Label elements or UILabels can easily be set to a localized String with this command.

@synthesize nameLabel;


self.nameLabel.text = NSLocalizedString(@"name.label.translation", @"Comment for the name label.");

How to NOT use localization for UIButtons

Since buttons have different states the label would disappear if you click it and you only set the title like that.
@synthesize myButton;
self.myButton.titleLabel = = NSLocalizedString(@"button.label.translation", @"Comment for the button label.");

How to USE localization for UIButtons

The proper way is to assign the localized string to all states of the UIButton.

@synthesize myButton;
NSString *buttonLabelString = NSLocalizedString(@"button.label.translation", @"Comment for the button label.");
 [self.myButton setTitle:buttonLabelString forState:UIControlStateNormal];
 [self.myButton setTitle:buttonLabelString forState:UIControlStateHighlighted];
 [self.myButton setTitle:buttonLabelString forState:UIControlStateDisabled];
 [self.myButton setTitle:buttonLabelString forState:UIControlStateSelected];

Wednesday, March 9, 2011

iPhone App: HT-SmartViewer Lite now in the AppStore

Its done. My first iPhone App made its way in the AppStore.

Get it for free now!

The App is a Match Viewer and Statistics App for the free Online Soccer Manager Hattrick. We hope to get people to use it and participate in the process to make it a really great, fun and useful Hattrick App.

Languages supporter are right now English, German, French and Spanish. If you want to see it in a different language feel free to contact us.

For feedback, news and more go to the HT-SmartViewer Homepage oder the HT-SmartViewer Forum.