Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 768
Moshe Avatar asked Dec 22 '10 02:12

Moshe


1 Answers

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).

like image 193
NSGod Avatar answered Oct 09 '22 08:10

NSGod