CMS icon indicating copy to clipboard operation
CMS copied to clipboard

ability to localize dataannotations model

Open ludoAlcala opened this issue 11 years ago • 2 comments

Hi,

please could you add a way to localize our model data-annotations using the label manager ? By example to have the possibility to add an attribute [KoobooDisplayName=("String")] on our model in a module and get the value directly in the label manager or register a custom modeldata provider? There is some example available on the internet, the best i've seen is : https://github.com/Haacked/mvc-metadata-conventions it includes everything to get the value in a resx directory, but it should be best from label manager to allow easy management.

What do you think about that ?

thanks !

ludoAlcala avatar Sep 10 '14 18:09 ludoAlcala

Hi,

The metadata string is already localized in the editor templates.

@{  
    ViewData.TemplateInfo.HtmlFieldPrefix = ViewData.TemplateInfo.HtmlFieldPrefix.Replace(ViewData.ModelMetadata.PropertyName, "").Trim('.');
    var propertyName = ViewData["name"] == null ? ViewData.ModelMetadata.PropertyName : ViewData["name"].ToString(); 
}
<tr>
    <th>
        @if (IsSectionDefined("Label"))
        { 
            @RenderSection("Label", false)
        }
        else
        {
            <label for="@ViewData.TemplateInfo.GetFullHtmlFieldId(propertyName)">
                @ViewData.ModelMetadata.GetDisplayName().Localize()</label>           
        }
    </th>
    <td>
        @RenderBody()       
    </td>
</tr>

kooboo-jifeng avatar Sep 11 '14 07:09 kooboo-jifeng

Hi jifeng,

thanks for your quick answer, but i just created a model in a specific module and put it some displayname annotations, and i have no labels corresponding to my properties shown in label management, is it possible to do that ?

thanks

ludoAlcala avatar Sep 11 '14 15:09 ludoAlcala