Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4: Framework localization not working

I am developing my own framework using Xcode 4, and I'm using it in two sample apps (a console one, and a Mac OS X Cocoa application).

I'm trying to add localization to the framework, so I've created two versions of a Localizable.strings file (en and fr versions), but every time I'm trying to print a localized string from the sample apps, I only get its technical name. For example, with the following line inside the framework's code:

NSLog(NSLocalizedString(@"LOC_TEST", nil));

I only get "LOC_TEST" displayed in the output...

Localization works fine with the Cocoa app itself however (meaning the Cocoa app's localized strings are shown appropriately).

Following this article, I have tried to add localizations in the framework's plist file:

<key>CFBundleLocalizations</key>
<array>
    <string>en</string>
    <string>fr</string>
</array>

But it didn't change anything...

What am I missing?

like image 905
Romain Avatar asked May 22 '11 08:05

Romain


1 Answers

The cause for not picking a right .strings file by framework is in NSLocalizedString macro:

#define NSLocalizedString(key, comment) [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]

Framework's location of .strings file is not [NSBundle mainBundle] as specified in macro.

From what I see, you'd need to use NSLocalizedStringFromTableInBundle instead and specify your framework's bundle location.

like image 88
Piotr Byzia Avatar answered Sep 21 '22 18:09

Piotr Byzia