Culture does not apply on a multilingual site

I have a very unusual problem that completely surpassed me. We have a multilingual website, so we use resource files. However, every piece of text in our minds that was burnt like <a href="#">@TextResources.my_key</a>will be localized in a random culture. This only happens when deploying Azure, I cannot play locally.

Adding to the riddle is that there is a single bit of text that ALWAYS respects my cultural change. This text is retrieved using a method call:

<a href="#">@.ConfigUtils.getTerms()</a>

Method:

public static string getTerms()
{
    string key = GetKeyFromDb(CONSTANTS.TERMS);
    if (!string.IsNullOrEmpty(key))
    {
        return TextResources.ResourceManager.GetString(key);

I am still reading from our resource file, but in this context it is localized as desired! Is the culture used after reading the resource file in the view, but before calling this method ?!

, OnActionExecuting() :

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);
    }
}

Azure , , , - , , , .

OnActionExecuting() , , . - ?

UPDATE

, , .

2 @RichardSchneider TextResources :

public static string my_key{
    get {
        return ResourceManager.GetString("my_key", resourceCulture);
    }
}
+4
3

- , . , URL-, . URL- , :

?

// ID = 123 & LANG =

, :

TextResources.Culture = new CultureInfo("de");

:

[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
public class TextResources
{
public static CultureInfo Culture { get; set; }

, , , . , , Azure . , .

, , :

public static string getTerms()
{
    string key = GetKeyFromDb(CONSTANTS.TERMS);
    if (!string.IsNullOrEmpty(key))
    {
         return TextResources.ResourceManager.GetString(key);
0

:


, async .ConfigureAwait(false) . awiat ( text/renders) , , , .

- .ConfigureAwait(false), , , -sensetive calls.

: , ASP.Net,

  • set CurrentUICulture
  • , Culture null.

, , , - Culture , "" .

Culture - null.

+2

, ResourceManager, .

TextResources.my_key , ( ) .

Automatically generated code for my_keytransfers culture information to ResourceManager.GetString. I suggest modifying the auto-generator to use only one argument overload to create:

public static string my_key{
get {
    return ResourceManager.GetString("my_key");
}
}

If this is not possible, you need to OnActionExecutinginstall resource_culture. resource_cultureThere must be a local stream variable for this.

+1
source

All Articles