0

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,

2 Answers 2

2

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);            
}
Sign up to request clarification or add additional context in comments.

2 Comments

I can have MyClass, MyClassShoes, MyClassCar, .... but all the time the same properties.
So you add a dictionary to each of them
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.