加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何在运行时更改CurrentCulture?

发布时间:2020-12-15 17:41:48 所属栏目:百科 来源:网络整理
导读:我需要根据每个文化的资源文件在运行时改变文化. 根据两种文化,我需要以我的形式更改控件的属性 其中指定了.resx文件 resorces1.aspx.resx // default resorces1.aspx.he-IL.resx // hebrew culture 我可以使用回退资源加载页面,或者通过pageload给出UICultu
我需要根据每个文化的资源文件在运行时改变文化.

根据两种文化,我需要以我的形式更改控件的属性
其中指定了.resx文件

resorces1.aspx.resx // default 
resorces1.aspx.he-IL.resx // hebrew culture

我可以使用回退资源加载页面,或者通过pageload给出UICulture =“he-IL”值,并且可以使用所需的资源加载页面.

问题是我需要在运行时进行这些更改.

1 ..在我更改一个按钮点击事件的值后

btn_change_Click(....)
    {
        UICulture = "he-IL" ;
    }

它仍然返回到初始化值“en-US”

在运行时如何对UICulture进行更改?

2 ..如果我不知道它是“en-US”,怎么能引用后备资源文件?

解决方法

改变当前的UI文化:
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("he-IL");

或者更好的是,检索他的IL-IL文化的缓存的只读实例:

System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("he-IL");

At run time,ASP.NET uses the resource file that is the best match for the setting of the CurrentUICulture property. The UI culture for the thread is set according to the UI culture of the page. For example,if the current UI culture is Spanish,ASP.NET uses the compiled version of the WebResources.es.resx file. If there is no match for the current UI culture,ASP.NET uses resource fallback. It starts by searching for resources for a specific culture. If those are not available,it searches for the resources for a neutral culture. If these are not found,ASP.NET loads the default resource file. In this example,the default resource file is WebResource.resx.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读