How do I load the proper localized file?
I've got a plist which I localized. How do I load the plist properly?
Right now, I'm using this code:
NSArray *numbersArray = [[NSArray alloc]开发者_高级运维 initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"Numbers" ofType:@"plist"]];
What do I need to change my code to in order to load the localized plist?
NSArray *numbersArray = [[NSArray alloc]
initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"Numbers" ofType:@"plist"]];
This should work provided that you assure that you have the following bundle layout:
MyApp.app
// no Numbers.plist here
.....
en.lproj/
Numbers.plist // english-version
fr.lproj/
Numbers.plist // french-version
The important thing is that you do not have a Numbers.plist
file at the root level (aka-non-localized level) of the bundle, since if you do, that Numbers.plist will always take precedence over the localized version (for performance reasons).
精彩评论