Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Localization for Enum #6006


User avatar
0
pointlevel created

Hello!

I need to use localization for my enums with annotation to use with dropdownlists, but i cant figure it out.

Aaron has described it like this:

public enum OrderByOptions
{
    [AbpDisplayName(MyConsts.LocalizationSourceName, "OrderByOptions.Default")]
    Default,
    [AbpDisplayName(MyConsts.LocalizationSourceName, "OrderByOptions.PriceLowToHigh")]
    PriceLowToHigh,
    [AbpDisplayName(MyConsts.LocalizationSourceName, "OrderByOptions.PriceHighToLow")]
    PriceHighToLow,
    [AbpDisplayName(MyConsts.LocalizationSourceName, "OrderByOptions.MostRecent")]
    MostRecent
}

Copied from this post: https://stackoverflow.com/a/46642292

But i get validation error saying that this attribute is not valid on this declaration type, only valid on 'class, method, property, indexer, event' declarations.

Any solution? Thanks in advance!


5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    You can take look this:https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3573

  • User Avatar
    0
    pointlevel created

    Any idea how to customize the taghelper GetEnumSelectList to support that functionality and make localization possible?

  • User Avatar
    0
    ismcagdas created
    Support Team

    You can define "Enum_{Enum_Name_Here}_{Enum_Value_Here}" localization keys for your enums. Something like "Enum_OrderByOptions_PriceLowToHigh".

  • User Avatar
    0
    pointlevel created

    ismcagdas, can you please provide some example, i dont really understand how to use your example?

    I have tried to add:

    <text name="Enum_Test_Type_Summer">Sommar</text>
    

    For this Enum...

    public class MyEnums
    {
        public enum Test_Type 
        {
            [Display(Name = "Summer")]
            Summer
        }
    }
    

    But the strings will not be localized.....the values in the dropdown becomes: "Summer" instead of the wanted "Sommar"

  • User Avatar
    0
    ismcagdas created
    Support Team

    @pointlevel

    Could you also share generated cshtml code ? Maybe I understand you wrong at the first place.