title: ResourceManager problem with MVC localization
body: <p>There is many solutions for localization.
  I've decided for this one:
  <a href="http://geekswithblogs.net/brians/archive/2010/06/14/asp.net-mvc-localization-displaynameattribute-alternatives-a-better-way.aspx" rel="nofollow">http://geekswithblogs.net/brians/archive/2010/06/14/asp.net-mvc-localization-displaynameattribute-alternatives-a-better-way.aspx</a></p>
  
  <pre><code>public class LocalizedDataAnnotationsModelMetadataProvider : DataAnnotationsModelMetadataProvider
          {
              protected override ModelMetadata CreateMetadata(
                  IEnumerable&lt;Attribute&gt; attributes,
                  Type containerType,
                  Func&lt;object&gt; modelAccessor,
                  Type modelType,
                  string propertyName)
              {
                  var meta = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
                  if (string.IsNullOrEmpty(propertyName))
                      return meta;
                  if (meta.DisplayName != null)
                      GetLocalizedDisplayName(meta, propertyName);
                  if (string.IsNullOrEmpty(meta.DisplayName))
                      meta.DisplayName = string.Format("[[{0}]]", propertyName);
                  return meta;
              }
              private static void GetLocalizedDisplayName(ModelMetadata meta, string propertyName)
              {
                  ResourceManager resourceManager = App_GlobalResources.Strings.ResourceManager;
                  CultureInfo culture = Thread.CurrentThread.CurrentUICulture;
                  meta.DisplayName = resourceManager.GetString(propertyName, culture);
              }
          }
  </code></pre>
  
  <p>I've changed line:</p>
  
  <pre><code>if (meta.DisplayName == null)
  </code></pre>
  
  <p>into:</p>
  
  <pre><code>if (meta.DisplayName != null)
  </code></pre>
  
  <p>to enter GetLocalizedDisplayName function</p>
  
  <p>In App_GlobalResources there are 2 files:
  <strong>Strings.resx</strong> and <strong>Strings.pl.resx</strong>. 
  Both of them ahave <strong>Public</strong> access modifier and build action is set to <strong>Embedded Resource</strong></p>
  
  <p>Whole site is translated but i have problem with <strong>Attributes</strong></p>
  
  <pre><code>[Required]
  [LocalizedDisplayName("UserName", NameResourceType = typeof(App_GlobalResources.Strings))]
  public string UserName { get; set; }
  </code></pre>
  
  <p>I think the problem is in this line from the link that i posted above:</p>
  
  <pre><code>meta.DisplayName = resourceManager.GetString(propertyName, culture);
  </code></pre>
  
  <p>GetString always return default value from <strong>Strings.resx</strong>.</p>
  
  <p><strong>culture</strong> is <strong>pl</strong> and <strong>propertyName</strong> is correct <strong>UserName</strong>, so returned value should be from Strings.<strong>pl</strong>.resx, not from Strings.resx.</p>
  
  <p>Please help me :)</p>