You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
Hello, Do you have any example on localizing DisplayAttribute or similar? i tried creating my own localized attribute but it seems you can't proper DI into attribute classes, here is what i tried:
public sealed class LocalizedDisplayAttribute : Attribute
{
protected IJsonStringLocalizer StringLocalizer;
public LocalizedDisplayAttribute(string displayName)
{
StringLocalizer = HttpContextHelper.HttpContext.RequestServices.GetService<IJsonStringLocalizer>();
DisplayName = displayName;
}
public string DisplayName
{
get
{
return StringLocalizer[DisplayName];
}
set
{
}
}
}
unfortunately it always returns null service to me, tried using httpcontextaccessor, direct injection and what not..
if anyone have done this already please help.
The text was updated successfully, but these errors were encountered:
if as DisplayAttribute you mean "DataAnnotation" you should only follow the microsoft guidelines to activate it.
For custom attribute you should inject the IJsonStringLocalizer like in your exemple.
I will investigate more next week. If you already have a solution, don't forgot to share it in this thread
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hello, Do you have any example on localizing DisplayAttribute or similar? i tried creating my own localized attribute but it seems you can't proper DI into attribute classes, here is what i tried:
unfortunately it always returns null service to me, tried using httpcontextaccessor, direct injection and what not..
if anyone have done this already please help.
The text was updated successfully, but these errors were encountered: