我有一个本地化的
InfoPlist.strings
文件,其中包含如下键值对:
NSHealthShareUsageDescription = "This enables you to sync your workout data and measurements with Apple Health.";
NSHealthUpdateUsageDescription = "This enables you to sync your workout data and measurements with Apple Health.";
NSPhotoLibraryUsageDescription = "This enables you to add photos from your library.";
NSPhotoLibraryAddUsageDescription = "This enables you to add photos from your library.";
现在我想添加
CFBundleLocalizations
,这需要一个数组。如果我这样做...
CFBundleLocalizations = ["en", "de"];
...我收到构建错误“验证失败:无法解析属性列表,因为输入数据的格式无效”。
我想这是因为这不是在
.strings
文件中编写数组的方式。我该如何正确做?
不确定您是否应该在您的属性列表中本地化这些项目...
但是如果我没记错的话,您只需要在原始 plist 中引入自定义键,然后为数组中的每个项目提供翻译。所以你的 plist 中的数组看起来像这样:
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>de</string>
</array>
(要查看此内容,请右键单击您的 plist 并选择“打开为 -> 源代码”)
您应该将其更改为例如:
<key>CFBundleLocalizations</key>
<array>
<string>LOCALIZATION_KEY_EN</string>
<string>LOCALIZATION_KEY_DE</string>
</array>
然后在
.string
中使用这些键:
LOCALIZATION_KEY_EN = "en";
LOCALIZATION_KEY_DE = "de";