Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to localise a string inside the iOS info.plist file?

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.

like image 818
Soheil Avatar asked Sep 09 '14 04:09

Soheil


People also ask

How do I edit info plist files?

All you have to do is click on the blue project icon -on top of the left- and go to the “Build Settings” tab, search “Info. plist” and choose “Info. plist File” section. Then change the information of the section from your folder's name.

How do I Localise my iOS app?

Go to the File menu and choose New > File, then select Strings File from the list of file types and click Next. Give this file the name “Localizable. strings”, then click Create to open it for editing.

What is localization string?

A localized string can have different values depending on the language in which the project is being build. There are two categories of localized strings: the strings included in the installation package's UI, common to every MSI file.

How to localize string files in iOS devices?

You should use InfoPlist.stringsfile to localize values of Info.plist. To do this, go to File->New->File, choose Strings Fileunder Resourcetab of iOS, name it InfoPlist, and create. Open and insert the Info.plistvalues you want to localize like: NSLocationWhenInUseUsageDescription = "Description of this";

How to localize a plist in Xcode 9?

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.

How to localize values in infoplist on iOS devices?

You should use InfoPlist.strings file 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";

How to enable plist key localization?

Select the localization options, or enable localization if needed, You should be able to see the file also on the left side editor. Hereis the official documentation for Info.plistkeys localization. Creditsto Marco, thanks for including the pics in this answer!


2 Answers

You should use InfoPlist.strings file 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

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

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

like image 126
Fahri Azimov Avatar answered Oct 13 '22 00:10

Fahri Azimov


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.

like image 36
Zvi Avatar answered Oct 12 '22 23:10

Zvi