aksoftware98 / multilanguages

AKSoftware.Localization.MultiLanguages is a package for .NET developers allows them to easily build apps target multiple languages with just few lines of code
MIT License
85 stars 15 forks source link

Adding support for UWP #18

Closed gerfen closed 3 years ago

gerfen commented 3 years ago

Hi @aksoftware98 ,

I've been working on adding support for UWP. Before submitting a PR I want to discuss some of the issues I faced to get everything working.

  1. In order to support UWP, I needed to change Target Framework for AKSoftware.Localization.MultiLanguages from .Net Standard 2.1 to .Net Standard 2.0.

  2. For my UWP needs I can't use embedded resource localization files, so I refactored to code to introduced an new interface called IKeysProvider. I added a implementation named EmbeddedResourceKeyProvider and refactored the original code to use this class to get the keys.

  3. I wasn't able to figure out how to get UWP to call an indexer with multiple parameters. Worse yet there is not out of the box way to pass multiple parameters to a value converter. I did find an implementation of a MultiValueConverter in the (Cimbalino.Toolkit UWP package). I only wanted support for the MultiValueConverter so I cut and pasted the code required to support MultiValueConverters into a new library called AKSoftware.Localization.MultiLanguages.UWP. I've left the copyright info in these borrowed classes for proper attribution. I'm really not sure what the proper etiquette is for borrowing code in this manner. Cimbalino.Toolkit uses the MIT License so I think it would be OK to include these files with proper attribution.

  4. I added two new indexers to Keys.cs to support passing IDictionary<string, object> and ExpandoObject to help support string interpolation in UWP with MultiValueConverter.

The golden path is pretty straight forward:

<TextBlock Text="{Binding Localization[HomePage:HelloWorld] }" Style="{StaticResource LargeHeaderLabelStyle}"></TextBlock>

String interpolation is a bit more complicated:

        <TextBlock Style="{StaticResource LabelStyle}">
            <interactivity:Interaction.Behaviors>
                <behaviors:MultiBindingBehavior PropertyName="Text" Converter="{StaticResource LocalizationConverter}" >
                    <behaviors:MultiBindingItem Value="HomePage:Hello"/>
                    <behaviors:MultiBindingItem Value="firstname:AK"/>
                    <behaviors:MultiBindingItem Value="lastname:Academy"/>
                </behaviors:MultiBindingBehavior>
            </interactivity:Interaction.Behaviors>
        </TextBlock>
  1. I built a sample UWP app that is mostly at parity with the sample Blazor app WRT to string interpolation. image

  2. I added more unit tests to test the refactoring to EmbeddedResourceKeyProvider.

With all of the these changes, the code still functions for Blazor apps and can now be used with UWP. If you would like to see the changes I've implemented, you can check out my fork here. I should also note that I am still working on an implementation of IKeysProvider to load localization resources from an external source in UWP. I hope to complete that work later today.

Looking forward to discussing how to move forward with a PR.

Thanks!

aksoftware98 commented 3 years ago

What you have over here is something super fantastic, this is really a very great idea, especially now before the big updates for Windows UI, I believe that many developers to be back to Windows development with the new UI improvements and with the release of Windows 10X. What I have seen is very smart, I'm ready to discuss the PR whenever you like and maybe we can work together to complete that implementation.

Here is my email address: aksoftware98@hotmail.com

To see how we can proceed

Thanks again for your interest and for your big contribution to this small project, this gives it a very big push among .NET developers

gerfen commented 3 years ago

@aksoftware98 - Nice chatting with you today. Thanks for being open to accepting my PR! Closing this issue.