Search code examples
iphonexcodelocalizationnslocalizedstringlocalizable.strings

Custom NSLocalizedString?


Is it possible to use the NSLocalizedString infrastructure (based on localizable.strings) with a custom-defined "localization"?

The thing is, there are some languages that have different wordings for males and females. I want to ask the user's gender on first launch and then use the appropriate phrases. Of course, both are based on the same language. I can do it with my own code but I'd rather do it the easy way if possible.


Solution

  • NSLocalizedString is just a macro defined in NSBundle.h
    Redefine it or create a new one, for example NSGenderAwareLocalizedString to fit your needs.

    With the new macro, you are free to do whatever you want: two strings files per language, one for male and one for female. Or you can define a convention to derivate the key for a localized string for a female from the key of the male localized string.