Reputation: 32808
I have an application which I need to have work in more than one language. Can someone give me some pointers as to where I should start looking. For example can I decorate the fields in my models with different headings that could be used depending on the language in use?
My application also uses messages like this:
ModelState.AddModelError("username", "You must specify a username.");
How can I code these messages for different languages?
Upvotes: 0
Views: 609
Reputation: 101150
You can customize a ModelMetadataProvider
and a ModelValidatorProvider
just as I've done in Griffin.MvcContrib.
With my versions, this is all you need to get localization of models and validations working:
protected void Application_Start()
{
var stringProvider = new ResourceStringProvider(Resources.LocalizedStrings.ResourceManager);
ModelMetadataProviders.Current = new LocalizedModelMetadataProvider(stringProvider);
ModelValidatorProviders.Providers.Clear();
ModelValidatorProviders.Providers.Add(new LocalizedModelValidatorProvider(stringProvider));
}
More info: http://blog.gauffin.org/2011/09/easy-model-and-validation-localization-in-asp-net-mvc3/
(nuget packages will be available as soon as I've got the administration area working with embedded views)
Upvotes: 0
Reputation: 31033
here are some good reads
http://haacked.com/archive/2010/05/10/globalizing-mvc-validation.aspx
https://stackoverflow.com/q/2455409/413670
Upvotes: 2