正在尝试读取 InfoPlist.strings 文件...正在获取密钥(?)

Trying to read InfoPlist.strings file... getting the key (?)

许多人不知道,在 iOS 和 OSX 上本地化应用程序名称的方法是将 InfoPlist.strings 文件添加到包中并本地化该文件。人们将此文件与 Info.Plist 文件混合在一起。本地化未在 Info.plist 中完成,而是在 InfoPlist.strings 文件中完成。

也就是说,我用两个键创建了这个文件:CFBundleDisplayNameCFBundleName,一如既往。这非常有效,您可以在不同的本地化版本中为您的应用程序定义不同的名称。该文件可以无缝运行。您什么都不用做,只需将文件添加到项目并对其进行本地化。

InfoPlist.strings 是这样的字符串文件:

"CFBundleDisplayName" = "My Localized App Name";
"CFBundleName" = "My Localized App Name";

特别是对于这个项目,我还必须在 运行 时间读取 CFBundleDisplayName 的值。

我试过使用这个代码:

NSString *appName = [[NSBundle mainBundle] localizedStringForKey:@"CFBundleDisplayName" value:nil table:@"InfoPlist"];

读取 CFBundleDisplayName 键,但我得到的值是 CFBundleDisplayName。换句话说,我提供密钥并接收回密钥,而不是值。我应该收到 My Localized App Name.

我错过了什么?

我在 Swift 中完全做到了这一点,并且按预期工作。

let appname = NSBundle.mainBundle().localizedStringForKey("CFBundleDisplayName", value: nil, table: "InfoPlist")

但是,如果我从相应的 InfoPlist.strings 文件中删除去本地化字符串,它 returns "CFBundleDisplayName".

因此,请检查您的 .strings 文件中是否遗漏了某些内容

After trying several possibilities..

BUG是"A second copy of InfoPlist.strings inside the project"