WindowsCommunityToolkit
WindowsCommunityToolkit copied to clipboard
Adding ResourceString Markup Extension
Fixes
#4318
With the markup extension:
<Button Content="{str:ResourceString Name=ButtonText}"/>
As you see we are using a custom markup extension to bind your content strings. We are able to simply pass in the name of the resource we want to use and get the localized string back.
Now our resource file need only contain simple names without the properties, making it much cleaner and easier to read.
One feature I'm adding to this is the ability to specify a language as well if the developer wanted to get resources from another language context.
<Button Content="{str:ResourceString Name=ButtonText}", Language="es-ES"/>
PR Type
What kind of change does this PR introduce?
- Adds a Markup Extension
- Adds a Sample page for the extension
Feature
Sample app changes
What is the current behavior?
What is the new behavior?
PR Checklist
Please check if your PR fulfills the following requirements:
- [X] Tested code with current supported SDKs
- [ ] New component
- [ ] Pull Request has been submitted to the documentation repository instructions. Link:
- [ ] Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
- [ ] If control, added to Visual Studio Design project
- [X] Sample in sample app has been added / updated (for bug fixes / features)
- [X] Icon has been created (if new sample) following the Thumbnail Style Guide and templates
- [ ] New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
- [ ] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [X] Header has been added to all new source files (run build/UpdateHeaders.bat)
- [X] Contains NO breaking changes
Other information
Thanks HerrickSpencer for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request ๐
This PR has been marked as "needs attention ๐" and awaiting a response from the team.
@Sergio0694 I updated all per your comments. Thank you.
This PR has been marked as "needs attention ๐" and awaiting a response from the team.
As pointed out in the original issue
Your helper depends on getting strings from "Resources.resw" file and due to this I can't get strings from another .resw files (for example: every page has .resw file for it like => Home.xaml have Home.resw & About.xaml have About.resw)
Many applications use more than one .resw file and wouldn't be able to fully use this new Markup Extension. I think we should look into providing this capability.
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 30 days of this comment.
@HerrickSpencer wanted to check-in and see if you were planning to pick this back up again to finish? Let us know, thanks!
@HerrickSpencer wanted to check-in and see if you were planning to pick this back up again to finish? Let us know, thanks!
Sure! I kind of let this drop off my radar since it wasn't touched in the last 2 months, but I can certainly take a stab at addressing the latest concerns and providing an optional solution.
This PR has been marked as "needs attention ๐" and awaiting a response from the team.
FYI @rudyhuyn
WinUI 3 doesn't support changing the language by x:uid without restarting the app https://github.com/microsoft/microsoft-ui-xaml/issues/5940.
I think when you reload the page, the language will be changed. Can str:ResourceString
be extended to support immediately language change for great UX? If it's a big overhead, maybe str:HotResourceString
should be added (at least for settings page)?