Localize Info.plist with XLIFF in Xcode 6 - localization

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.

Related

Export XLIFF file seems to be missing some .strings and .stringsdict files for localization

I am attempting to export XLIFF files for my app. I currently have 2 .strings files one from a module and one in the app itself, and one .stringsdict file.
When I select the project file, and go to editor > Export for localization only the strings from the first file are included (the one from the other module) in the exported XLIFF file.
I was able to figure this out.
Just a simple oversight, needed to link these localization files to my project by tapping on this "Locaolize..." button in the right pain

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:

Can you localized NSAppleMusicUsageDescription? [duplicate]

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

Swift Localization: Genstrings

I'm trying to prepare my app to be passed off to translators for localization, but I'm running into some issues. I added the file "Localizable.strings" to my project, and I have "Use Base Internationalization" checked.
Looking at my app in Xcode, however, I don't see any "Base.lproj" or "en.lproj" or .lproj files for any language, though when I open my app in Finder I can see an "en.lproj" and an "es.lproj" folder.
I'm guessing this may be the reason that the genstrings utility isn't working properly for me. I have many calls in my code like self.navigationItem.title = NSLocalizedString(...), but when I execute genstrings *.swift, nothing changes in Localizable.strings, and I still can't see any .lproj folders.
Xcode doesn't automatically add those files you generated into your build path, you have to manually add them. Also, genstrings generate Localizable.strings file that you can then localize. To generate the lproj files you were talking about, you have to localize your Main.storyboard file.

Resource files are not displaying in Localization

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.

Resources