0

我正在尝试在 .aspx.cs 页面的 Page_Load 中设置文化和文化 ui。我努力了

Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-CA");

CultureInfo ci = new CultureInfo("fr-CA");
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;

Culture = "fr-CA";
UICulture = "fr-CA";

但它们都不起作用。有谁知道如何设置文化和uiculture?

谢谢!

4

1 回答 1

0

我找到了解决方案:覆盖 InitializeCulture。这是我合并 cookie 并使用当前 cookie 设置页面语言时的样子。

protected override void InitializeCulture()
    {

        HttpCookie cookie = Request.Cookies["CurrentLanguage"];
        if (!IsPostBack && cookie != null && cookie.Value != null)
        {
            if (cookie.Value.ToString() == "en-CA")
            {
               // currently english
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-CA");
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-CA");
                base.InitializeCulture();
            }
            else
            {
               //currently french
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-CA");
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-CA");
                base.InitializeCulture();
            }
        }
    }
于 2014-09-23T19:00:17.267 回答