Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuget packages containing localized resources not working with UWP/UAP. Is there a workaround? #2684

Closed
Stefan-deHoDev opened this issue Apr 28, 2016 · 3 comments
Labels
Resolution:Duplicate This issue appears to be a Duplicate of another issue

Comments

@Stefan-deHoDev
Copy link

Installing a nuget package that has localized resources in an UWP app, you can only access the default language resources.

How to reproduce:
-1. Create blank UWP app
-2. Install localized nuget package, you can use this test package I created:
Install-Package LocalizationTest
-3. Add this code to MainPage.xaml

 <StackPanel>
            <Button Content="languagetest"
                    Click="Button_Click" />
            <TextBlock x:Name="output"
                       Style="{StaticResource BodyTextBlockStyle}" />
        </StackPanel>

-4. Add this code to MainPage.xaml.cs

        public void Write(String t)
        {
            output.Text += t + Environment.NewLine;
            System.Diagnostics.Debug.WriteLine(t);
        }
        private void Button_Click(System.Object sender, RoutedEventArgs e)
        {
            String en = LocalizationTest.Resources.Strings.ResourceManager.GetString("Language", new System.Globalization.CultureInfo("en"));
            String de = LocalizationTest.Resources.Strings.ResourceManager.GetString("Language", new System.Globalization.CultureInfo("de"));
            String en_Us = LocalizationTest.Resources.Strings.ResourceManager.GetString("Language", new System.Globalization.CultureInfo("en-US"));
            String de_DE = LocalizationTest.Resources.Strings.ResourceManager.GetString("Language", new System.Globalization.CultureInfo("de-DE"));
            Write(String.Format("Strings:en {0}, de {1}, en_US {2}, de_DE {3}", en, de, en_Us, de_DE));
            var map = Windows.ApplicationModel.Resources.Core.ResourceManager.Current.AllResourceMaps.First().Value;
            var element = map.First(x => x.Key.Contains("LocalizationTest"));
            Write(element.Key + Environment.NewLine + getLang(element.Value));
        }
        public String getLang(Windows.ApplicationModel.Resources.Core.NamedResource r)
        {
            String ret = "";
            foreach (var item in r.Candidates)
            {
                ret += item.ValueAsString + Environment.NewLine;
            }
            return ret;
        }

-5. Start the app, press the button, You only get the english strings.

Do the same steps with an blank Windows 8.1 app and you get german and english strings.

If, instead of adding the nuget package, you reference the LocalizationTest.dll directly, you get the same result in an UWP app.

For reference:
Output in a Windows 8.1 app:

Strings:en english, de german, en_US english, de_DE german
LocalizationTest.Resources.Strings/Language
english
german

Output in a UWP app:

Strings:en english, de english, en_US english, de_DE english
LocalizationTest.Resources.Strings/Language
english

Again: The UWP output is the same as the Windows 8.1, when referencing the LocalizationTest.dll directly instead of using the nuget package.

This is using the newest NuGet version and Visual Studio 2015 Update 2.

If anyone can figure out a workaround that would very much be appreciated!

@rrelyea rrelyea added the Resolution:Duplicate This issue appears to be a Duplicate of another issue label Apr 28, 2016
@rrelyea
Copy link
Contributor

rrelyea commented Apr 28, 2016

Unfortunately there is no way around this at the moment. One needs to use fat packages for this.
Duplicate of #2245

@rrelyea rrelyea closed this as completed Apr 28, 2016
@Stefan-deHoDev
Copy link
Author

Wait, I'm telling you fat packages are not working!

This package is a normal Portable Class Library with multiple languages inside. It's not possible to access the other languages inside that Portable Class Library. (That's the definition of a fat package, is it not?)

@Stefan-deHoDev
Copy link
Author

Can this be reopened? The issue was missunderstood. This is NOT a duplicate of issue #2245

I apologize, the title should have been worded differently. I edited the title to make it more clear.

@Stefan-deHoDev Stefan-deHoDev changed the title Localized nuget packages not working with UWP/UAP. Is there a workaround? Nuget packages containing localized resources not working with UWP/UAP. Is there a workaround? Apr 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution:Duplicate This issue appears to be a Duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants