【问题标题】:Localize Validation Messages from XDocument.Validate()本地化来自 XDocument.Validate() 的验证消息
【发布时间】:2012-10-23 15:42:47
【问题描述】:

如何本地化从 XDocument.Validate() 返回的消息?它似乎为我返回了英文信息。

下面的 sn-p 写入消息“未声明‘UndeclaredElement’元素。”但这对非英语用户没有帮助。

[Test]
public void Test()
{
    var xDocument = XDocument.Parse("<UndeclaredElement/>");

    var stringReader =
        new StringReader("<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'/>");

    var xmlSchema = XmlSchema.Read(XmlReader.Create(stringReader), (o, e) => Console.WriteLine(e.Message));

    var schemaSet = new XmlSchemaSet();
    schemaSet.Add(xmlSchema);

    xDocument.Validate(schemaSet, (o, e) =>
    {
        Console.Out.WriteLine(e.Message);
    });
}

【问题讨论】:

  • 您当前的文化设置是什么?
  • System.Threading.Thread.CurrentThread.CurrentCulture 显示在en-us下运行
  • 这就是邮件是英文的原因...

标签: .net validation localization xsd linq-to-xml


【解决方案1】:

要本地化来自 XDocument.Validate() 的消息,必须做两件事:

  1. 将当前文化设置为所需的语言:

    System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-fr");
    System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-fr");
    
  2. 安装 .net 框架语言包(在我的例子中,版本 4 的包是 found here

感谢约翰的快速指点..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多