简体   繁体   English

在iOS上以编程方式本地化info.plist

[英]programmatically localize info.plist on iOS

I am facing a problem with a specific translation issue on iOS. 我在iOS上遇到特定翻译问题。 The app I am currently working on gets all the texts it displays from a web service. 我当前正在使用的应用程序将从Web服务获取其显示的所有文本。 I have been able to implement this everywhere with one single exception: 我已经能够在任何地方实现这一点,只有一个例外:

I have not yet found a way to programmatically alter texts from info.plist which get used from the system in code I cannot control. 我尚未找到一种方法来以编程方式更改info.plist中的文本,这些文本已在系统无法控制的代码中被系统使用。 The one I need to deal with is "Privacy - Camera Usage Description". 我需要处理的是“隐私-相机使用说明”。 So far any documentation I have found tells me to add localized text versions for info.plist - but in this particular case this won't help me, because different customers may specify different texts for the same language, and I sometimes do not even know what language the texts are in, so I cannot solely rely on static data in the app to select the proper text version. 到目前为止,我发现的所有文档都告诉我要为info.plist添加本地化的文本版本-但在这种情况下,这对我无济于事,因为不同的客户可能会为同一语言指定不同的文本,而我有时甚至不知道文字使用哪种语言,因此我不能仅依靠应用程序中的静态数据来选择正确的文字版本。

Is there any way to set such a text programmatically, or if that isn't possible to catch the alert displaying it and replace it with one of my own? 有什么方法可以通过编程方式设置这样的文本,或者如果无法捕获显示它的警报并将其替换为我自己的文本呢?

No, It's not possible, we can not change Info.plist runtime. 不,不可能,我们不能更改Info.plist运行时。 But if I was there in place of you I will do one thing as a solution. 但是,如果我在那里代替您,我会做一件事作为解决方案。 Display a custom alertview with your specified text from the api. 使用api中指定的文本显示自定义的alertview。 Which will ask that "We will use your camera". 它将询问“我们将使用您的相机”。 If user says "Ok" than display the system's alertview for the permission with static localized string. 如果用户说“确定”,则使用静态本地化字符串显示系统的警报视图以获取许可。 It needs 2 time interaction but it can guide user thoroughly. 它需要2次互动,但可以彻底指导用户。

You can localize info.plist file itself. 您可以本地化info.plist文件本身。 from project, go to your info.plist file and open Utilities tab and hit on Localization. 从项目中,转到您的info.plist文件,然后打开“实用工具”选项卡,然后单击“本地化”。 For different Localizations, use different Strings on specified keys. 对于不同的本地化版本,请在指定键上使用不同的字符串。

Note 注意

I Haven't tried it myself, just checked to see if it can be localized. 我自己还没有尝试过,只是检查它是否可以本地化。 and one more thing, using this way, Application will use Device's Localization (You can't use libraries to swizzle String table your app uses) 还有另一件事,通过这种方式,应用程序将使用设备的本地化(您不能使用库来混淆应用程序使用的String表)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM