InitializeCulture()的每一个页面上有必要吗? [英] InitializeCulture() on every single page necessary?

查看:354
本文介绍了InitializeCulture()的每一个页面上有必要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要本地化的Web表单的网站。我的意思是,它是局部的,我只需要根据域设置正确的语言。是这样的:

 保护覆盖无效InitializeCulture()
{
    VAR I = Request.Url.Host.ToLower();
    VAR域= i.Substring(i.Length  -  2,2);
    如果(域==SE)
    {
        Thread.CurrentThread.CurrentCulture =
            CultureInfo.CreateSpecificCulture(SV-SE);
        Thread.CurrentThread.CurrentUICulture =新
            的CultureInfo(SV-SE);
    }
    否则,如果(域==DK)
    {
        Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(DA-DK);
        Thread.CurrentThread.CurrentUICulture =新
            的CultureInfo(DA-DK);
    }
}
 

我的第一个问题是:难道我真的要叫 InitializeCulture()合适的资源加载 <每一个网页? / P>

第二个问题。我也有一些全球性的资源。如果是肯定的第一个问题,他们将被设置正确呢?

诗。 的UICulture =自动 enableClientBasedCulture =真正的在webconfig是不够的(长的故事)。

解决方案

是的。你在做什么符合了 Microsoft推荐的方法。 而且,由于你的榜样决定用什么语言来使用基于URL,那么每一个页面请求可能需要不同的语言,所以你只是无法避免这样做,为每个单独的页面。

根据你的第二个问题,是的,所有的资源加载依赖于的CurrentCulture 。因此,本地和全球的资源会受你的文化初始化。

I have a web forms site that needs to be localized. I mean, it is localized, I just need to set the right language according to the domain. Something like:

protected override void InitializeCulture()
{
    var i = Request.Url.Host.ToLower();
    var domain = i.Substring(i.Length - 2, 2);
    if (domain == "se")
    {
        Thread.CurrentThread.CurrentCulture =
            CultureInfo.CreateSpecificCulture("sv-SE");
        Thread.CurrentThread.CurrentUICulture = new
            CultureInfo("sv-SE");
    }
    else if (domain == "dk")
    {
        Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture("da-DK");
        Thread.CurrentThread.CurrentUICulture = new
            CultureInfo("da-DK");
    }
}

My first question is: Do I really have to call InitializeCulture() on every single page for the right resources the be loaded?

Second question. I also have some global resources. If yes to first question, will they be set correctly as well?

Ps. uiCulture="auto" and enableClientBasedCulture="true" in webconfig will not be sufficient (long story).

解决方案

Yes. What you are doing complies with the Microsoft-recommended method. And since your example determines what language to use based on the URL, then each page request may require a different language, so you just couldn't avoid doing this for each individual page.

As per your second question, yes, all resource loading depends on CurrentCulture. So both local and global resources will be affected by your culture initialization.

这篇关于InitializeCulture()的每一个页面上有必要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆