Thursday 17 May 2012

Avoid my mistakes when localising your iPhone/iPad app

One of the great things about the iOS (iPhone/iPad) world, is the geographic spread of users.  Everyone around the world is in love with Apple, from the US to China and everywhere in between.  This means a huge audience for your game, but it also means a huge number of languages to deal with.  How on earth do you reach all those users who don't necessarily speak your language?

The first game I developed was a cute Tetris type clone - Honey Pot.  It was my foray into iOS development.  The aim was to learn iOS programming, become fabulously wealthy and retire to a life of luxury.  As part of this dream, I was aiming to try out every piece of functionality that Apple offered, just to see how it works.  One thing I looked at, was how to localise the application for different languages.

Unlike some platforms I've used in the past, Apple has built localisation into the core of the iOS experience.  When done properly, the user sets their preferred language, then all the applications magically convert to the language.  It's designed to be simple and works well.  They've also given the ability to add different languages to iTunes as well, so people when shopping for apps see descriptions in their own language.  Great stuff, but how does it work?

At a basic level, Apple allows developers to store language specific versions of all assets that might be different for each language.  This obviously includes text, but it also includes images as well.  The idea is some images might be culturally specific and what's appropriate in one culture might be bad in another.  Within XCode, you can specify different versions of assets for each language you support.

The first thing I noticed, is that all my messages were stored as embedded text all over the place.  I added localisations into the game at a late stage.  Bad move.  This meant I'd have to do a piece of logic every time I wanted to display a message to the user.  Lots of work, with not much fun!

The sensible way of doing it, is to use a string file - Localizable.strings.  You create one string file for each language and it's a simple task of just updating the text appropriately.  Ray Wenderlich's team has a great tutorial here: How to Localize an iPhone App.

The other problem I ran into, was my superb artist had rendered a whole bunch of buttons for me, with lovely text embedded onto the image.  This was a problem.  I needed a version of the button for every supported language!  This was a pain to maintain, as well as making the executable much larger than it needed to be!

My solution, was to develop a little library that took my base image (minus the text) and added the custom text on top.  Perfect.  Using one image file, I can now have as many images as I like.

Just to make things fun, I was using a pre-rendered font atlas everywhere.  Using the great Glyph Designer, you can create some cool looking fonts to match your game.  This worked amazingly well, up until I ran into Unicode character sets - Chinese and Japanese!  Cocos2d limits the size of your sprite sheets to being 1024x1024 (if you want to support older iPhones).  When you put in all the characters in the Chinese character set, you soon run out of space!

To get around this, I had to do some pretty tedious manual work.  First of all, I dumped all the characters required into a single file, then pulled out the set of unique characters.  These were then the only characters I used in Glyph Designer.  Every time I added some new text, I had to make sure all the required characters were in the character set.  Not much fun!  The end result was some pretty text, but it was a lot of work!

So, these are my three recommendations if you intend on localising your iPhone/iPad app:

  • Always, always put all your text into a separate file.  Resist the temptation of putting any user facing text into a hard coded string
  • Design your buttons with localisations in mind.  Never render your text onto graphics.  Always add the text on later
  • Bear in mind unicode character sets - Chinese, Japanese, Thai and Arabic in particular
As a result of localising my puzzle game Honey Pot, I have about 50% of my downloads from China and another 15% from Japan.  Prior to localising my game, I got very few downloads outside European countries.  Definitely a good result!

So, how do I get my text translated?  More on that next time!


No comments:

Post a Comment