Reputation: 19933
I read some post about ASP.NET MVC application, but I found only article on static text. Which is the strategy when the content of a dropdown must change with the language too ?
I have a IList<MyClass>()
where MyClass
is
public MyClass(){
public int Id { get; set; }
public string Code { get; set; }
public string EN { get; set; }
public string FR { get; set; }
public string ES { get; set; }
}
depending the language of my UI, I have to use EN (English), FR (French), .. values.
Thanks,
Upvotes: 0
Views: 502
Reputation: 443
In our case I suggest to use EF Code-First (http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx) for your business models. I'ts simplest.
Use metadata attributes to localize property names and validation messages (http://afana.me/post/aspnet-mvc-internationalization.aspx).
Use database stored dictionaries to map entities codes to human readable localized names.
If you need simple lists, use localized string resources to define comma separated list and string.Split() to make a list of items.
Upvotes: 2
Reputation: 31202
You could use this approach :
public class LocalizableModel
{
private Dictionary<string,string> labels = new Dictionary<string,string> ();
public string LocalizedLabel
{
get { return this.labels[Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName]; }
}
}
And in Global.asax
protected void Session_Start(Object Sender, EventArgs e)
{
// set the correct culture, using cookie, querystring, whatever
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(1033);
}
Upvotes: 2