Darren
Darren

Reputation: 11021

How to use language files in MVC3?

right now I am typing out my messages in the controllers I use like this:

TempData["flashError"] = "There Was A Problem Updating Your Account, Please Try Again";

I would like to reference a key/value system such as:

TempData["flashError"] = Messages["accountProblem"];

Is there a certain way to do this so I can maintain my messages from a separate file? Can someone tell me best practice?

Upvotes: 2

Views: 488

Answers (2)

Omu
Omu

Reputation: 71288

to add to Darin's answer

there's a sample application that uses resource files for MUI

you can download it from here: http://prodinner.codeplex.com

it also has a code walkthrough pdf file

also, see it live: http://prodinner.aspnetawesome.com

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039508

You may take a look at the following guide. You'd basically externalize the messages into resource files for each language and then you could use the strongly typed class that is automatically generated by Visual Studio to access those strings in your code.

Upvotes: 4

Related Questions