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

Fixed StringFormatConverter ignoring Language parameter, cleanup #4764

Merged

Conversation

Arlodotexe
Copy link
Member

Fixes #3243

This PR pulls in the changes from #4546, and cleans up a significant amount of plumbing that isn't needed. All unit tests are passing, and new tests have been added.

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Code style update (formatting)

What is the current behavior?

In IValueConverter, the language parameter is being ignored.

That means passing a language via ConverterLanguage wouldn't format the string with respect to the provided language.

What is the new behavior?

The language property is being passed to the string formatter. Now, the following will format as expected:

Example usage:

<TextBlock Text="{x:Bind SomeCurrencyValue, Converter={StaticResource MyConverter}, ConverterLanguage='en-GB'}" />
<TextBlock Text="{Binding SomeDateValue, Converter={StaticResource MyConverter}, ConverterLanguage='de-DE'}" />

PR Checklist

Please check if your PR fulfills the following requirements:

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • 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

@ghost
Copy link

ghost commented Sep 13, 2022

Thanks Arlodotexe 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 September 13, 2022 17:39
@ghost ghost added feature request 📬 A request for new changes to improve functionality improvements ✨ labels Sep 13, 2022
@Arlodotexe Arlodotexe added this to the 7.1.3 milestone Sep 15, 2022
@Arlodotexe Arlodotexe self-assigned this Sep 15, 2022
@Arlodotexe Arlodotexe added the for-review 📖 To evaluate and validate the Issues or PR label Sep 22, 2022
Copy link
Member

@michael-hawker michael-hawker left a comment

Choose a reason for hiding this comment

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

Not sure if we can add a better test case here based on how this works or could be compromised if something in the platform/world changes (though think that would be unlikely).

Small optimization though for the converter itself though which I think could be a good change.

Assert.AreEqual(Date.ToString(expectedFormat, CultureInfo.InvariantCulture), result);
}

[TestCategory("Converters")]
Copy link
Member

Choose a reason for hiding this comment

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

Is there a test we could add like a general date where we have the same format string but then change the language between en/gb and see the result of the date with month/day flipped? Then we know for sure it worked, right?

A lot of the current test cases just seem to be testing string.Format to ToString in a way we know should work, right? (which is important, but not really replicating how we expect it to be used in an app, right?)

Copy link
Member

Choose a reason for hiding this comment

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

@Arlodotexe you could have left them, was just suggesting an additional test, looks like something was missed in the clean-up:

         D:\a\1\s\UnitTests\UnitTests.UWP\Converters\Test_StringFormatConverter.cs(19,41): error CS0414: The field 'Test_StringFormatConverter.Amount' is assigned but its value is never used [D:\a\1\s\UnitTests\UnitTests.UWP\UnitTests.UWP.csproj]

@ghost
Copy link

ghost commented Oct 11, 2022

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

@michael-hawker michael-hawker merged commit ca55ade into CommunityToolkit:main Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request 📬 A request for new changes to improve functionality for-review 📖 To evaluate and validate the Issues or PR improvements ✨ needs attention 👋
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use of CultureInfo in StringFormatConverter
4 participants