开发者

Localization works on localhost but not in production enviroment

I have this website with english and portuguese support. In localhost everything works fine and the content is translated based on the querystring parameter named "lang".

This chunk of code makes the trick in every page:

protected override void InitializeCulture()
{
     SetCulture();
}

private void SetCulture()
{
    var logger = Util.GetLogger();

    string lang = Request.QueryString["l开发者_开发知识库ang"];
    if (string.IsNullOrEmpty(lang)) { lang = "pt-br"; }

    string sessionLang = (string)Session["lang"];


    if (sessionLang != lang)
    {
        Session["lang"] = lang;
    }

    logger.Log(string.Format("Culture {0} found",lang));

    UICulture = lang;
    Culture = lang;

    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);

    logger.Log(string.Format("Cultura {0} set", lang));

    base.InitializeCulture();
}

Thanks to the logger I can say for sure that this method is called in both cases (production and localhost).

I have two resources files in App_GlobalResources folder: -WebSitemapGlobal.en-us.resx; -WebSitemapGlobal.resx;

Any clue?

Thanks in advance.


I can see you are little confused about localization in .NET.

First, if WebSiteMapGlobal.resx is in Brazilian Portuguese, there is no need to specify pt-br as culture, since the culture is neutral

Probably, the problem is due to calling base.InitializeCulture() after setting language. You should also have posted a little log about your page execution.

Also, a software engineering tip: you should call base.InitializeCulture() from void InitializeCulture() after SetCulture(). The result is identical (I just asked you to remove that call anyway) but it's a very good practice to call a base method from its override.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜