本文介绍了创建自定义的CultureInfo的国家,语言组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作需要被MULT语言支持多文化等一个.NET 4.5应用程序。

下面是国家的样本列表/语言

  • 在俄罗斯/俄罗斯
  • 在比利时/法国
  • 在比利时/荷兰

有关所有上述,存在可以基于上述培养名称创建一个CultureInfo对象

  • RU-RU
  • FR-BE
  • NL-BE

当用户进入网站,我设置Thread.CurrentThread.CurrentCulture和Thread.CurrentThread.CurrentUICulture与上述名称,例如创造的文化。

  Thread.CurrentThread.CurrentCulture =新的CultureInfo(NL-BE,FALSE)
Thread.CurrentThread.CurrentUICulture =新的CultureInfo(NL-BE,FALSE)
 

以上所有的名称是有效的区域性名称。

没有,但是我需要添加另一种文化的名字,英语语言,在俄罗斯。但问题是code EN-RU是无效的,所以当我创建新的CultureInfo(EN-RU,FALSE)我得到一个CultureNotFoundException为恩RU是无效的。

通过这种文化,我想俄罗斯各地的数字,日期等格式等等,但我想在网站上的语言是英语。难道possbile创建自定义的CultureInfo与国(俄罗斯)?的行为无效的区域性名称对象

解决方案

是的。

请使用<$c$c>CultureAndRegionInfoBuilder以帮助创建自定义的CultureInfo 。 (特别注意:一旦你有code,以创造一种文化,设置要做到这一点,可以保存为XML,然后加载,例如,从资源,应该在运行时需要较少的code)

I am working on a .net 4.5 application that needs to be mult lingual supporting multi cultures etc.

The following is sample list of Countries/Languages

  • Russia / Russian
  • Belgium / French
  • Belgium / Dutch

For all the above, there is a CultureInfo object that can be created based upon the above culture names

  • ru-RU
  • fr-BE
  • nl-BE

When the user enters the site, I set Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture to the culture created with the above names eg.

Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-BE", false)
Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl-BE", false)

All the above names are valid culture names.

No however I need to added another culture name, language of English in Russia. But the problem is the code en-RU is not valid so when I create new CultureInfo("en-RU", false) I get a CultureNotFoundException as en-RU is not valid.

With this culture, I want the formatting etc of Russia around numbers, dates etc, but I want the language on the site to be English. Is it possbile to create custom CultureInfo objects for invalid culture names with the behaviour of the country (Russia)?

解决方案

Yes.

Make use of CultureAndRegionInfoBuilder to help create the custom CultureInfo. (NB. once you have code to create a culture, the settings to do this can be saved to XML and then loaded, eg. from a resource, which should need less code at runtime.)

这篇关于创建自定义的CultureInfo的国家,语言组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:06