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.
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.
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,
You should be able to see the file also on the 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!
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.
Step by step localize Info.plist:
Find in the Xcode the folder Resources (is placed in root)
Select the folder Resources
Then press the main menu File->New->File...
Select in section "Resource" Strings File and press Next
Then in Save As field write InfoPlist ONLY ("I" (eye) capital and "P" capital - the l (ell) after the P should not be capital)
Then press Create
Then select the file InfoPlist.strings that created in Resources folder and press in the right menu the button "Localize"
Then you Select the Project from the Project Navigator and select the The project from project list
In the info tab at the bottom you can as many as language you want (There is in section Localizations)
The language you can see in Resources Folder
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
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!
Tips
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.
The localisation string (see Apple docs here) should be
NSLocationWhenInUseUsageDescription = "Description of this";
and not (with quote "...")
"NSLocationWhenInUseUsageDescription" = "Description of this";
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.
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 project, 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.
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.
For newer XCode 12 / 13 /...
1. Create a new InfoPlist.string file in your project.
2. Select your file, and you should see the right sidebar option "Localize"
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.
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.
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:
Also, check the project.pbxproj file, it is in XXX.xcodeproj/project.pbxproj:
it should have all your languages in codes (en, fr, etc.)
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.
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.
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
) 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
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.
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.
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";
Currently I have a project with a lot of targets and each of them has its own "info.plist" file with its own name specified in settings:
Build Settings >> Packaging >> Info.plist File
Yes, I have read some topics similar to this one. It works when I have "Info.plist" file with this exact name (of course, I can't have ~10 files with the same name due to some reasons).
How to solve this issue?
I faced the same issue today and it took me almost a whole day to fix it. I read a lot of questions related to this on stackoverflow and found out that whatever name you give your Info.Plist file (lets say InfoTarget1.plist), when it's built, it is converted to standard "Info.plist" inside product.
Surprisingly, this doesn't happen for the corresponding InfoPlist.strings file (with custom name, lets say, InfoTarget1Plist.strings).
Work around for it is to create a single InfoPlist.strings and localize it for the required languages. This worked for me since I only wanted to localize 'NSLocationAlwaysUsageDescription' for all targets.
Hence, if you only have common fields from among your plist files that you want localize, you can follow the same approach as below:
Create a new InfoPlist.strings file in your folder where .plist are saved.
Add the key-value pairs to localize.
Localize this file from File Inspector on right side in your xcode.
It will ask you to move your current InfoPlist.strings file, select 'Base' from the drop down.
Select other languages you want to localize in from the File Inspector, assuming you have already added those languages in localization for your project from Info tab.
Update the localized values in corresponding files.
Clean and Run your app. This should do it!
Problem
I cannot figure out how to localize the NSLocationWhenInUseUsageDescription key. During export of the base language XLIFF file, Xcode automatically includes CFBundleDisplayName, CFBundleName, CFBundleShortVersionString, and NSHumanReadableCopyright. How can I include additional Info.plist keys? When I try to edit the strings files directly, the added keys are not included in future XLIFF exports.
Background
I am using the new base internationalization and localization tools in Xcode 6. With it, you no longer create or edit .strings files. Rather, choose "Export for Localization" from the "Editor" menu. Xcode will create an XLIFF file with strings from all nibs, code, and Info.plist. You then import a translated XLIFF, which then creates all strings files automatically, including InfoPlist.strings. See Localizing Your App from Apple's documentation.
You need to manually create an InfoPlist.strings file, and add it to the en.lproj folder in the project directory in the Finder. Then drag it into the Xcode project with the other InfoPlist.strings files without copying it.
Please Note:
The InfoPlist.strings file will need to include the default keys and the keys you wish to add.
The file should NOT be added to base.lproj. This is reserved only for xib and storyboard related files.
I am trying to understand Base.lproj but I am not still understanding it. If I create a new simple project with a view controller and Swift+Storyboard in XCode 6 beta 4 I get a Base.lproj folder out of the box containing the storyboard file.
I then add a simpel NSLocalizedString(...) in my view controller for testing purposes. This requires a Localizable.strings file. When I create one should I add it in the Base.lproj or should I add it in a specific language folder?
If I change the Localization native development region key in Info.plist to de for german and I no Localizable.strings file for de in the de.lproj folder it seems to fallback on Base.lproj if Localizable.strings file is found there. However, if I add a Localizable.strings file in the de.lproj folder but don't add the property (key + value) the app fails during runtime. It seems like Base.lproj isn't searched.
I don't understand which language Base is and when it is used? Is it only for Storyboard files?
I was under the impression that base.lproj is used in cases where the current language/ localisation file does not have a property key. For instance if I do have Main_Title = "Title Text"; in base.lproj and absent in en.lproj while the current language is English, I assumed iOS will find it in base.lproj but that is not the case.
Your initial conclusion is correct:
Base is only used when you did not support that language in localizable.strings
The specific language localizable.strings folder is used when device/ app is using that language
If you do not provide support for a specific file/ string key in a language and you have a folder for that language, it will throw run-time warning
In case of storyboard files and xibs if you only have base.lproj folder which contains your views, notwithstanding how many languages you support, it will not fail (this is what I am doing as well).
Only one Resource file is displaying When i'm adding Localizable.strings file for any language. My steps are,
Selected My main app's project file in xcode and found info option is there
in info - Localization - + option
Note: there is only one resource file (InfoPlist.strings) is available to add Language.
3- then Finish, but there is no Localizable.strings file is displaying in xcode but there is InfoPlist.strings file displaying.
But if i do these same steps in sample app which is working fine , I can able to select Multiple resource files And also I can see many Localizable.strings & InfoPlist.strings
in xcode.
Like:
Localizable.strings (English)
Localizable.strings (Spanish)
InfoPlist.Strings (English)
InfoPlist.Strings (Spanish)
Can anyone please tell me the solution to add multiple resource files when localizing any language?
If you want to make your app to support multiple languages, then you'll need to add .strings files to your project, make sure that you should name it "Localizable.strings" only, and need to put in particular language folder,
See this question and my answer there,
Localized filename should always be named Localizable.strings, and that file is within the particular language folder, for English, en.lproj and for French fr.lproj like wise.
Localizable.strings file should be inside the Base.lproj folder.