Can't localize info.plist strings

浪子不回头ぞ 提交于 2020-01-03 07:08:06

问题


I need to localize two keys of info.plist: NSLocationUsageDescription and NSCameraUsageDescription. So I tried to create a new file called InfoPlist.strings and then I localized it, but app always shows strings stored in info.plist file. What's wrong?

Official documentation from Information Property List Key Reference

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.

My InfoPlist.strings file:

NSCameraUsageDescription = "hello";
NSLocationUsageDescription = "hello hello";

回答1:


Please check in the generated application package, whether the file is really stored in there and it is put to the correct location. Usually this is the missing step.

Just go into the project settings, open "Build Phases" and see whether the file can be found in "Copy Bundle Resources"




回答2:


Your plist file can have multiple versions for each language your application supports. In Utilities \ File Inspector (on the right) click on "Localize":

And then choose the languages you want to have their own versions:

After that you will be able to enter each plist file and edit it as you want.




回答3:


Sometimes you have to make a Clean first, Click Menu -> Product -> Clean.




回答4:


InfoPlist.strings doesn't consider your scheme's Application Region, but the region set in the device! On your device: Settings-> General -> Language & Region, check if iPhone Language is the one that you like.




回答5:


As a matter of fact, my problem was that I had misspelled the NSLocationWhenInUseUsageDescription constant so of course it was not taken into account.




回答6:


Since iOS 10, you are required to add the privacy keys to your Info.plist.

<key>NSPhotoLibraryUsageDescription</key>
<string>Please allow access to the photo library.</string>

Of course, you still need those keys to be localized (and you can't localize the application's Info.plist). So you ALSO add those privacy keys to the InfoPlist.strings, which in turn are localized.

"NSPhotoLibraryUsageDescription" = "Please allow access to the photo library.";



回答7:


The file needs to be inside of a directory indicating the language, for example en.lproj



来源:https://stackoverflow.com/questions/21735999/cant-localize-info-plist-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!