Sto appena iniziando a localizzare un'applicazione ASP.Net MVC. La maggior parte delle stringhe verrà definita nei file di risorse e recuperata tramite Matt's Localization Helpers. Altre stringhe devono essere memorizzate in un database.ASP.NET MVC: quando impostare Thread.CurrentThread.CurrentUICulture?
La mia domanda: Devo impostare CurrentUICulture
presto in cantiere richiesta e l'uso che in tutta l'applicazione, o utilizzare direttamente Request.UserLanguages[0]
in caso di necessità?
In questo momento Sto pensando che dovrei impostare CurrentUICulture
in Application_BeginRequest. L'implementazione sarebbe simile a questa:
protected void Application_BeginRequest(object sender, EventArgs e)
{
var cultureName = HttpContext.Current.Request.UserLanguages[0];
Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName);
}
È questo il posto migliore per impostare CurrentUICulture
ed è Request.UserLanguages[0]
il posto migliore per ottenere queste informazioni?
Aggiornamento:
Ariel's messaggio mi ha fatto capire che questo può essere definito senza codice, utilizzando web.config
<system.web>
<!--If enableClientBasedCulture is true, ASP.NET can set the UI culture and culture for a Web page automatically, based on the values that are sent by a browser.-->
<globalization enableClientBasedCulture="true" culture="auto:en-US" uiCulture="auto:en"/>
ottimo collegamento! Grazie. –
Questo metodo è ancora valido con l'arrivo di AsyncController nella versione recente di ASP.NET MVC? Perché tecnicamente potrebbero non essere eseguiti con lo stesso thread di 'Thread.CurrentThread'. –
Non fuori dalla scatola. Vedi http: // StackOverflow.it/questions/20601578/async-webapi-thread-currentculture –