Base solution for your next web application
Open Closed

Enum localization #3213


User avatar
0
PhilWynn created

Hi,

I would like to use the Display Attribute to apply localized names to my enum value. Could you please tell me how I can do this using the AZ localization framework.

Thank you


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can check this forum topic #914@00c8767f-2677-4838-85ef-3d2e9f2bd10f

  • User Avatar
    0
    PhilWynn created

    Hi,

    I am not really sure how that post will help me with my current issue. I need to present the localized value of an enum on a modal form. The code I have is as follows:

    public enum ProcessingType
        {
            [Display(Name = "Standard")]
            Standard = 1,
            [Display(Name = "Off cycle")]
            OffCycle = 2,
            [Display(Name = "End of year")]
            EndOfYear = 3
        }
    
    public class HeadlineTaskDto
    {
            ...
            public ProcessingType ProcessingType { get; set; }
           ...
    }
    
    public static class EnumExtensions
        {
            public static string GetDisplayName(this Enum enumValue)
            {
                return enumValue.GetType()
                                .GetMember(enumValue.ToString())
                                .First()
                                .GetCustomAttribute<DisplayAttribute>()
                                .GetName();
            }
        }
    
    ...
    <div class="col-md-3">
            <div class="form-group form-md-line-input form-md-floating-label">
                 <div class="form-control form-control-static">@Model.Task.ProcessingType.GetDisplayName()</div>
                    <label>Type</label>
            </div>
    </div>
    ...
    

    I'm not sure how a client side constant would help me here?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    The approach on the forum topic I have sent is for using localized enum values with javascript on the client side.

    In your approach, you can try to use

    LocalizationHelper.GetString("SourceName", "Standart")