【问题标题】:ASP.NET Localizations and User definded languageASP.NET 本地化和用户定义的语言
【发布时间】:2009-07-08 16:02:41
【问题描述】:

我正在开发一个 asp.net Web 应用程序,其中一项要求是用户必须能够选择他们想要的语言。我正在使用 Resx 文件来存储本地人。我的问题是每次加载页面时我是否需要更改线程的 CurrentCulture,或者有没有办法在登录用户从一个页面移动时自动处理它到下一个。

【问题讨论】:

    标签: asp.net globalization resx


    【解决方案1】:

    是的,我相信您每次都需要设置它。更糟糕的是,您必须重写 Page 类的 InitializeCulture 方法。我创建了一个 SitePage,我的项目中的所有页面都继承自而不是 Page 来执行此操作。

    public class SitePage : Page
    {
        protected override void InitializeCulture()
        {
            base.InitializeCulture();
    
            // Set both the CurrentCulture (for currency, date, etc) conversion, and the CurrentUICulture for resource file lookup.
            Thread.CurrentThread.CurrentCulture = whatever;
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
        }
    

    }

    延伸阅读:http://msdn.microsoft.com/en-us/library/bz9tc508.aspx

    【讨论】:

    • 在 Global.asax 中的 Application_BeginRequest 上做这件事怎么样,因为它会在其他所有东西被调用之前被调用
    • 我刚刚在反射器中打开了 Page 类,InitializeCulture 只是一个虚拟方法,所以它只是为您提供了一个设置文化的地方,所以在 Application_BeginRequest 中执行它应该可以工作。如果没有,我将发布其他方式
    • 我知道 不能使用 Application_BeginRequest 是有原因的,但我不记得这是否是全局限制。
    猜你喜欢
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-17
    • 2018-12-13
    相关资源
    最近更新 更多