Can you localized NSAppleMusicUsageDescription? [duplicate] - ios

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";

Related

How to localize Info.plist content in Visual Studio

I have a Xamarin iOS application that supports 4 different languages ​​at the moment. However
I would now like to be able to translate the contents of my info.plist file and its keys like NSCameraUsageDescription so that its
values ​​can be translated as well.
I have done quite a lot of research so far and by searching through the documentation it is advisable to create an InfoPlist.strings file which would contain
my key NSCameraUsageDescription = "the content here".
There would be an InfoPlist.strings file for each language and this would be contained in a folder fr.lproj, es.lproj etc following the language.
I think that it is relatively well explained to exploit this option in Xcode with the possibility to create .strings files and to localize them directly.
However, on Visual Studio I have some difficulties to introduce and adapt my files. The equivalent of a .strings file on Xcode is a .resx file on VS ?
How can the relationship between my InfoPlist.strings and my main Info.plist file be in order to tell my application to tap in the folder fr.lproj / InfoPlist.strings when I switch to french for instance.
Am I supposed to create one folder for each language named fr.lproj where I put a single file InfoPlist.strings or InfoPlist.resx with my keys ?
However, on Visual Studio I have some difficulties to introduce and
adapt my files. The equivalent of a .strings file on Xcode is a .resx
file on VS ?
No, to create a .strings file in visual studio, you should choose add -> new item -> Text File, then change the file name With xxx.strings.
How can the relationship between my InfoPlist.strings and my main
Info.plist file be in order to tell my application to tap in the
folder fr.lproj / InfoPlist.strings when I switch to french for
instance.
If you created the InfoPlist.strings for each language, it will automatically read the configuration in the file of the Corresponding language, and then show the right language. If the key was not find on the InfoPlist.strings, it will use the default value in main Info.plist.
Am I supposed to create one folder for each language named fr.lproj
where I put a single file InfoPlist.strings or InfoPlist.resx with my
keys ?
Yes, if you have four language to support, you should create 3 xx.lporj folders(another is Base.lporj) and each contains an InfoPlist.strings and Localizable.strings.
In your InfoPlist.strings file, set the key NSCameraUsageDescription = "the content here" and ect....
Read the document may help.
Here is what I just created in my project:

How to Localize Location Permission Dialog alert? [duplicate]

I've completed translating my app to Turkish using Base Localization. However, I also need to translate NSLocationWhenInUseUsageDescription key in my Info.plist file. I did exactly what I did for everything else:
Went to File inspector and checked Turkish:
Then I went to the new strings resource and completed my translation by adding this key to the localization file:
"NSLocationWhenInUseUsageDescription" = "[my Turkish description of location permissions]";
Saved, compiled, even deleted app from device and rebuilt, but no avail. When my app asks for location permissions, the explanation underneath is still the English one (I've tried including the English translation as well under Base translation file, but it didn't change anything).
Everything else is Turkish, translated just fine. It's just the location permission that doesn't translate. I've also seen How to localise a string inside the iOS info.plist file? and added the "Localized resources can be mixed" = YES key (of course, as CFBundleAllowMixedLocalizations, not literally that sentence) to my original plist but that also didn't change anything.
How can I solve the problem?
Here's what ended up working for me in Xcode 7.1.
First, go to project directory and manually create two InfoPlist.strings files, the first inside the en.lproj folder and the second inside the fr.lproj folder.
Both files should have the following content :
NSLocationWhenInUseUsageDescription = "YOUR TEXT HERE";
Since the files won't show up automatically in Xcode, you have to manually add both to the project bundle, this can be achieve via right-clicking the project name in Xcode and choosing the Add files to X option, then selecting the files you just created.
Also if you want to test the result & make sure things work, changing the Application Language in Edit Scheme > Run > Options isn't enough.
You need to change the simulator or the device language via Settings > General > Language & Region > iPhone Language
I've started over. Removed the translations, cleaned the project, and tried again. It worked. I have no idea why it didn't initially though.
My problem seems to be case sensitive:
My InfoPlist.strings had a lower "i" in finder and Xcode (infoPlist), but needs to be upper.
I changed file name and reference in the source Xcode Project and it works
(or deleted and re-create with the right name).

Localize info.plist file which has a different name?

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!

Xcode - Changing Bundle Display Name By Language

I want my app name to be localized(English and Simplified Chinese). I localize the Info.plist in my project and added Simplified Chinese. So I have two Info.plist files now. Error occured when I build the project. "Info.plist could not be found". So I edited the path of Info.plist at Build Settings > Packaging > Info.plist File Path. Now it worked.
The problem is that at Build Settings > Packaging > Info.plist File Path , Xcode only seeks for one Info.plist. If I change the path to zh-Hans.lproj/Info.plist It would only display Chinese App Name on both English and Chinese Language Settings. And the same goes when I change it to en.lproj.
How can I set the path of the Info.plist so that xcode could recognize that there are two of them that needs to be used according to Language setting?
Or is there any better way than what I am doing?
Many Thanks!
You don't localize Info.plist itself, you put localized strings in a separate file InfoPlist.strings. Quoting 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. 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.
In the specific case of the display name, each localized version of InfoPlist.strings would contain something like
CFBundleDisplayName = "My Cool App";
and the display name in Info.plist would be used only if it is not overridden in InfoPlist.strings.

I deleted the Localizations in Xcode, then I cannot add any Localizations back

I deleted the Localizations of the project from the project's info by mistake. Both the storyboard and the related language were removed.
I got back the storyboard from previous file but when I want to add a new Localization, a window popped out and asked me to "Choose files and reference language to create English localization" and there is no resource file at all.
How can I add back the localizations?
Adding back a localization
When you delete your localizations sometimes you can get that situation where you can't add back any localizations in Xcode. Go to the command-line and create a ISO 639-1 two-letter language abbreviation folder with the lproj extension somewhere within your project.
Create an empty language folder
For example:
${SRCROOT}/Resources/Translations/nb.lproj
or
${SRCROOT}/Resources/Translations/en.lproj
Re-add language files to project
In the folder create an empty file called Localizable.strings and add this file to your project. Don't add the .lproj folder, just the contents. Then when you go back into the project file you will see the language under localizations. Now when you have added this, you should see the localization in your project.
No checkbox
If the added file, like a storyboard, doesn't have a checkbox next to it indicating that is part of that language localization you might need to round trip them through another language. To do this add a new language in the project. It should prompt you to copy the existing localized files over to the new language. Then delete the broken localization and re-add it.
My Example
As a specific example, I added the storyboard in the nb.lproj directory to the project. The Norwegian Bokmål appears in the project, but the checkbox for the language in the storyboard inspector won't let me add it. I created nb_NO in the project and it prompted me to copy over the storyboard. Then the storyboard had that checkbox checked. I deleted the 'nb' localization and re-added it. Now everything was the way I wanted it.
I had to solve same problem, and found one solution:
You need to find in finder your *.xcodeproj file and open it as container (ctrl+click on it and you will see it in context menu)
Here you can see project.pbxproj file, open it in Xcode. Its large (but still readable file).
(it will be better to make some copy on save spot, before you start)
Now its the task to add the missing language to this file, and its done.(U can try it on other project with localizations).
There is paragraph you need to add. Search in this file for this /* End PBXSourcesBuildPhase section */(its paragraph right before localization paragraph which is missing) and add something like this after:
/* Begin PBXVariantGroup section */
27548D921611B0BE008EA1CD /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
27548D941611B0BE008EA1CD /* en */,
);
name = Localizable.strings;
path = ../Code;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
You have to do some changes first. Look at the long number 27548D921611B0BE008EA1CD, its ID of the localization file (or some xib file, or other localizable file...), if you dont have any in the procject, just add some Localizable.string file to the project, reopen(or refresh) this project.pbxpro, and find this Localizable.string you should find something like this:
275490591611B0BE008EA1CD /* Localizable.strings in Resources */
and this is it what you need to replace in localization paragraph
also you need to do right settings on path parametr and sourceTree. This twos are readable in fileinspector in xcode.
The "sourceTree" param is Location - mostly its relative to group so sourceTree = "<group>";
The path is path relative from the group to the file (if you dont know, try to make some localization files in different project and look at project.pbxpro, what all this works)
After this you can save project.pbxpro, and you should see in xcode info section "en" localization and you can add more localizations and all other localization stuff.
In xcode 6, do the following:
With the command line, create the following directory/file structure somewhere outside your project directory:
/en.lproj/InfoPlist.strings
/en.lproj/Localizable.strings
In Xcode, open your project and choose File>Add Files to ProjectName to add the recently created en.lproj directory.
After that, you will see English in the Localizations list.
This is an old topic, but after having this issue, and then trying the solution (and having it not work exactly), I thought I'd give details on what DID work.
Like the original poster, I accidentally deleted all of my localizations and was given no obvious recourse in Xcode-- in the project settings under Info it simply said 'this project has not been localized', and when I clicked on the plus button beneath, a blank list of resource files was presented.
I followed #Cameron's guide but found that language folders with Localizable.strings files were already present in Finder, but weren't being acknowledged by Xcode. I couldn't decide how to proceed, but I happened to see an unrelated comment about adding files to Xcode, so I tried adding the existing en.lproj folder and its Localizable.strings file.
This worked, and the listing for English as the development language appeared under Info as well.
Hopefully this will help anyone who experiences the same problem!
Simply create a Folder "Base.lproj" in finder and paste the Xib you want to localize inside it, and add this folder to your project. Now you can able to add other languages without issue.
I've followed a similar approach of #user2070775 reply.
Firstyl when you delete Storyboard and Launchscreen to use your own creation or code programmatically, on Localization you might get similar following empty screen.
Then firstly you should know the language code for example to use French localization its fr etc
With project folder in the Project Navigator you must add New Group -> {LANGUAGE_CODE}.lproj. And then you should add New File -> Strings File -> Localizable.strings. In the #user2070775 answer, also InfoPlist.strings file has added so I added too for now.
In the Localizable.strings file you can add <KEY> = <VALUE> pairs for string to localizated.
Our pair is "this-is-key" = "and-this-is-value-for-spesific-language-on-localizable-string"; for now.
HINT: In key-value pair, when I did not put the semicolon, the XCode
gives error for this situation.
Until now, the following project scheme, must the result of you have.
Additionally, when you looked at the Project -> Info -> Localizations the French or etc. language must be added like in the following image.
TESTING
Basically you can get the results of the what've you done
The remaining part can be set from the Simulator. You must change the simulator language, for this answer the correct one is French.
Go to Settings -> General -> Language & Region -> French and run the project again.

Resources