title: ASP.Net MVC model translate language for display
body: <p>I am working on multi-language enabled mvc application. I have a translation table in database, which I bring on application start and save it in application memory. </p>
  
  <p>The database structure is {TextId, LanguageId, Translation}. TextId is assigned to each UI element (like label, validators, dropdown list text, etc.). There is an admin interface to manage the translation text.</p>
  
  <p>I want to know what is a good way to show translated text on UI, and where is the best place to do the actual translation. I do not want to use the resource manager, since the database is being used in other Asp &amp; Asp.Net webforms applications.</p>
  
  <p>Here is the model (for example)</p>
  
  <pre><code>public class UserLoginModel
  {
      [Required(ErrorMessage="ER001")]
      [Range(6,10,ErrorMessage="ER002")]
      [Display(Description="TX001", Name="TX002")]
      public string LoginId { get; set; }
  
      [Required(ErrorMessage="ER003"), DataType(DataType.Password)]
      public string Password { get; set; }
  
      public bool RememberMe { get; set; }
  }
  </code></pre>
  
  <p>Language Id will be in Session["LanguageId"], and TranslationText is in Application variable.</p>
  
  <p>Models reside in separate project, hence there is not direct access to session, but I can use DI (don't know whether it is a good practice!)</p>
  
  <p>Here are following things I was considering:</p>
  
  <ol>
  <li><p>Write Html helper extension like @Html.TranslateText("TX001"). I started with this method, but soon realized that @Html.ValidationMessage accepts only one message, irrespective of multiple validator attributes on property. I cannot use EditorFor templates either.</p></li>
  <li><p>Use javascript to replace text ids with appropriate messages</p></li>
  <li><p>Use reflection on model and replace text ids for attributes.</p></li>
  </ol>
  
  <p>I am leaning towards option 3, by extending ModelMetadataProvider, or writing action filter attribute, or in EditorForModel template.</p>
  
  <p>I am very confused on how to proceed. I am still in process of learning MVC. Hence. I would like to ask experts on how to handle this problem in best possible way.</p>
  
  <p>Thanks,</p>