fix: add translations to the type of validation message (#2226)
This commit is contained in:
parent
8e450423da
commit
3dbee0c9b0
41 changed files with 335 additions and 8 deletions
5
.changeset/calm-chicken-obey.md
Normal file
5
.changeset/calm-chicken-obey.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@lion/ui': patch
|
||||
---
|
||||
|
||||
[FeedbackValidation] add a translation of the validation feedback type to the beginning of the validation message
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
export const localizeNamespaceLoader = /** @param {string} locale */ locale => {
|
||||
switch (locale) {
|
||||
case 'bg-BG':
|
||||
return import('@lion/ui/form-core-translations/bg-BG.js');
|
||||
case 'bg':
|
||||
return import('@lion/ui/form-core-translations/bg.js');
|
||||
case 'cs-CZ':
|
||||
return import('@lion/ui/form-core-translations/cs-CZ.js');
|
||||
case 'cs':
|
||||
return import('@lion/ui/form-core-translations/cs.js');
|
||||
case 'de-DE':
|
||||
return import('@lion/ui/form-core-translations/de-DE.js');
|
||||
case 'de':
|
||||
return import('@lion/ui/form-core-translations/de.js');
|
||||
case 'en-AU':
|
||||
return import('@lion/ui/form-core-translations/en-AU.js');
|
||||
case 'en-GB':
|
||||
return import('@lion/ui/form-core-translations/en-GB.js');
|
||||
case 'en-US':
|
||||
return import('@lion/ui/form-core-translations/en-US.js');
|
||||
case 'en-PH':
|
||||
case 'en':
|
||||
return import('@lion/ui/form-core-translations/en.js');
|
||||
case 'es-ES':
|
||||
return import('@lion/ui/form-core-translations/es-ES.js');
|
||||
case 'es':
|
||||
return import('@lion/ui/form-core-translations/es.js');
|
||||
case 'fr-FR':
|
||||
return import('@lion/ui/form-core-translations/fr-FR.js');
|
||||
case 'fr-BE':
|
||||
return import('@lion/ui/form-core-translations/fr-BE.js');
|
||||
case 'fr':
|
||||
return import('@lion/ui/form-core-translations/fr.js');
|
||||
case 'hu-HU':
|
||||
return import('@lion/ui/form-core-translations/hu-HU.js');
|
||||
case 'hu':
|
||||
return import('@lion/ui/form-core-translations/hu.js');
|
||||
case 'it-IT':
|
||||
return import('@lion/ui/form-core-translations/it-IT.js');
|
||||
case 'it':
|
||||
return import('@lion/ui/form-core-translations/it.js');
|
||||
case 'nl-BE':
|
||||
return import('@lion/ui/form-core-translations/nl-BE.js');
|
||||
case 'nl-NL':
|
||||
return import('@lion/ui/form-core-translations/nl-NL.js');
|
||||
case 'nl':
|
||||
return import('@lion/ui/form-core-translations/nl.js');
|
||||
case 'pl-PL':
|
||||
return import('@lion/ui/form-core-translations/pl-PL.js');
|
||||
case 'pl':
|
||||
return import('@lion/ui/form-core-translations/pl.js');
|
||||
case 'ro-RO':
|
||||
return import('@lion/ui/form-core-translations/ro-RO.js');
|
||||
case 'ro':
|
||||
return import('@lion/ui/form-core-translations/ro.js');
|
||||
case 'ru-RU':
|
||||
return import('@lion/ui/form-core-translations/ru-RU.js');
|
||||
case 'ru':
|
||||
return import('@lion/ui/form-core-translations/ru.js');
|
||||
case 'sk-SK':
|
||||
return import('@lion/ui/form-core-translations/sk-SK.js');
|
||||
case 'sk':
|
||||
return import('@lion/ui/form-core-translations/sk.js');
|
||||
case 'uk-UA':
|
||||
return import('@lion/ui/form-core-translations/uk-UA.js');
|
||||
case 'uk':
|
||||
return import('@lion/ui/form-core-translations/uk.js');
|
||||
case 'zh-CN':
|
||||
case 'zh':
|
||||
return import('@lion/ui/form-core-translations/zh.js');
|
||||
default:
|
||||
return import('@lion/ui/form-core-translations/en.js');
|
||||
}
|
||||
};
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
import { html, LitElement } from 'lit';
|
||||
import { css, html, LitElement } from 'lit';
|
||||
import { LocalizeMixin } from '@lion/ui/localize-no-side-effects.js';
|
||||
import { localizeNamespaceLoader } from '../localizeNamespaceLoader.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('./Validator.js').Validator} Validator
|
||||
|
|
@ -6,17 +8,46 @@ import { html, LitElement } from 'lit';
|
|||
* @typedef {import('../../types/validate/ValidateMixinTypes.js').FeedbackMessage} FeedbackMessage
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string} string
|
||||
*/
|
||||
const capitalize = string => `${string[0].toUpperCase()}${string.slice(1)}`;
|
||||
|
||||
/**
|
||||
* @desc Takes care of accessible rendering of error messages
|
||||
* Should be used in conjunction with FormControl having ValidateMixin applied
|
||||
*/
|
||||
export class LionValidationFeedback extends LitElement {
|
||||
export class LionValidationFeedback extends LocalizeMixin(LitElement) {
|
||||
static get properties() {
|
||||
return {
|
||||
feedbackData: { attribute: false },
|
||||
};
|
||||
}
|
||||
|
||||
static localizeNamespaces = [
|
||||
{ 'lion-form-core': localizeNamespaceLoader },
|
||||
...super.localizeNamespaces,
|
||||
];
|
||||
|
||||
static get styles() {
|
||||
return [
|
||||
css`
|
||||
.validation-feedback__type {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
overflow: hidden;
|
||||
clip-path: inset(100%);
|
||||
clip: rect(1px, 1px, 1px, 1px);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @overridable
|
||||
* @param {Object} opts
|
||||
|
|
@ -58,6 +89,9 @@ export class LionValidationFeedback extends LitElement {
|
|||
${this.feedbackData &&
|
||||
this.feedbackData.map(
|
||||
({ message, type, validator }) => html`
|
||||
<div class="validation-feedback__type">
|
||||
${this._localizeManager.msg(`lion-form-core:validation${capitalize(type)}`)}
|
||||
</div>
|
||||
${this._messageTemplate({ message, type, validator })}
|
||||
`,
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -800,7 +800,7 @@ export function runValidateMixinSuite(customConfig) {
|
|||
expect(el.hasFeedbackFor).to.deep.equal(['error']);
|
||||
const { _feedbackNode } = getFormControlMembers(el);
|
||||
await el.updateComplete;
|
||||
await el.updateComplete;
|
||||
await _feedbackNode.updateComplete;
|
||||
const messageHtmlNode = _feedbackNode.shadowRoot?.querySelector(`#${messageHtmlId}`);
|
||||
expect(messageHtmlNode?.outerHTML).to.equal(messageHtml);
|
||||
expect(messageHtmlNode?.tagName).to.equal('DIV');
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ describe('lion-validation-feedback', () => {
|
|||
const el = /** @type {LionValidationFeedback} */ (
|
||||
await fixture(html`<lion-validation-feedback></lion-validation-feedback>`)
|
||||
);
|
||||
expect(el).shadowDom.to.equal('');
|
||||
expect(el.shadowRoot?.textContent).to.not.include('hello');
|
||||
el.feedbackData = [{ message: 'hello', type: 'error', validator: new AlwaysInvalid() }];
|
||||
await el.updateComplete;
|
||||
expect(el).shadowDom.to.equal('hello');
|
||||
expect(el.shadowRoot?.textContent).to.include('hello');
|
||||
});
|
||||
|
||||
it('renders the validation type attribute', async () => {
|
||||
|
|
@ -73,4 +73,32 @@ describe('lion-validation-feedback', () => {
|
|||
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
it('shares to the user the type of validation feedback', async () => {
|
||||
const el = /** @type {LionValidationFeedback} */ (
|
||||
await fixture(html`<lion-validation-feedback></lion-validation-feedback>`)
|
||||
);
|
||||
|
||||
el.feedbackData = [{ message: 'hello', type: 'error', validator: new AlwaysInvalid() }];
|
||||
await el.updateComplete;
|
||||
|
||||
const validationFeedbackType = el.shadowRoot?.querySelector('.validation-feedback__type');
|
||||
expect(validationFeedbackType?.textContent?.trim()).to.equal('Error');
|
||||
|
||||
el.feedbackData = [{ message: 'hello', type: 'info', validator: new AlwaysInvalid() }];
|
||||
await el.updateComplete;
|
||||
|
||||
expect(validationFeedbackType?.textContent?.trim()).to.equal('Info');
|
||||
});
|
||||
|
||||
describe('accessibility', () => {
|
||||
it('passes a11y audit when with a message', async () => {
|
||||
const el = /** @type {LionValidationFeedback} */ (
|
||||
await fixture(html`<lion-validation-feedback></lion-validation-feedback>`)
|
||||
);
|
||||
el.feedbackData = [{ message: 'hello', type: 'error', validator: new AlwaysInvalid() }];
|
||||
await el.updateComplete;
|
||||
await expect(el).to.be.accessible();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
5
packages/ui/components/form-core/translations/bg-BG.js
Normal file
5
packages/ui/components/form-core/translations/bg-BG.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import bg from './bg.js';
|
||||
|
||||
export default {
|
||||
...bg,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/bg.js
Normal file
6
packages/ui/components/form-core/translations/bg.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Грешка',
|
||||
validationWarning: 'Предупреждение',
|
||||
validationSuccess: 'Успех',
|
||||
validationInfo: 'Информация',
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/cs-CZ.js
Normal file
5
packages/ui/components/form-core/translations/cs-CZ.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import cs from './cs.js';
|
||||
|
||||
export default {
|
||||
...cs,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/cs.js
Normal file
6
packages/ui/components/form-core/translations/cs.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Chyba',
|
||||
validationWarning: 'Varování',
|
||||
validationSuccess: 'Úspěch',
|
||||
validationInfo: 'Informace',
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/de-DE.js
Normal file
5
packages/ui/components/form-core/translations/de-DE.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import de from './de.js';
|
||||
|
||||
export default {
|
||||
...de,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/de.js
Normal file
6
packages/ui/components/form-core/translations/de.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Fehler',
|
||||
validationWarning: 'Warnhinweis',
|
||||
validationSuccess: 'Erfolgreich',
|
||||
validationInfo: 'Info',
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/en-AU.js
Normal file
5
packages/ui/components/form-core/translations/en-AU.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import en from './en.js';
|
||||
|
||||
export default {
|
||||
...en,
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/en-GB.js
Normal file
5
packages/ui/components/form-core/translations/en-GB.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import en from './en.js';
|
||||
|
||||
export default {
|
||||
...en,
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/en-US.js
Normal file
5
packages/ui/components/form-core/translations/en-US.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import en from './en.js';
|
||||
|
||||
export default {
|
||||
...en,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/en.js
Normal file
6
packages/ui/components/form-core/translations/en.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Error',
|
||||
validationWarning: 'Warning',
|
||||
validationSuccess: 'Success',
|
||||
validationInfo: 'Info',
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/es-ES.js
Normal file
5
packages/ui/components/form-core/translations/es-ES.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import es from './es.js';
|
||||
|
||||
export default {
|
||||
...es,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/es.js
Normal file
6
packages/ui/components/form-core/translations/es.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Error',
|
||||
validationWarning: 'Advertencia',
|
||||
validationSuccess: 'Satisfactorio',
|
||||
validationInfo: 'Información',
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/fr-BE.js
Normal file
5
packages/ui/components/form-core/translations/fr-BE.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import fr from './fr.js';
|
||||
|
||||
export default {
|
||||
...fr,
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/fr-FR.js
Normal file
5
packages/ui/components/form-core/translations/fr-FR.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import fr from './fr.js';
|
||||
|
||||
export default {
|
||||
...fr,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/fr.js
Normal file
6
packages/ui/components/form-core/translations/fr.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Erreur',
|
||||
validationWarning: 'Avertissement',
|
||||
validationSuccess: 'Succès',
|
||||
validationInfo: 'Info',
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/hu-HU.js
Normal file
5
packages/ui/components/form-core/translations/hu-HU.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import hu from './hu.js';
|
||||
|
||||
export default {
|
||||
...hu,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/hu.js
Normal file
6
packages/ui/components/form-core/translations/hu.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Hiba',
|
||||
validationWarning: 'Figyelmeztetés',
|
||||
validationSuccess: 'Sikeres',
|
||||
validationInfo: 'Információ',
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/it-IT.js
Normal file
5
packages/ui/components/form-core/translations/it-IT.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import it from './it.js';
|
||||
|
||||
export default {
|
||||
...it,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/it.js
Normal file
6
packages/ui/components/form-core/translations/it.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Errore',
|
||||
validationWarning: 'Avvertenza',
|
||||
validationSuccess: 'Operazione riuscita',
|
||||
validationInfo: 'Info',
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/nl-BE.js
Normal file
5
packages/ui/components/form-core/translations/nl-BE.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import nl from './nl.js';
|
||||
|
||||
export default {
|
||||
...nl,
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/nl-NL.js
Normal file
5
packages/ui/components/form-core/translations/nl-NL.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import nl from './nl.js';
|
||||
|
||||
export default {
|
||||
...nl,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/nl.js
Normal file
6
packages/ui/components/form-core/translations/nl.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Fout',
|
||||
validationWarning: 'Waarschuwing',
|
||||
validationSuccess: 'Succes',
|
||||
validationInfo: 'Informatie',
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/pl-PL.js
Normal file
5
packages/ui/components/form-core/translations/pl-PL.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import pl from './pl.js';
|
||||
|
||||
export default {
|
||||
...pl,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/pl.js
Normal file
6
packages/ui/components/form-core/translations/pl.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Błąd',
|
||||
validationWarning: 'Ostrzeżenie',
|
||||
validationSuccess: 'Zrealizowano pomyślnie',
|
||||
validationInfo: 'Informacja',
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/ro-RO.js
Normal file
5
packages/ui/components/form-core/translations/ro-RO.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import ro from './ro.js';
|
||||
|
||||
export default {
|
||||
...ro,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/ro.js
Normal file
6
packages/ui/components/form-core/translations/ro.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Eroare',
|
||||
validationWarning: 'Atenție',
|
||||
validationSuccess: 'Succes',
|
||||
validationInfo: 'Informații',
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/ru-RU.js
Normal file
5
packages/ui/components/form-core/translations/ru-RU.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import ru from './ru.js';
|
||||
|
||||
export default {
|
||||
...ru,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/ru.js
Normal file
6
packages/ui/components/form-core/translations/ru.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Ошибка',
|
||||
validationWarning: 'Предупреждение',
|
||||
validationSuccess: 'Успешно',
|
||||
validationInfo: 'Информация',
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/sk-SK.js
Normal file
5
packages/ui/components/form-core/translations/sk-SK.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import sk from './sk.js';
|
||||
|
||||
export default {
|
||||
...sk,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/sk.js
Normal file
6
packages/ui/components/form-core/translations/sk.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Chyba',
|
||||
validationWarning: 'Varovanie',
|
||||
validationSuccess: 'Úspešné',
|
||||
validationInfo: 'Info',
|
||||
};
|
||||
5
packages/ui/components/form-core/translations/uk-UA.js
Normal file
5
packages/ui/components/form-core/translations/uk-UA.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import uk from './uk.js';
|
||||
|
||||
export default {
|
||||
...uk,
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/uk.js
Normal file
6
packages/ui/components/form-core/translations/uk.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: 'Помилка',
|
||||
validationWarning: 'Попередження',
|
||||
validationSuccess: 'Успішно',
|
||||
validationInfo: 'Інформація',
|
||||
};
|
||||
6
packages/ui/components/form-core/translations/zh.js
Normal file
6
packages/ui/components/form-core/translations/zh.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
validationError: '错误',
|
||||
validationWarning: '警告',
|
||||
validationSuccess: '成功',
|
||||
validationInfo: '信息',
|
||||
};
|
||||
|
|
@ -195,6 +195,9 @@ describe('<lion-input-amount>', () => {
|
|||
expect(el.formattedValue).to.equal('123.45');
|
||||
localize.locale = 'nl-NL';
|
||||
await el.updateComplete;
|
||||
// TODO find out why the localize needs to be loaded for the feedbackNode
|
||||
// @ts-ignore [allow-protected] in test
|
||||
await el._feedbackNode.localizeNamespacesLoaded;
|
||||
expect(el.formattedValue).to.equal('123,45');
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -108,9 +108,10 @@ describe('lion-selected-file-list', () => {
|
|||
`);
|
||||
const fileItems = el.shadowRoot?.querySelectorAll('.selected__list__item');
|
||||
const feedback = fileItems ? fileItems[0].querySelector('lion-validation-feedback') : undefined;
|
||||
|
||||
// @ts-ignore
|
||||
expect(feedback).to.exist;
|
||||
expect(feedback).shadowDom.to.equal('foobar');
|
||||
expect(el.shadowRoot?.textContent).to.include('foobar');
|
||||
});
|
||||
|
||||
it('should call removeFile method on click of remove button', async () => {
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@
|
|||
},
|
||||
"./calendar-translations/*": "./components/calendar/translations/*",
|
||||
"./combobox-translations/*": "./components/combobox/translations/*",
|
||||
"./pagination-translations/*": "./components/pagination/translations/*",
|
||||
"./progress-indicator-translations/*": "./components/progress-indicator/translations/*",
|
||||
"./form-core-translations/*": "./components/form-core/translations/*",
|
||||
"./input-datepicker-translations/*": "./components/input-datepicker/translations/*",
|
||||
"./input-file-translations/*": "./components/input-file/translations/*",
|
||||
"./input-iban-translations/*": "./components/input-iban/translations/*",
|
||||
|
|
@ -27,6 +26,8 @@
|
|||
"./input-stepper-translations/*": "./components/input-stepper/translations/*",
|
||||
"./input-tel-translations/*": "./components/input-tel/translations/*",
|
||||
"./overlays-translations/*": "./components/overlays/translations/*",
|
||||
"./pagination-translations/*": "./components/pagination/translations/*",
|
||||
"./progress-indicator-translations/*": "./components/progress-indicator/translations/*",
|
||||
"./validate-messages-translations/*": "./components/validate-messages/translations/*",
|
||||
"./docs/*": "./docs/*"
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue