Bug 60200 - NSBundle.MainBundle.Localizations has duplicate entries
Summary: NSBundle.MainBundle.Localizations has duplicate entries
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-10-16 10:35 UTC by Mikael Nensén
Modified: 2017-11-30 20:24 UTC (History)
7 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Debug information (27.41 KB, image/png)
2017-10-16 10:35 UTC, Mikael Nensén
Details
Swift Example of Duplicated Locales (32.01 KB, application/zip)
2017-11-30 20:24 UTC, Vincent Dondain [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Mikael Nensén 2017-10-16 10:35:55 UTC
Created attachment 25311 [details]
Debug information

The NSBundle.MainBundle.Localizations property lists duplicate entries.

I have the following entries in my Info.plist:
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleLocalizations</key>
<array>
        <string>de</string>
        <string>nl</string>
        <string>no</string>
        <string>sv</string>
</array>

I have the following folders at the root of my project (previously under \Resources\ but I moved them to the root of my project to see if that was the issue):
Base.lproj
de.lproj
nl.lproj
no.lproj
sv.lproj

If I remove the CFBundleDevelopmentRegion and CFBundleLocalizations data from Info.plist, I only get "en" as a extra entry in my NSBundle.MainBundle.Localizations property.
Comment 1 Pierce Boggan [MSFT] 2017-10-27 16:57:52 UTC
Hey Mikael,

Thanks so much for taking the time to file this issue! :) I'm moving this over to the iOS team, as it looks like a bug there and not in the Visual Studio Tools for Xamarin. Thanks for your patience!

Best,
Pierce Boggan
Comment 2 Timothy Risi 2017-10-27 17:31:08 UTC
Please include your full build logs, crash reports (if any), test case (to reproduce) and all version information.

To get full build logs just set the log verbosity to diagnostic at the following locations:
- On Visual Studio for Mac: Preferences > Projects > Build
- On Visual Studio for Windows: Tools > Options > Projects and Solutions > Build and Run

On Visual Studio Windows you also want to add `-v -v -v -v` to the mtouch additional arguments by right-clicking the project in the solution explorer and selecting `Properties`.
Note: this is done automatically on Visual Studio for Mac when the log verbosity is set to diagnostic.

Easiest way to get exact version information:
- On Visual Studio for Mac: "Visual Studio" menu, "About Visual Studio" item, "Show Details" button.
- On Visual Studio for Windows: "Help menu", "About Microsoft Visual Studio" item.
Then copy/paste the version information (you can use the "Copy Information" button).
Comment 3 Vincent Dondain [MSFT] 2017-11-29 22:34:10 UTC
Hi Mikael,

I'm not sure what you mean exactly by: "The NSBundle.MainBundle.Localizations property lists duplicate entries" but it seems that the output of 'NSBundle.MainBundle.Localizations' after you removed 'CFBundleDevelopmentRegion' and 'CFBundleLocalizations' surprises you. You're getting "en" when you're probably expecting to get nothing.

The reason for this is because the 'CFBundleDevelopmentRegion' is automatically added if missing (you can check the generated Info.plist in your bin folder to confirm that).

Because of that 'NSBundle.MainBundle.Localizations' returns "en".

We're changing that behavior with https://github.com/xamarin/xamarin-macios/pull/2779 so we don't set 'CFBundleDevelopmentRegion' automatically.

Hope this answers your question, feel free to reopen the bug if you're still experiencing the issue.
Comment 4 Mikael Nensén 2017-11-30 08:53:08 UTC
Sorry, I haven't had the time to go over this and create an example.

Just check the attached screenshot. There are duplicate entries for my supported languages. If i debug the following line:
NSBundle.MainBundle.Localizations

It says it contains 10 localizations, while I've only set that I support 5.

de
nl
no
sv
Base
de - duplicate
nl - duplicate
no - duplicate
sv - duplicate
en - didn't add this.
Comment 5 Mikael Nensén 2017-11-30 08:55:15 UTC
If I remove the below information from my Info.plist:
<key>CFBundleLocalizations</key>
<array>
        <string>de</string>
        <string>nl</string>
        <string>no</string>
        <string>sv</string>
</array>

The duplicates go away.

It's like it's reading the info from the Info.plist file and then appending the localization folders ontop of the information already in the Info.plist file.

Either base the metadata off of what is in the Info.plist file or the folder structure, not both.
Comment 6 Vincent Dondain [MSFT] 2017-11-30 20:24:28 UTC
Hi Mikael,

So for the "en - didn't add this" as I explained we add this automatically but this is gonna change after https://github.com/xamarin/xamarin-macios/pull/2779.

As for the duplicates, unfortunately this is the behavior of the native method, it returns the language of the locales found in both the Info.plist and the localization folders (lproj).

I attached a native Swift project showing this.
It has an Info.plist with:

<key>CFBundleLocalizations</key>
<array>
        <string>en</string>
        <string>fr</string>
        <string>de</string>
        <string>it</string>
</array>

and 1 lproj for each language.

I then do: 'print (Bundle.main.localizations)', the equivalent of our 'NSBundle.MainBundle.Localizations' and it returns: '["en", "fr", "de", "it", "de", "it", "Base", "fr"]'.

Apple's documentation isn't very precise about the behavior of 'localizations': https://developer.apple.com/documentation/foundation/bundle/1417415-localizations.

"A list of all the localizations contained in the bundle." (all including duplicates I guess).

Xamarin.iOS is a thin layer on top of the native iOS frameworks and we cannot change the behavior of the native method. If you believe that this in not the way the API should behave you can still open a radar against Apple (https://developer.apple.com/bug-reporting) and hope that someone from Apple answer it (note: they are not very fast).

In the meantime I'm closing this bug as invalid as, unfortunately, we cannot fix it.

However I will make sure that we update our documentation: https://developer.xamarin.com/api/property/Foundation.NSBundle.Localizations

Thanks.
Comment 7 Vincent Dondain [MSFT] 2017-11-30 20:24:57 UTC
Created attachment 25877 [details]
Swift Example of Duplicated Locales