364

As you might know the iOS 8 requires NSLocationWhenInUseUsageDescription key for using user's location. I have added this key and some general information into my info plist. enter image description here

How can I use translation string inside the plist file ?

-- Update --

I already have a Localizable string. I'm just wondering that can I use something like NSLocalizedString(MYSTRING,nil) inside the plist string. I know that I can create multiple file of info.plist for localisation but I was wondering there might be an easier way.

King-Wizard
  • 15,628
  • 6
  • 82
  • 76
Soheil
  • 5,054
  • 3
  • 24
  • 43

15 Answers15

676

You should use InfoPlist.strings file (keep both I & P capital) to localize values of Info.plist. To do this, go to File->New->File, choose Strings File under Resource tab of iOS, name it InfoPlist, and create. Open and insert the Info.plist values you want to localize like:

"NSLocationWhenInUseUsageDescription" = "Description of this";

Now you can localize InfoPlist.strings file with translations.

Select the localization options, or enable localization if needed,

right side editor

You should be able to see the file also on the left side editor.

left side editor

NOTE: When testing the localizations on the simulator. You have to change the language on the simulator itself not just the language in the Xcode target. (Credits to John Webb)

Here is the official documentation for Info.plist keys localization.

Credits to Marco, thanks for including the pics in this answer!

Raphaël Balet
  • 6,334
  • 6
  • 41
  • 78
Fahri Azimov
  • 11,470
  • 2
  • 21
  • 29
  • 5
    Works. Don't forget to clean the project first, and make sure it's a freshly installed build on your iDevcie or reset the content on the simulator. – Raz Sep 21 '14 at 20:40
  • Plus for a comprehensive answer with graphics. – Johan Karlsson Feb 23 '15 at 14:27
  • 34
    After creating the strings file, do you need to include the key in the Info.plist file as well, or is it safe to delete from there? – rounak Mar 23 '15 at 17:50
  • @rounak I'm not totally sure, but I think, you should keep it in the plist file as well. Anyways, you can make an experiment :). – Fahri Azimov Mar 24 '15 at 05:17
  • 4
    After creating InfoPlist.strings file and adding it to the project, I made a mistake by selecting the localization options of Info.plist. Instead, we should localize the "InfoPlist.strings" file. (They are different files) – Jakehao Apr 20 '15 at 07:44
  • 24
    Tip: Use exactly the name "InfoPlist.strings" and nothing else. For example my original infoplist file was named something else but I needed to use this name exactly in order to get it to work. – Sjoerd Perfors Sep 08 '15 at 10:48
  • 37
    When testing the localizations on the simulator. I had to change the language on the simulator itself not just the language in the xcode target. Just a warning for anyone else. – John Webb Sep 23 '15 at 10:35
  • 4
    Note that the string on the left needs to be exactly as shown in this answer, and NOT the base language version of the description. – Nestor Oct 07 '15 at 13:39
  • 6
    Note that the filename InfoPlist.strings is **case-sensitive**. I lost 2 hours debugging the mistake that someone had named it infoPlist.strings (missing the capital 'I') – xaphod Mar 07 '16 at 18:40
  • What if there is another plist file with name test.plist, and what shall I create for it ? testPlist.strings ?@FahriAzimov – Teja Nandamuri Mar 24 '16 at 17:52
  • 2
    @TejaNandamuri, no, you can just localize that file by selecting, and going to File Inspector->Localization, pressing 'Localize' button, and selecting right localization. – Fahri Azimov Mar 25 '16 at 04:36
  • 2
    Notice that Info.plist is translated by properties keyex.: `NSLocationWhenInUseUsageDescription" = "Your text";` or `"CFBundleDisplayName" = "An app name";` – akaDuality Oct 08 '16 at 08:13
  • 9
    To answer a previous comment, you should keep the keys/values in the actual plist file. If a corresponding value is found in a localized version of InfoPlist.strings, that value will be used instead. If certain keys aren't in the actual Info.plist file itself, iTunes Connect will trigger warnings when you submit your app. – djibouti33 Dec 07 '16 at 19:04
  • 15
    the correct usage is keyname = "your text"; e.g: NSLocationWhenInUseUsageDescription = "your text" – Magurizio Mar 16 '17 at 14:05
  • 21
    Caution: the key in this file should not have quotation mark, which is different with the normal localization. e.g: NSMicrophoneUsageDescription = "your description"; – Yuchao Zhou Apr 11 '17 at 22:01
  • So weird that this works, and yet Xcode does the wrong thing when you try to localize your Info.plist. Thanks for this answer, saved me a ton of time – johnnyclem May 05 '17 at 16:03
  • 1
    Here's the part from Apple: https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html – bauerMusic Jun 13 '17 at 07:22
  • That works well, I have couple of targets and each of them has different property file with different messages so how do I handle that? – Anirudha Mahale Dec 01 '17 at 13:22
  • Create separate .strings files for each target. – Fahri Azimov Dec 01 '17 at 16:41
  • 5
    After spending 30 minutes on this, what you need to add to that `InfoPlist.strings` as the KEY (value on the left) is the KEY of that permission, which is ALWAYS the permission name (e.g. NSPhotoLibraryAddUsageDescription), and NOT the value you put in that info plist. – jomafer Feb 11 '18 at 13:58
  • 1
    Don't forget the semi-colon at the end of each line. Otherwise build fails with "Couldn't parse property list because the input data was in an invalid format" error. – changingrainbows Sep 01 '19 at 04:34
  • @changingrainbows Yes, that's the localizable string making basics. – Fahri Azimov Sep 02 '19 at 01:24
  • I am using xcode10.1, I am unable to find those Localization checkboxes for multiple languages you have in your screenshot, please tell me are they removed in this version of xcode? Also I am confused how app will differentiate which value to use for which localized language – Muhammad Awais Sep 17 '19 at 07:25
  • Make sure your string file for the base language is located in the Base.lproj folder, and the various alternative localization string files are located in the various xx.lproj folders. – Giorgio Barchiesi Oct 06 '19 at 07:26
  • If you failed to make this work, remember to check the `;` at the end of the line. – kkpattern Oct 29 '19 at 07:24
  • Can I use the Localizable.strings file I already have in my project of does it necessarily need to be name infoPlist.strings ? – Cublax Oct 29 '20 at 11:01
  • @SjoerdPerfors, yes, thank you, it needs to be exactly "InfoPlist.strings". But what if I have more than a target? – Frade Mar 11 '21 at 12:33
  • This is the perfect solution...It's working in xcode 12.4 and ios 14.6. Thank you. – Naresh Jul 26 '21 at 09:34
43

All the above did not work for me (XCode 7.3) so I read Apple reference on how to do, and it is much simpler than described above. According to Apple:

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.

Accordingly, I created a string file named InfoPlist.strings and placed it in the xx.lproj folder of the "xx" language (and added it to the project using File->Add Files to ...). That's it. No need for the key "Localized resources can be mixed" = YES, and no need for InfoPlist.strings in base.lproj or en.lproj.

The application uses the Info.plist key-value as the default value if it can not find a key in the language specific file. Thus, I put my English value in the Info.plist file and the translated one in the language specific file, tested and everything works.

In particular, there is no need to localize the InfoPlist.strings (which creates a version of the file in the base.lproj, en.lroj, and xx.lproj), and in my case going that way did not work.

hyde
  • 60,639
  • 21
  • 115
  • 176
Zvi
  • 2,354
  • 2
  • 26
  • 37
  • 2
    Why did't include the link to appropriate document? – Jurasic Sep 18 '17 at 07:28
  • 4
    Here the link to Apple doc's relevant page in case anyone is interested: https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html – bend Jul 16 '19 at 07:08
  • and how we decide that xx? for example for english it can be en, En, Eng, English etc? Sorry if its a stupid question because I am a beginner – Muhammad Awais Sep 17 '19 at 07:41
  • Your answer worked for me except the fallback language scenario, app is getting fallback language always the previously used language and not english, my english value is present in Info.plist file though, also I have tried base.lproj as well – Muhammad Awais Sep 17 '19 at 08:24
43

Step by step localize Info.plist:

  1. Find in the Xcode the folder Resources (is placed in root)
  2. Select the folder Resources
  3. Then press the main menu File->New->File...
  4. Select in section "Resource" Strings File and press Next
  5. Then in Save As field write InfoPlist ONLY ("I" (eye) capital and "P" capital - the l (ell) after the P should not be capital)
  6. Then press Create
  7. Then select the file InfoPlist.strings that created in Resources folder and press in the right menu the button "Localize"
  8. Then you Select the Project from the Project Navigator and select the The project from project list
  9. In the info tab at the bottom you can as many as language you want (There is in section Localizations)
  10. The language you can see in Resources Folder
  11. To localize the values ("key") from info.plist file you can open with a text editor and get all the keys you want to localize
  12. You write any key as the example in any InfoPlist.strings like the above example

"NSLocationAlwaysAndWhenInUseUsageDescription"="blabla";

"NSLocationAlwaysUsageDescription"="blabla2";

That's all work and you have localize your info.plist file!

Andy Weinstein
  • 2,639
  • 3
  • 21
  • 32
Costas Bakoulias
  • 895
  • 9
  • 11
36

Tips

  1. Remember that the iOS Simulator exploits by default your system language. Please change the language (and region) in the iOS Simulator Setting too in order to test your translations.

  2. The localisation string (see Apple docs here) should be

    NSLocationWhenInUseUsageDescription = "Description of this";
    

    and not (with quote "...")

    "NSLocationWhenInUseUsageDescription" = "Description of this";
    
24

For newer XCode 12 / 13 /...

1. Create a new InfoPlist.string file in your project.

Select your project, click with the right button and select New File

Select the type of file 'Strings File'

Name it 'InfoPlist' and create it

2. Select your file, and you should see the right sidebar option "Localize"

Select Localize in the right sidebar

Done.

3. If you want add more languages in your project's Info >> Localizations

It will create automatically a copy of your "InfoPlist.string" for the new languages you add.

Add more languages to your project.

ofundefined
  • 2,692
  • 2
  • 18
  • 35
23

If something is not working make sure you added:

"Localized resources can be mixed" = YES

into the info.plist. In my case the InfoPlist.strings files were just ignored.

Alex Zavatone
  • 4,106
  • 36
  • 54
tuvok
  • 679
  • 5
  • 16
14

I would highly recommend reading Apple's guides, and viewing the WWDC resources listed here: Internationalization and Localization Topics

To specifically answer your question, when you add a new language to your projectenter image description here, you get an opportunity to choose what InfoPlist files to include (if you have multiple targets, you'll have multiple Info plist files). All you need to do to get the following screen is hit the + under Localizations and choose a new language to add support for. enter image description here

Once you've added, it will create the necessary string files in the appropriate lproj directories for the given language.

--EDIT--

Just to be clear, iOS will swap out the string for your Plist file based upon the user's currently selected language using the plist entry's key as the key in the localized strings file.

Matt S.
  • 1,882
  • 13
  • 17
  • 3
    Translating the entire plist for just one key is an overkill. Find more info here: bit.ly/1yBUTru – RGML Dec 01 '14 at 16:11
  • 2
    It simply does not true for XCode 9. It nevers asks for plist localization when adding a new language. – Tom Oct 12 '17 at 13:00
  • I will need to look into that for Xcode 9 - have not had a chance to test in the new Xcode yet. – Matt S. Oct 13 '17 at 17:33
9

In addition to the accepted answer (the project is on Flutter but it's basically the same as native):

I do have folders Base.lproj, en.lproj, xx.kproj. etc. with InfoPlist.strings in each. This file has lines like this (no quotes around the key and with a semicolon at the end):

NSLocationWhenInUseUsageDescription = "My explanation why I need this";

Check that you have your languages in your YourProject > Info: enter image description here

Also, check the project.pbxproj file, it is in XXX.xcodeproj/project.pbxproj: it should have all your languages in codes (en, fr, etc.)

enter image description here

But even then it didn't work. Finally, I noticed the CFBundleLocalizations key in the Info.plist file. (to open it as raw key-values in XCode - right mouse button on the Info.plist file -> Open As -> Source Code) Make sure that the values in array are codes rather than complete words, for example fr instead of French etc.

<key>CFBundleLocalizations</key>
<array>
    <string>en</string>
    <string>ru</string>
    <string>lv</string>
</array>

And double-check that your device is set to the language you're testing. Cheers

P.S. "Development Language" doesn't affect your issue, don't bother changing it.

Kirill Karmazin
  • 6,256
  • 2
  • 54
  • 42
  • 1
    "no quotes around the key and with a semicolon at the end" - Xcode 12.0.1 - Actually, it works fine even if keys have quotes. – Legonaftik Dec 18 '20 at 15:44
7

For anyone experiencing the problem of the info.plist not being included when trying to add localizations, like in Xcode 9.

You need make the info.plist localiazble by going into it and clicking on the localize button in the file inspector, as shown below.

The info.plist will then be included in the file resources for when you go to add new Localizations.

enter image description here

Edward
  • 2,864
  • 2
  • 29
  • 39
  • 4
    Did you encounter any problems? I can't build project when I add two languages to Localization since xcode is saying "The file info.plist couldn't be opened because there is no such file. – mkkrolik Apr 25 '18 at 13:53
  • 3
    @mkkrolik I'm having the same issue now. Have you found a solution? – Todanley May 01 '18 at 05:29
  • @Todanley skip this solution it doesn't work for me. Use InfoPlist.strings instead. – mkkrolik May 01 '18 at 09:06
  • @mkkrolik Thank you that works. And also when testing with simulator, I had to change the language setting of simulator rather than that of my target for it to work. – Todanley May 01 '18 at 22:32
3

As RGML say, you can create an InfoPlist.strings, localize it then add your key and the value like this: "NSLocationWhenInUseUsageDescription" = "Help To locate me!";

It will add the key to your info.plist for the specified language.

Cap
  • 2,004
  • 16
  • 17
2

In my case everything was set up correctly but still the InfoPlist.strings file was not found.

The only thing that really worked was, to remove and add the InfoPlist.strings files again to the project.

d.ennis
  • 3,445
  • 2
  • 28
  • 36
2

When using InfoPlist.strings file (in XCode it should be placed next to Info.plist file - real file location can be anywhere within the project probably

View in XCode

) be careful to use the key's short name for the translation.

I was trying to use Privacy - Camera Usage Description, but the working key is NSCameraUsageDescription

Hourglasser
  • 667
  • 1
  • 9
  • 17
2

You can use string catalog from,

Xcode 15 +

Simply create a String catalog file named InfoPlist.

enter image description here

enter image description here

enter image description here

enter image description here

YodagamaHeshan
  • 4,996
  • 2
  • 26
  • 36
1

In my case the localization not worked cause of '-' symbol in the name. Example: "aero-Info.plist" And localized files: "aero-InfoPlist.strings" and "aeroInfoPlist.strings" did not work.

Mike Glukhov
  • 1,758
  • 19
  • 18
0

iOS localize .plist

You can skip defining key into .plist if you set it in InfoPlist.string

.plist

InfoPlist.string

"NSPhotoLibraryAddUsageDescription" = "You need to allow access to the photo library to download image";
yoAlex5
  • 29,217
  • 8
  • 193
  • 205
  • This is wrong. The file must be named "InfoPlist.strings", also the description `To download image` will be too short. Apple wants a very descriptive sentence here. – FrugalResolution Feb 11 '23 at 01:28