42

Faced interesting thing while preparing app for iOS 10. Starting from Xcode 8 you must provide description about any permission you ask in the app (https://forums.developer.apple.com/thread/49951)

Everything seems good, but what if I want localize this descriptions?

If I would place it inside InfoPlist.strings - app will continue crashing. But if I would place it in InfoPlist.strings and Info.plist - app would always take description from Info.plist, so there won't be any localization.

Maybe someone have a solution. Thanks :)

Cœur
  • 37,241
  • 25
  • 195
  • 267
Alexander Zimin
  • 1,700
  • 1
  • 15
  • 19
  • 1
    Checked it on device & simulator (Xcode 8 beta 5, iOS 10 beta 5) with `NSCameraUsageDescription` / `NSPhotoLibraryUsageDescription` - works as expected with placing strings only inside of `InfoPlist.strings`. Which usage description are you trying to localize? – Roman Ermolov Aug 15 '16 at 19:09
  • 1
    It seems that the problem in quotes around the key. Try `NSPhotoLibraryUsageDescription = "Value";` – Roman Ermolov Aug 16 '16 at 08:30
  • @RomanErmolov problem in video was about copying key from stackoverflow (there was strange symbol between key prefix and description), so it works now. Checking my key – Alexander Zimin Aug 16 '16 at 08:32
  • @RomanErmolov checked with Xcode 8 beta 6 in fresh project, everything work fine. Can't launch working project right now, but if there will be a problem, it would relate to this project itself. Thank you for the help! – Alexander Zimin Aug 16 '16 at 11:57
  • the localization strings work well on iOS11, but not on iOS10. don't know why – DàChún Jan 24 '18 at 18:25

4 Answers4

51

I faced the same issue and I was able to resolve it because I noticed that the InfoPlist.strings wasn't member of any target.

So setting the Target Membership on the file (which puts it into the Copy Bundle Resources build phase) fixed it.


And for anyone googling here: https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html

Scroll down to "Localizing Property List Values"

Fattie
  • 27,874
  • 70
  • 431
  • 719
Martin Polak
  • 1,228
  • 1
  • 12
  • 16
  • thanks for that Martin - so, after I set `Target Membership`, indeed it then allows localization of the whole plist file ?? cheers... – Fattie Oct 03 '16 at 20:59
  • 2
    Yes, you can put any `"key" = "string";` into the `InfoPlist.strings` of the respective language and it will be used instead of the value provided in the `Info.plist`. I suggest putting a default value in the `Info.plist` anyway even though from my experiment it was not necessary to put the key in the plist itself. Also the name of `InfoPlist.strings` is crucial as indicate the comments in this answer: http://stackoverflow.com/questions/25736700/how-to-localise-a-string-inside-the-ios-info-plist-file . – Martin Polak Oct 04 '16 at 08:35
  • 1
    Same problem, but my Info.strings files were already added to the target. Nevertheless, the text in the Info.plist was output. – Reinhard Männer Oct 07 '16 at 13:01
  • 1
    @ReinhardMänner I suggest you double check the naming of the strings file and the name of the keys you are trying to localize. – Martin Polak Oct 08 '16 at 16:24
  • @Martin Polak thank you! I made the crazy error to name these files "Info.strings" since the unlocalized version is named "Info.plist". After renaming them to "InfoPlist.strings" everything works as expected. – Reinhard Männer Oct 09 '16 at 10:56
  • 2
    Please note that doc state that key should not be double quoted... `NSLocationWhenInUseUsageDescription = "xxx";` vs `"NSLocationWhenInUseUsageDescription" = "xxx";`. i.e.: https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html – Hugues BR Jan 18 '17 at 12:34
  • 1
    Also, changing language using specific `scheme` doesn't seem to work correctly for `Info.plist` localization, you need to manually set the simulator language to see the localized text. – Hugues BR Jan 18 '17 at 12:36
  • its not working, if I use this: NSLocalizedString(@"NSCameraUsageDescription",nil). It should work this way? Although OS is picking the right localization when it asks for permissions. But if I want to display this text somewhere, all I see is "NSCameraUsageDescription" – nr5 Jun 26 '17 at 14:09
10

Here are the steps for localizing info.plist variables

  1. create a new file named "InfoPlist.strings" under your project .string

  2. click on your project to open settings (if target is your app, select project by just clicking it in opened window) add any necessary languages under "localizations"

  3. go to your InfoPlist.strings file and mark checkbox of desired languages under localizations. (Press "utilities" button unless localizations is not visible after clicking on .strings file, which is at the top right corner of xcode - the rightmost one) localize

  4. add necessary "key" = "value" pairs for all localization languages in InfoPlist.strings. If you have difficulties in finding keys belonging to info.plist rows, just right click on your info.plist and select Open As -> Source Code, all row parameters are indicated as keys in source code

Mamad Farrahi
  • 394
  • 1
  • 5
  • 20
brsr
  • 111
  • 2
  • 3
9

enter image description here

enter image description here

Steps to Implement the localization for Permission.

Step 1 - Click the Info.plist

Step 2 - Click the Localize button [Xcode right middle]

Step 3 - Tick the languages

Gomino
  • 12,127
  • 4
  • 40
  • 49
Faizal Malik
  • 197
  • 3
  • 11
3

I had a similar issue, it was caused by using the wrong file name:

InfoPList.strings

instead of

InfoPlist.strings

Hope this info might be of useful for someone.

AamirR
  • 11,672
  • 4
  • 59
  • 73