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

这一生的挚爱 提交于 2019-11-28 06:19:22

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/13017013/how-can-i-load-a-default-language-plist-if-the-localized-version-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!