Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Support localizing [DisplayAttribute] via IStringLocalizer #3518

Closed
NTaylorMullen opened this issue Nov 10, 2015 · 12 comments
Closed

Support localizing [DisplayAttribute] via IStringLocalizer #3518

NTaylorMullen opened this issue Nov 10, 2015 · 12 comments

Comments

@NTaylorMullen
Copy link
Contributor

Today we only localize validation based data annotations. We should expand this outside of the realm of validation (especially since you do a services.AddDataAnnotationsLocalization which says nothing about only adding validation based data annotations.

Having support like this would enable scenarios such as:

Model:

public class User
{
    [Display(Name = "Last Name")]
    public string LastName { get; set; }
}

Page

@model User
@addTagHelper *, Microsoft.AspNet.Mvc.TagHelpers

<label asp-for="LastName" /> <!-- Label would be localizable -->

This issue is for more than just [Display] but this data annotation is the one that showed itself during my sign off activities.

@NTaylorMullen NTaylorMullen changed the title [DisplayName] Data Annotation is not Localized [DisplayName] is not Localized Nov 10, 2015
@NTaylorMullen NTaylorMullen changed the title [DisplayName] is not Localized [Display] is not Localized Nov 11, 2015
@DamianEdwards DamianEdwards changed the title [Display] is not Localized Support localizing [DisplayAttribute] via IStringLocalizer Nov 11, 2015
@DamianEdwards
Copy link
Member

I agree this is something we should investigate. I imagine we'd do the work in DataAnnotationsMetadataProvider to support this.

@hishamco
Copy link
Contributor

Can we extend DataAnnotationsModelMetadataProvider to make this happen, code snippet may look like this

public class LocalizedDataAnnotationsModelMetadataProvider: DataAnnotationsModelMetadataProvider
{
    protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
    {
        var meta = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
        meta.DisplayName = Localizer[propertyName];
    }
}

@DamianEdwards
Copy link
Member

At this stage this is extremely unlikely to make it into 1.0.0, but we'll revisit it after we release.

@hishamco
Copy link
Contributor

I'm agree with you, this may be move to the backlog, because it need more investigation ..

@ahmedanis03
Copy link

ahmedanis03 commented Jun 11, 2016

there is no workaround or a temporary solution we can use until you support it?

@ManuelHaas
Copy link

Is there any progress on this issue? What's the schedule for this issue?

In the current state DisplayAttribute is rather useless for localized applications.

@hishamco
Copy link
Contributor

hishamco commented Aug 6, 2016

@ManuelHaas As I see it's still in backlog

@DamianEdwards
Copy link
Member

@Eilon let's do this one in 1.1 if it fits.

@ShikiGami
Copy link

It's Ok if you want to do it in 1.1, but is there ANY current workaround for this one?

Most of my code was written when back in RC1 when localization wasn't even moving, but I just assumed it will work when it released, and now here I am, getting a bunch of not localized keys as results.

I'm like the 5th person asking for help in this one.

@Eilon
Copy link
Member

Eilon commented Aug 8, 2016

@ShikiGami we'll see if there's a workaround that works on 1.0, but I can't immediately think of any simple workaround.

@Eilon
Copy link
Member

Eilon commented Aug 8, 2016

Putting in the 1.1 milestone. @ryanbrandenburg , I marked this as needs-design because I'm not sure if this is straightforward ("just another attribute") or if this requires some extra plumbing in the system. So, have a look at this, and if it's not trivial, let's see if we can come up with some ideas and run it by @DamianEdwards / @dougbu (because it probably affects Model Metadata or something).

@cihadsevim
Copy link

cihadsevim commented Sep 18, 2016

Keep waiting on this issiue.

https://github.com/dotnet/corefx/issues/11846

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants