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

Adding ResourceString Markup Extension #4319

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

HerrickSpencer
Copy link
Contributor

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:

  • 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
  • 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)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

Other information

image

@ghost
Copy link

ghost commented Oct 13, 2021

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 ghost requested review from michael-hawker and azchohfi October 13, 2021 22:03
@michael-hawker michael-hawker added this to the 7.2/8.0? milestone Oct 14, 2021
Copy link
Member

@Sergio0694 Sergio0694 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 😄
Just left a bunch of code style nits, but the functionality looks perfect!

@ghost
Copy link

ghost commented Oct 15, 2021

This PR has been marked as "needs attention 👋" and awaiting a response from the team.

@HerrickSpencer
Copy link
Contributor Author

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

@HerrickSpencer HerrickSpencer dismissed Sergio0694’s stale review October 23, 2021 05:43

Thanks! I've updated per all your comments.

@HerrickSpencer HerrickSpencer linked an issue Oct 23, 2021 that may be closed by this pull request
@ghost
Copy link

ghost commented Nov 2, 2021

This PR has been marked as "needs attention 👋" and awaiting a response from the team.

Copy link
Member

@Arlodotexe Arlodotexe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far. Mostly styling fixes.

There's also a large file called "how" I wasn't able to directly comment on. Appears to contain a lot of git history and may have been added by mistake, this will need to be removed.

return GetValue(name);
}

// Not using ResourceContext.GetForCurrentView nor GetForViewIndependentUse
Copy link
Member

@Arlodotexe Arlodotexe Jan 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for not using these APIs here? Can we add more clarification to the code comment?

@Arlodotexe
Copy link
Member

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.

@ghost ghost removed the needs attention 👋 label Jan 20, 2022
@ghost ghost added the no-recent-activity 📉 Open Issues that require attention label Feb 4, 2022
@ghost
Copy link

ghost commented Feb 4, 2022

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.

@michael-hawker
Copy link
Member

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

@ghost ghost removed the no-recent-activity 📉 Open Issues that require attention label Feb 4, 2022
@HerrickSpencer
Copy link
Contributor Author

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

@ghost
Copy link

ghost commented Feb 11, 2022

This PR has been marked as "needs attention 👋" and awaiting a response from the team.

…esourceStringXaml.bind

Microsoft.Toolkit.Uwp.UI/Extensions/Markup/ResourceStringExtension.cs
Per comments in PR
…hat accomodates no optional value in x:Bind compiled function
@michael-hawker michael-hawker mentioned this pull request Feb 14, 2022
17 tasks
@michael-hawker
Copy link
Member

FYI @rudyhuyn

@ghost ghost removed the needs attention 👋 label Mar 11, 2022
@michael-hawker michael-hawker added the labs 🧪 Marks an issue/PR involved with Toolkit Labs label Jun 9, 2022
@YegorStepanov
Copy link

WinUI 3 doesn't support changing the language by x:uid without restarting the app microsoft/microsoft-ui-xaml#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)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
labs 🧪 Marks an issue/PR involved with Toolkit Labs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] ResourceString Markup Extension for easy localization
7 participants