如果当前语言的本地化版本不存在,如何加载默认语言plist? [英] How can I load a default language plist if the localized version does not exist for the current language?

查看:122
本文介绍了如果当前语言的本地化版本不存在,如何加载默认语言plist?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在像这样加载plist:

I am loading the plist like so:

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

但是,如果当前设备的语言不存在plist,则contentArray为nil.我该如何默认为英语?

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

推荐答案

NSBundle有效地使用

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

然后,Info.plist指定enCFBundleDevelopmentRegion.

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

如果法国用户运行该应用程序,并且fr没有本地化的Numbers.plist文件,则NSBundle应该在en.lproj目录中返回Numbers.plist文件.

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.

这篇关于如果当前语言的本地化版本不存在,如何加载默认语言plist?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆