Quantcast
Viewing all articles
Browse latest Browse all 3

How To Make NSLocalizedString Fun To Use

To localize apps (which means: to make them work in other languages) you need to avoid using plain @”strings” and instead use the one of the tedious functions NSLocalizedString, NSLocalizedStringFromTable, or NSLocalizedStringFromTableInBundle, that take two to four arguments. Horror.

I mean, any sane programmer will get a headache from replacing a simple @"Great!" with this:

NSLocalizedStringFromTable(@"Great!", @"Messages", nil)

So I took a leaf from WordPress, and shortened the calls:

#define __(str) NSLocalizedStringFromTable(str, @"Messages", nil)
#define __d(str, description) NSLocalizedStringFromTable(str, @"Messages", description)

Now localization is easy and fun: I simply type

__(@"Great!")

and the localization code is taken care of by the C pre-processor. Mission accomplished.


Viewing all articles
Browse latest Browse all 3

Trending Articles