I have a very unusual issue that has me completely stumped. We have a multilingual website so we employ Resource files. However, every piece of text on our Views that has been burned in like <a href="#">@TextResources.my_key</a>
will be localized to a random culture. This happens only on my Azure deployment, I cannot reproduce locally.
Adding to the mystery is that there is a lone bit of text that ALWAYS respects my change of culture. That text gets retrieved via a method call:
<a href="#">@.ConfigUtils.getTerms()</a>
Method is:
public static string getTerms()
{
string key = GetKeyFromDb(CONSTANTS.TERMS);
if (!string.IsNullOrEmpty(key))
{
return TextResources.ResourceManager.GetString(key);
I'm still reading from our resource file, but in this context, it is being localized as desired! Is the culture being applied after the resource file is read in the view, but before this method is called?!
All our controllers inherit from a base controller, where we override OnActionExecuting()
to apply our culture:
protected override void OnActionExecuting(ActionExecutingContext filterContext) {
ContextModel ctx = (ContextModel) Session["ContextModel"];
// Set the correct localization according to the value set by the user
if (ctx != null && ctx.UserLanguageId != null){
Thread.CurrentThread.CurrentUICulture = new CultureInfo (ctx.UserLanguageId);
Thread.CurrentThread.CurrentCulture = new CultureInfo(ctx.UserLanguageId);
}
}
Before I start moving the culture management code to different spots and re-deploying to Azure in hopes that resolves the issue, I'm hoping that someone has a thought as to why only the text retrieved via the method call gets localized.
OnActionExecuting()
is executed before the action, so I had thought this would be the appropriate spot to put culture management code. Is there somewhere else that would be better?
UPDATE
It looks like this issue presents itself after a deployment, but can be resolved by restarting the cloud service.
UPDATE 2
Per @RichardSchneider's request, the auto-generated TextResources
code is as follows:
public static string my_key{
get {
return ResourceManager.GetString("my_key", resourceCulture);
}
}