我正在开发一个 .net 4.5 应用程序,它需要多语言支持多文化等。
以下是国家/语言的示例列表
- 俄罗斯/俄语
- 比利时/法语
- 比利时/荷兰
对于以上所有内容,有一个 CultureInfo 对象可以根据上述文化名称创建
- ru-ru
- fr-BE
- nl-BE
当用户进入该站点时,我将 Thread.CurrentThread.CurrentCulture 和 Thread.CurrentThread.CurrentUICulture 设置为使用上述名称创建的区域性,例如。
Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-BE", false)
Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl-BE", false)
以上所有名称都是有效的区域性名称。
不,但是我需要添加另一个文化名称,即俄罗斯的英语。但问题是代码 en-RU 无效,所以当我创建 new CultureInfo("en-RU", false)
时,我得到一个 CultureNotFoundException,因为 en-RU 无效。
在这种文化下,我希望围绕数字、日期等使用俄罗斯的格式等,但我希望网站上的语言是英语。是否可以为具有国家(俄罗斯)行为的无效文化名称创建自定义 CultureInfo 对象?
最佳答案
Is it possbile to create custom CultureInfo objects for invalid culture name
是的。
利用CultureAndRegionInfoBuilder
帮助创建自定义 CultureInfo
。 (注意。一旦您有了创建文化的代码,就可以将执行此操作的设置保存到 XML 中,然后加载,例如从资源中加载,这在运行时应该需要更少的代码。)
一个示例项目如何做到这一点,加上可下载的代码,可以 be found at CodeProject .这篇文章的一个重要说明是,即使这个类位于 System.Globalization
命名空间中,它在默认情况下不可用,引述:
We’ll start by referencing the assembly
sysglobl.dll
and add ausing
statement for the namespaceSystem.Globalization
.
关于c# - 为国家、语言组合创建自定义 CultureInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12916940/