CommunityToolkit / CommunityToolkit/dotnet

Incorrect parameter localization via the Display attribute during validation

Open
#412 0 comments 0 reactions 0 assignees View on GitHub
bug :bug:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

When trying to add localization for an attribute through the following code:
```cs
[ObservableProperty]
[NotifyDataErrorInfo]
[Required(
ErrorMessageResourceType = typeof(ValidationResources),
ErrorMessageResourceName = nameof(ValidationResources.Required))]
[Display(
ResourceType = typeof(ValidationResources),
Name = nameof(ValidationResources.Username))]
private string username = string.Empty;
```
localization works correctly for the message itself, but not for the field name set via Display. I assume that there is some kind of cache that blocks the change of locale.

![image](https://user-images.githubusercontent.com/3002068/187570972-a826579a-ed98-4d86-a658-9a2c10fe7370.png)
[issue.zip](https://github.com/CommunityToolkit/dotnet/files/9457545/issue.zip)

### Regression

_No response_

### Steps to reproduce

```text
Run example solution and change language
```

### Expected behavior

parameter display name should change correctly when changing language

### Screenshots

_No response_

### IDE and version

VS 2022

### IDE version

17.3

### Nuget packages

- [ ] CommunityToolkit.Common
- [ ] CommunityToolkit.Diagnostics
- [ ] CommunityToolkit.HighPerformance
- [X] CommunityToolkit.Mvvm (aka MVVM Toolkit)

### Nuget package version(s)

8.0.0

### Additional context

_No response_

### Help us help you

No, just wanted to report this

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.