Kooboo / CMS

Old Kooboo CMS, Use Kooboo/Kooboo instead.
http://www.kooboo.com
Other
337 stars 223 forks source link

ability to localize dataannotations model #290

Open ludoAlcala opened 10 years ago

ludoAlcala commented 10 years ago

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 !

kooboo-jifeng commented 10 years ago

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>
ludoAlcala commented 10 years ago

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