Objective C InfoPlist.strings本地化 - 使用应用程序名称

3

我有一个${PRODUCT_NAME},用于为所有目标引用应用程序名称。我想在InfoPlist.strings中使用它,以便在CameraUsageDescription和其他描述中使用目标名称。

我该如何在字符串中使用它?

类似这样:

/* Localized versions of Info.plist keys */

"NSLocationWhenInUseUsageDescription" = "Allows geolocation to send your location in the chat or know which institutions and services are near you";
"NSContactsUsageDescription" = "To be able to talk with the contacts who have ${PRODUCT_NAME} we need to access your agenda";
"NSPhotoLibraryUsageDescription" = 'Allows ${PRODUCT_NAME} to access the gallery to be able to send photos through the chat';
"NSCameraUsageDescription" = "Allows access to the camera to make a photo and send it";
"NSContactsUsageDescription" = "To be able to talk with the contacts who have ${PRODUCT_NAME} we need to access your agenda";
"NSPhotoLibraryAddUsageDescription" = "Allows access to save the images received by the chat";
1个回答

0

您可以在info.plist中使用$(PRODUCT_NAME)来引用应用程序名称。

例如:“$(PRODUCT_NAME)需要相机权限。

它将显示为“YourAppName需要相机权限。


我正在使用InfoPlist.strings,所以这个方法的响应(我昨天已经检查过了)是:“$(PRODUCT_NAME)允许地理定位在聊天中发送您的位置或了解附近的机构和服务”。 - Javier Torron Diaz
抱歉,我没有解释清楚。那个方法不起作用,因为模态框要求授权时不显示PRODUCT_NAME的值,而是直接显示$(PRODUCT_NAME)。问题还未解决。我的意思是,使用这个公式时,$(PRODUCT_NAME)没有被翻译成它的值。 - Javier Torron Diaz
我创建了一个示例应用程序,以展示如何使用.plist文件进行本地化。我已将.plist本地化为法语和英语。测试用例:将设备语言更改为法语或英语,并运行示例项目。PS:每次运行应用程序时,您需要卸载它,因为权限弹出窗口只会出现一次。示例应用程序链接:https://files.fm/u/7fw3zwf9如果我以任何方式帮助到您,请点赞。谢谢 :) - Bikramjeet Singh
我已经测试过了,它确实可以工作,但不是我要求的。你使用了正确的 info.plist 文件进行本地化处理,但在我的项目中,我有本地化处理的 InfoPlist.strings 文件。在这个 InfoPlist.strings 文件中,代码 $(PROCUDT_NAME) 被显示为一个字面字符串。 - Javier Torron Diaz
当然,我会告诉你。非常感谢。 - Javier Torron Diaz
显示剩余6条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接