[英]Aurelia Validation error messages DisplayName is not shown up
我有一個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>
類型腳本:
ValidationRules.ensure('value').displayName(this.i18n.tr(model.displayName, {ns:'translation'})).required()
.minLength(model.minLength)
.on(this.model);
輸出: ${$displayName} fehlt!
預期: Vorname fehlt!
是應該在默認命名空間中聲明 errorMessages 還是我遺漏了什么?
ValidationMessageProvider.prototype.getMessage = function (key) { const i18n = aurelia.container.get(I18N); const translation = i18n.tr(errorMessages.${key}, {ns:'validation'}); 返回 this.parser.parse(translation); };
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.