I'm using localization for my ASP.NET Page with a database.
Everything is working fine, a language Dictionary is in the ViewBag, and it's just working for everything, except the DisplayName in the ViewModels.
This is how I'm using translation in the Views:
namespace Helpers
{
public static class LocalizationHelper
{
/// <summary>
/// Returns the translation for the term
/// </summary>
public static string Translate(this HtmlHelper helper, Term term)
{
Dictionary<string, string> dic = helper.ViewContext.Controller.ViewBag.LangDict;
Dictionary<string, string> fallbackDic = helper.ViewContext.Controller.ViewBag.StandardLangDict;
string trans = "";
if (dic.TryGetValue(term.ToString(), out trans))
return trans;
else if (fallbackDic.TryGetValue(term.ToString(), out trans))
{
return trans;
//exception trans not available for this lang
//return fallback language
}
else
return "Translation not set";
}
}
But I cant use this for the ViewModel because I'cant pass the HTMLHelper Attribute. And if i decide to write another method like:
public static string Translate(Term term)
The Viewbag cant work any more. Term is an Enumeration.
Now I have no idea how to get the Data from the Viewbag into the ViewModel.