Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot get localization working in MVC 4
    primarykey
    data
    text
    <p>I've been trying to follow the blog post found <a href="http://afana.me/post/aspnet-mvc-internationalization-part-2.aspx" rel="nofollow">here</a>. I've added a new assembly that hosts my resource files (I used a separate assembly as the resources may need to be shared between multiple projects). I have added the following to my web.config:</p> <pre><code> &lt;system.web.webPages.razor&gt; &lt;host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt; &lt;pages pageBaseType="System.Web.Mvc.WebViewPage"&gt; &lt;namespaces&gt; &lt;add namespace="System.Web.Mvc" /&gt; &lt;add namespace="System.Web.Mvc.Ajax" /&gt; &lt;add namespace="System.Web.Mvc.Html" /&gt; &lt;add namespace="System.Web.Routing" /&gt; &lt;add namespace="MyResources.Resources"/&gt; &lt;!-- New entry for resources --&gt; &lt;/namespaces&gt; &lt;/pages&gt; &lt;/system.web.webPages.razor&gt; </code></pre> <p>And I have gone though and added resource strings to a few files for testing purposes. Now the problem that I seem to be running into, is that I cannot set the resource to be anything other than the default. So for example, in the generated resource file designer there is the following:</p> <pre><code> /// &lt;summary&gt; /// Looks up a localized string similar to Log in was unsuccessful. Please correct the errors and try again.. /// &lt;/summary&gt; public static string Account_LoginUnsuccessful { get { return ResourceManager.GetString("Account_LoginUnsuccessful", resourceCulture); } } </code></pre> <p>If I set a breakpoint in this method, <code>resourceCulture</code> is NEVER anything but null. Even though I have tried the following:</p> <p>In Global.asax.ca:</p> <pre><code> protected void Application_AcquireRequestState(object sender, EventArgs e) { var culture = new System.Globalization.CultureInfo("fr"); // Modify current thread's cultures Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture.Name); } // End of Application_AcquireRequestState </code></pre> <p>In a base mvc controller that all of my other controller inherit:</p> <pre><code> protected override void Initialize(System.Web.Routing.RequestContext requestContext) { SetCulture(requestContext.HttpContext.Request); base.Initialize(requestContext); } protected override void ExecuteCore() { SetCulture(Request); base.ExecuteCore(); } protected override void Execute(System.Web.Routing.RequestContext requestContext) { SetCulture(requestContext.HttpContext.Request); base.Execute(requestContext); } protected override IAsyncResult BeginExecute(System.Web.Routing.RequestContext requestContext, AsyncCallback callback, object state) { SetCulture(requestContext.HttpContext.Request); metrics = Metrics.BeginTimer(); return base.BeginExecute(requestContext, callback, state); } private void SetCulture(HttpRequestBase Request) { string cultureName = "fr"; // Validate culture name cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe // Modify current thread's cultures Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName); Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; } </code></pre> <p>Now, to my understanding setting the threading current culture should be causing my resource files culture to change. I can't seem to get this working of the life of me (hence why I have tried setting the cultire in about ten different locations).</p> <p>Any suggestions on what I am doing wrong here?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload