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

查看:19
本文介绍了如果当前语言不存在本地化版本,如何加载默认语言 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 有效地使用了 CFBundleDevelopmentRegion(又名本地化原生开发区域")应用程序/bundle 的 Info.plist 文件中的条目以指定备用"语言,如果您愿意的话.

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 目录下的 code>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天全站免登陆