Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
888 views
in Technique[技术] by (71.8m points)

objective c - How can I load a default language plist if the localized version does not exist for the current language?

I am loading the plist like so:

 NSString * plistPath = [[NSBundle mainBundle] pathForResource:@"Names" ofType:@"plist"];
 NSDictionary * contentArray = [[NSDictionary alloc] initWithContentsOfFile:plistPath];

But contentArray is nil if the plist doesn't exist for the current device's language. How can I default to English?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

NSBundle effectively uses the CFBundleDevelopmentRegion (aka "Localization native development region") entry in the application/bundle's Info.plist file to specify the "fallback" language, if you will.

For example, let's assume we have the following bundle layout:

MyApp.app
 // no Numbers.plist here
.....
en.lproj/
    Numbers.plist // english-version
es.lproj/
    Numbers.plist // spanish-version

And, the Info.plist specifies a CFBundleDevelopmentRegion of en.

If a French user runs the app, and there is no localized Numbers.plist file for fr, then NSBundle should return the Numbers.plist file in the en.lproj directory.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...