ios - Xcode - 按语言更改 bundle 显示名称

标签 ios xcode

我希望本地化我的应用程序名称(英语和简体中文)。我在项目中本地化了 Info.plist 并添加了简体中文。所以我现在有两个 Info.plist 文件。我构建项目时发生错误。 “找不到Info.plist”。因此,我在“build设置”>“打包”>“Info.plist 文件路径”中编辑了 Info.plist 的路径。现在它起作用了。

问题是,在 Build Settings > Packaging > Info.plist File Path 处,Xcode 只寻找一个 Info.plist。如果我将路径更改为 zh-Hans.lproj/Info.plist 它只会在英文和中文语言设置中显示中文应用程序名称。当我将其更改为 en.lproj 时也是如此。

如何设置Info.plist的路径,以便xcode能够根据Language设置识别出其中有两个需要使用?

或者有比我正在做的更好的方法吗?

非常感谢!

最佳答案

您无需本地化 Info.plist 本身,而是将本地化字符串放入单独的文件 InfoPlist.strings 中。 Quoting Apple:

Localized values are not stored in the Info.plist file itself. Instead, you store the values for a particular localization in a strings file with the name InfoPlist.strings. You place this file in the same language-specific project directory that you use to store other resources for the same localization. The contents of the InfoPlist.strings file are the individual keys you want localized and the appropriately translated value. The routines that look up key values in the Info.plist file take the user’s language preferences into account and return the localized version of the key (from the appropriate InfoPlist.strings file) when one exists. If a localized version of a key does not exist, the routines return the value stored in the Info.plist file.

在显示名称的特定情况下,InfoPlist.strings 的每个本地化版本都将包含类似的内容

CFBundleDisplayName = "My Cool App";

只有在 InfoPlist.strings 中未覆盖 Info.plist 中的显示名称时,才会使用它。

关于ios - Xcode - 按语言更改 bundle 显示名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31056558/

相关文章:

ios - 一个面向其他普遍面向的应用程序如何强制启动肖像?

objective-c - TwoPieceImage 复杂化

iphone - 哪个是不允许在 "App would like to use your current location"中点击的委托(delegate)方法?

iOS:FBSDKShareDialog 自定义消息

ios - NSUbiquitousKeyValueStore花费太长时间进行初始同步

swift - 将框架添加到框架项目后单元测试失败

iphone - iOS : How to allign UITableView to bottom?

iphone - 如何裁剪(调整大小)从 iPhone 捕获的图像并从相册中选择?

swift 3 : 'Doesn' t match any overloaded Audio' error when using AVAudioPlayer

ios - 从 2 个 View Controller 传递数据而不使用 segue