无法本地化infoplist.strings



我试图使用推荐的InfoPlist.strings 向Info.plist添加一个本地化值

我是否需要将密钥也保存在Info.plist中?

我的信息.plist

 <key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>

我的本地化字符串

en.proj
  -> InfoPlist.strings
    /* Localized versions of Info.plist keys */ 
    CFBundleName = "ABC-EN";
it.proj
  -> InfoPlist.strings
    /* Localized versions of Info.plist keys */ 
    CFBundleName = "ABC-IT";

如果我如上所述将密钥保存在Info.Plist中,那么在代码中,一个应该具有密钥值的变量

_localisedName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];

正在返回Info.plist(myApp)中的字符串如果我从Info.plist中删除CFBundleName,则字符串为<nil>

还有另一个我错过的场景?我已经尝试从副本捆绑包中添加和删除这两个文件(没有任何更改)。

;复杂的";搜索它,但我最终找到了它,我希望它对其他有用

_localisedName = [[[NSBundle mainBundle] localizedInfoDictionary] objectForKey:@"CFBundleName"];

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/occ/instm/NSBundle/localizedInfoDictionary

本地化信息字典

返回一个字典,其中包含捆绑包的本地化属性列表中的键。

  • (NSDictionary*)本地化信息字典

返回值一个字典,包含捆绑包的本地化属性列表(InfoPlist.strings)中的键。

讨论

在确定返回哪些资源时,此方法使用当前用户的首选本地化。如果首选定位不可用,则此方法选择在捆绑包中找到的最合适的定位。

您没有丢失设置,而是调用了错误的方法。您需要调用一个本地化的字符串方法,例如:

_localisedName = NSLocalizedString(@"CFBundleName", nil);

最新更新