views:

97

answers:

1

I want to localize / globalize the fields on my Login page. I am using ASP.NET MVC 3 Preview 1 with the razor view engine.

Some background

First of all, i've set my routing and added a localization attribute handler so that I can write http://mysite.com/{lang}/{controller}/{action}/{id}. Now this works all good. In my Viewsfolder I've added a Home folder with a corresponding App_LocalResources so far so good. I can even add language files for different languages such as Index.resx and Index.sv.resx`.

The problem

Having a file called Account.resx in the root's App_GlobalResources I of course imagine I should be able to access that from my pages. In my AccountModel.cs ( which came with the installation / template project ) I have added the following to the LogOnModel

public class LogOnModel
{
    [Required]
    [Display(Name = "UserName", ResourceType = typeof(Account))]
    public string UserName { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Password", ResourceType = typeof(Account))]
    public string Password { get; set; }

    [Display(Name = "RememberMe", ResourceType = typeof(Account))]
    public bool RememberMe { get; set; }
}

I have two files in my App_GlobalResource

  • Account.resx
  • Account.sv.resx

And it does in fact take the text from the english / default file. But when I append /sv/ to my URL or even ensure that the culture is swedish, it doesn't change the language to what is in my `Account.sv.resx.

An example of what could be in the LogOn.cshtml

<div class="editor-label">
    @Html.LabelFor(m => m.UserName)
</div>

Any ideas?

A: 

Not MVC 3 specific, however this may help

http://geekswithblogs.net/shaunxu/archive/2010/05/06/localization-in-asp.net-mvc-ndash-3-days-investigation-1-day.aspx

Tanzy
I've seen this but that doesn't help me much since `DisplayAttribute` isn't working properly in MVC 3.
Filip Ekberg
Never mind, the build action for one resource file was wrong. Thanks.
Filip Ekberg