WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

Adding ResourceString Markup Extension

Open HerrickSpencer opened this issue 2 years ago โ€ข 11 comments

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)
  • [ ] 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

image

HerrickSpencer avatar Oct 13 '21 22:10 HerrickSpencer

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 ๐Ÿ™Œ

ghost avatar Oct 13 '21 22:10 ghost

This PR has been marked as "needs attention ๐Ÿ‘‹" and awaiting a response from the team.

ghost avatar Oct 15 '21 18:10 ghost

@Sergio0694 I updated all per your comments. Thank you.

HerrickSpencer avatar Oct 15 '21 20:10 HerrickSpencer

This PR has been marked as "needs attention ๐Ÿ‘‹" and awaiting a response from the team.

ghost avatar Nov 02 '21 19:11 ghost

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.

Arlodotexe avatar Jan 20 '22 20:01 Arlodotexe

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.

ghost avatar Feb 04 '22 21:02 ghost

@HerrickSpencer wanted to check-in and see if you were planning to pick this back up again to finish? Let us know, thanks!

michael-hawker avatar Feb 04 '22 22:02 michael-hawker

@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.

HerrickSpencer avatar Feb 06 '22 23:02 HerrickSpencer

This PR has been marked as "needs attention ๐Ÿ‘‹" and awaiting a response from the team.

ghost avatar Feb 11 '22 23:02 ghost

FYI @rudyhuyn

michael-hawker avatar Mar 11 '22 22:03 michael-hawker

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)?

YegorStepanov avatar Jun 23 '22 10:06 YegorStepanov