在 Windows XP 上使用 CultureAndRegionInfoBuilder 从 XML 加载区域性时出现问题
我有一个将使用几种不同文化的 Web 应用程序,其中之一是 es-US(美国西班牙语)。但是,Windows XP 不支持 es-US 文化。为了解决这个问题,我发现应该能够使用 CultureAndRegionInfoBuilder。因此,我研究了 CultureAndRegionInfoBuilder 并执行了以下操作:
在 Windows 7 计算机上,我将区域性 es-US 保存到 XML 文件中,如下所示:
private static void SaveCultureToFile() {
try {
CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = null;
Console.WriteLine("Saving es-US to xml disc...\n");
cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder("es-US", CultureAndRegionModifiers.Replacement);
// Populate the new CultureAndRegionInfoBuilder object with culture information.
CultureInfo ci = new CultureInfo("es-US");
cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(ci);
cultureAndRegionInfoBuilder.Save("es-US.xml");
}
然后,我有一个函数可以读取 xml,并将区域性注册到系统中,如下所示如下所示:
private static void RegisterCultureFromDisk() {
try {
CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = null;
Console.WriteLine("Loading es-US from xml...\n");
cultureAndRegionInfoBuilder = CultureAndRegionInfoBuilder.CreateFromLdml("es-US.xml");
Console.WriteLine("Culture is registred to the system...\n");
cultureAndRegionInfoBuilder.Register();
Console.WriteLine("The following culture has been registred to the system: \n");
}
因此,我在 Windows 7 计算机上使用 SaveCultureToFile 方法运行该程序,从而将区域性保存到 xml 文件中。然后,我将文件复制到 Windows XP 计算机,并运行相同的程序,但运行 RegisterCultureFromDisk() 方法。但程序在 CultureAndRegionInfoBuilder.CreateFromLdml("es-US.xml") 方法中失败,并表示:
“文化名称‘es-us’不是 支持”
好吧,这正是我尝试从 xml 加载文化并将其注册到系统中的原因。
有谁知道我做错了什么,或者我如何在 Windows XP 上创建 es-us 文化机器?
谢谢!
I have a web application that will use a few different cultures, one of which is es-US (Spanish United States). However, Windows XP do not have any support for the culture es-US. To work around the problem, I've found out that one is supposed to be able to use the CultureAndRegionInfoBuilder. So I looked into CultureAndRegionInfoBuilder and did the following:
On a Windows 7 machine I saved the culture es-US to an XML-file, as follows:
private static void SaveCultureToFile() {
try {
CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = null;
Console.WriteLine("Saving es-US to xml disc...\n");
cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder("es-US", CultureAndRegionModifiers.Replacement);
// Populate the new CultureAndRegionInfoBuilder object with culture information.
CultureInfo ci = new CultureInfo("es-US");
cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(ci);
cultureAndRegionInfoBuilder.Save("es-US.xml");
}
Then I have a function that reads the xml, and registeres the culture into the system, as follows:
private static void RegisterCultureFromDisk() {
try {
CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = null;
Console.WriteLine("Loading es-US from xml...\n");
cultureAndRegionInfoBuilder = CultureAndRegionInfoBuilder.CreateFromLdml("es-US.xml");
Console.WriteLine("Culture is registred to the system...\n");
cultureAndRegionInfoBuilder.Register();
Console.WriteLine("The following culture has been registred to the system: \n");
}
So I run the program using the SaveCultureToFile method on a Windows 7 machine, thus saving the culture to an xml file. Then I copy the files to the Windows XP machine, and runs the same program but the RegisterCultureFromDisk() method. But the program fails in the CultureAndRegionInfoBuilder.CreateFromLdml("es-US.xml") method saying that:
"Culture name 'es-us' is not
supported"
Well, thats exactly why I'm trying to load the culture from the xml and registering it into the system.
Do any one know what I'm doing wrong, or how I can create the es-us culture at the Windows XP machine?
Thanx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这是一个古老的问题,但我最近遇到了这个问题并设法实际解决了它。
事实证明,如果您只是使用要导入的区域性名称创建临时区域性,则
CreateFromLdml
方法可能会被欺骗以加载不存在的区域性。然后,您可以取消注册临时区域性并注册刚刚加载的区域性。我制作了一个用于导出/导入区域性的简单命令行工具,我们已成功使用该工具添加了在 Azure 上部署新服务器时所需的一些模糊的缺失区域性。
如果您需要它 - 可以获取源代码和更深入的解决方案描述 这里。
I know this is an ancient question, but I've recently run into this issue and managed to actually solve it.
Turns out the
CreateFromLdml
method can be tricked into loading a non-existing culture if you just create a temporary culture using the name of the one you want to import. Then you can unregister the temporary culture and register the one you just loaded instead.I've made a simple command-line tool for exporting/importing cultures, which we've successfully used to add in some obscure missing cultures we needed when deploying new servers on Azure.
If you need it - the source code and a more in depth description of the solution is available here.
来自 MSDN:
我怀疑这可能是您问题的原因...您对此计算机有管理员权限吗?
From MSDN:
I suspect it might be the cause of your problem... do you have admin rights on this machine ?