Thursday, 14 August 2008

ArtenSUITE Part 15: Multi Language Support

A Development Journal
Part 15: Multi Language Support

One of the original design ideas for ArtenSUITE was to develop the application in such a way that conversion to a different (non English) language was straightforward. As it was I got carried away with other (more exciting) things and that idea fell by the wayside. Realising the error of my ways, I started to rectify that today.

The first thing I did was create two modules, mStrings, for storing the constants that will contain all the text that the user will see in message and dialog boxes. The second module mUIText, for storing the text elements for the UI controls, ie: Captions, Names etc. These two modules are stored within a Localisation folder inside my Project.

The constants are named in the following way:

kError = "An Error Occurred ..."
kDBConnectOK = "You Successfully Connected to the Database ..."

Real examples can be seen in the following screenshot taken from my project:

I then went through my application replacing the text with the name of the appropriate constant. Interestingly enough if you are fairly consistent with your messages you will be surprised how many times you use the same type of message, meaning that the amount of constants required is probably smaller than you imagine.

It's important to keep the formatting and spacing within your code and not move that to constants. For example if your code says something like:

Message = "An Error Has Occurred: " + "Error Number: " + intErrNum

You would make the text into constants but leave the spacing in the Message string. It would look like this:

Message = mStrings.kErrorOccurred + " " +mStrings.kErrorNum + " " + intErrNum

The main reason for this is if you decide to implement another language and send an export of your modules to be translated there is a good chance the spaces will get 'lost' along the way.

So assuming all your text that will be seen by the user is contained inside a couple of modules all you need to do to implement another language is export these modules, get them translated, then re-import them and assign a language to them. Bingo! Multiple Language Support with the added bonus that it makes your code slicker and more maintainable.
Honest Expert Independent Technology Advice for Business

No comments: