How to handle localization of POCO enums in asp.net mvc - best practice
Let me preface this by saying I'm fairly new to ASP.NET MVC. I've decided to use Telerik's ASP.NET MVC extensions http://www.telerik.com/products/aspnet-mvc.aspx
I would like to hear from you a recommendation how to handle the following situation.
I have a model POCO class called Print.
public class Print
{
public int Id { get; set; }
public DateTime Date { get; set; }
public PrintStatus Status { get; set; }
}
I'm passing collection of objects of this class to view in order to show it on the Grid. The view looks as follows:
...
@{
var grid = Html.Telerik().Grid(Model)
.Name("Grid")
.DataKeys(keys =>
{
keys.Add(o => o.Id);
})
.Columns(columns =>
{
columns.Bound(o => o.Date).Title(ModRes.Print.Date);
columns.Bound(o => o.Status)).Title(ModRes.Print.Status);
})
.DataBinding(dataBinding =>
{
dataBinding.Server().Select("Index", "Print")
.Insert("Insert", "Print")
.Update("Save", "Print")
.Delete("Delete", "Print");
})
.Sortable()
.Pageable()
.Filterable()
.Groupable()
.Footer(true);
}
@grid
...
The relevant line is this:
columns.Bound(o => o.Status)).Title(ModRes.Print.Status);
As you can see the grid is going 开发者_StackOverflowto use Status property, which is an enumeration. However this leads to a question on how to localize it i.e. How to show different translations of the Status property.
My thought is to inherit from Print class and allow additional string property which would hold the tranlation and alow to create Print class from it in the background (I heard that Automapper library might be helpful with this). This, however, seems like an ugly solution for me.
Thank you for your input.
Create an instance of a ResourceManager and use the print status as a lookup key to a resource file. Or if you are localizing in a database do the same thing to the DB. If you need it to be more specific of a key then add a prefix of some sort.
This link might help:
http://msdn.microsoft.com/en-us/library/c6zyy3s9.aspx
精彩评论