Search code examples
objective-ciosxcode4

Localizing implementation file in Objective C


I just started localizing my app, and what I want now is a method that is different for every locale. I have thought of certain ways to do this: since this method is currently the only method for the implementation, I could localize the whole .m. If this is even possible, it may work when there's only one method, but when new methods get added this could get problematic. The second option is simple decision-making in the method (if the locale equals X, then do this, otherwise do Y), but if there are 10 localizations that would create a ridiculously long method.

What would be the best way to do this? Just to be clear: I'm not talking about a few different strings that are dependent on the locale, the whole code is different for each locale.


Solution

  • You can't "localize" the .m since that gets compiled into the code. I think you're going to have to look at doing your option 2. Though a potentially more elegant way to implement that is to use an array of pointers to functions, and select from that array based on your locale.

    This can help:

    Objective-c function pointer