【问题标题】:Aurelia Validation error messages DisplayName is not shown upAurelia 验证错误消息 DisplayName 未显示
【发布时间】:2018-06-15 08:46:42
【问题描述】:

我有一个 Translation.json 文件,其中定义了与应用程序相关的属性。

{
"firstName": "Vorname",
"First Name": "Vorname",
"lastName": "Nachname",
"Last Name": "Nachname",
"Experience": "Erfahrung",
"experience": "erfahrung",
"Country": "Land",
"Currency": "Währung",
"currency": "währung",
"country": "land",
"DefaultSelectValue": "--${$displayName} auswählen--",
"switchLanguage": "Sprache wechseln",
"youHaveErrors": "Es gibt Fehler!",
"allGood": "Alles in Ordnung!",
"latestValidationResult": "Aktuelles Validierungsergebnis",
"heading": "Validierungsergebnis" }

同样,我在 Validation.json 文件中放置了验证消息

{
"errorMessages": {
    "required": "${$displayName} fehlt!",
    "minLength": "Der ${$displayName} sollte mindestens ${$config.length} Zeichen lang sein",
    "matches": "${$displayName} ist nicht gültig",
    "email": "${$displayName} is not a valid email.",
 } }

并且默认命名空间是 Translation.json,现在当我运行应用程序时,验证消息不会显示 displayName。

HTML:

 <span class="help-block" repeat.for="errorInfo of ValueErrors">${errorInfo.error.message & t:{ns:'validation'}}</span>

TypesScript:

ValidationRules.ensure('value').displayName(this.i18n.tr(model.displayName, {ns:'translation'})).required()
                .minLength(model.minLength)
                .on(this.model); 

输出: ${$displayName} 感觉!

预期: Vorname fehlt!

errorMessages 应该在默认命名空间中声明还是我遗漏了什么?

【问题讨论】:

  • 您能否上传一个显示该问题的示例?如果没有一个真实的例子,很难弄清楚配置方面的事情
  • 谢谢,无论如何问题已解决。,在覆盖“getMessage”函数以查找自定义 json 文件以查找错误消息后,它开始按预期工作。
  • 您能否发布您的解决方案,以便其他有相同问题的人知道该怎么做?谢谢
  • @zewa666 我所做的只是明确指定在validation.json 文件中查找错误消息ValidationMessageProvider.prototype.getMessage = function (key) { const i18n = aurelia.container.get(I18N); const translation = i18n.tr(errorMessages.${key}, {ns:'validation'}); return this.parser.parse(translation); };
  • 请将此添加为答案并接受为答案

标签: display messages aurelia


【解决方案1】:

ValidationMessageProvider.prototype.getMessage = function (key) { const i18n = aurelia.container.get(I18N); 常量翻译 = i18n.tr(errorMessages.${key}, {ns:'validation'});返回 this.parser.parse(translation); };

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2020-06-20
  • 1970-01-01
  • 2022-06-20
  • 2016-06-21
  • 2016-07-05
  • 2017-01-06
  • 2018-11-05
  • 2019-06-11
  • 2020-08-06
相关资源
最近更新 更多