Localization of proprties

Topics: Core, General, Localization, Troubleshooting, Writing modules
Dec 2, 2012 at 2:02 PM


I am trying to localize(translate) the "creatable" and "Draftable" properties of content types

I added a display name to one of the properties, but this doesn't seem to work:


using System.ComponentModel;
namespace Orchard.Core.Contents.Settings {
    public class ContentTypeSettings {
        /// <summary>
        /// Used to determine if an instance of this content type can be created through the UI
        /// </summary>
        public bool Creatable { get; set; }
        /// <summary>
        /// Used to determine if this content type supports draft versions
        /// </summary>
        [DisplayName("Lovely new property name")] 
        public bool Draftable { get; set; }
        /// <summary>
        /// Defines the stereotype of the type
        /// </summary>
        public string Stereotype { get; set; }

Dec 2, 2012 at 2:11 PM
Edited Dec 2, 2012 at 2:11 PM

I'm not sure if this is correct, but I think the new DataAnnotations (System.ComponentModel.DataAnnotations) uses [Display(Name="TEXT")] in favor over [DisplayName("TEXT")].

That being said, I have been trying to figure out a way to localize the [Display(Name="TEXT")] attribute. But I have not had any success.  I've tried a lot of different things that I've found here and elsewhere (related to metadata and MVC).

I started to take a look at Orchard.Framework.Mvc.DataAnnotations folder for examples. It has Required/String/RegularExpression/Range validators. But nothing about plain attributes.

Dec 3, 2012 at 1:09 PM

Can anyone help us please :)?

Dec 3, 2012 at 6:44 PM

Data annotations are entirely the wrong place to look for this: both strings are already localizable through the po files, and are defined in ContentTypeSettings.cshtml. I hope this helps.

May 30, 2014 at 9:21 AM
Edited May 30, 2014 at 10:49 AM
Roy, you are right but there is one case when we want to localize properties by DisplayNameAttribute. This case appears when you have form with validation.

DisplayNameAttribute is translated here
// substitute the attribute to its localized version if available
if ( _validationAttributes.TryGetValue(attribute.GetType(), out localizedAttribute) ) {
    localizedAttributes.Add(localizedAttribute((ValidationAttribute)attribute, tProvider.Value));
else {

    // try to inject the localizer if it's an unkown validation attribute
    if ( validationAttribute != null ) {
        var propertyInfo = validationAttribute.GetType().GetProperty("T", typeof(Localizer));
        if ( propertyInfo != null ) {
            propertyInfo.SetValue(attribute, tProvider.Value, null);
    if ( attribute is DisplayNameAttribute ) {
        metadata.DisplayName = tContainer.Value(metadata.DisplayName).Text;