How do you localize/internationalize an MVC Controller when using a SQL based localization provider?
        Posted  
        
            by EBarr
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by EBarr
        
        
        
        Published on 2010-03-16T22:26:52Z
        Indexed on 
            2010/03/16
            22:31 UTC
        
        
        Read the original article
        Hit count: 423
        
Hopefully this isn't too silly of a question. In MVC there appears to be plenty of localization support in the views. Once I get to the controller, however, it becomes murky.
- Using meta:resourcekey="blah" is out, same with <%$ Resources:PageTitle.Text%>.
 - ASP.NET MVC - Localization Helpers -- suggested extensions for the Html helper classes like 
Resource(this Controller controller, string expression, params object[] args). Similarly, Localize your MVC with ease suggested a slightly different extension likeLocalize(this System.Web.UI.UserControl control, string resourceKey, params object[] args) 
None of these approaches works while in a controller. I put together the below function and I'm using the controllers full class name as my VirtualPath. But I'm new to MVC and assume there's a better way.
    public static string Localize (System.Type theType, string resourceKey, params object[] args) {
         string resource = (HttpContext.GetLocalResourceObject(theType.FullName, resourceKey) ?? string.Empty).ToString();
         return mergeTokens(resource, args);
    }
Thoughts? Comments?
© Stack Overflow or respective owner