Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

How to localize Attribute values? #116

@aloksharma1

Description

@aloksharma1

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions