specta / expecta

A Matcher Framework for Objective-C/Cocoa
MIT License
1.59k stars 158 forks source link

Localization problem #151

Closed nickbit closed 9 years ago

nickbit commented 9 years ago

I have something like this

expect([OKPCreditCardInfo messageWithCreditCardError:OKPCreditCardErrorCCNumberTooShort]).to.match(NSLocalizedString(@"CC number too short", nil));

The return statement for messageWithCreditCardError:OKPCreditCardErrorCCNumberTooShort is exactly the same (NSLocalizedString(@"CC number too short", nil)) and the test still fails. Seems that the localization for the class is non english (which is correct) while the localization for the test class is english.

Any thoughts?

orta commented 9 years ago

Could the test bundle think it only has 1 localisation, while the app itself can support many?

nickbit commented 9 years ago

I added the localization files in the test target. This didn't change anything. The expected value is english, while the returned value by the object tested is non english like expect("english", "non english") Is there a way to synchronize the localizations?

orta commented 9 years ago

I'm afraid this is outside of my scope, I've not done enough localization to know what's going on here. Anyone else?

tonyarnold commented 9 years ago

You will need to look at using NSLocalizedStringFromTableInBundle() rather than plain old NSLocalizedString(), and pass it the correct bundle for your app/framework. objc.io did a pretty great overview a while back: http://nshipster.com/nslocalizedstring/

nickbit commented 9 years ago

Thank you all for your answers. The problem was that the NSLocalizedString was redefined in the project but not in the test class. Had to import the relevant header file to fix that. Closing the issue.