Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(datepicker): Adding translatibility - FRONT-3573 #2363

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/implementations/twig/components/datepicker/datepicker.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,40 @@ import getSystem from '@ecl/builder/utils/getSystem';

import specsEc from '@ecl/specs-component-datepicker/demo/data--ec';
import specsEu from '@ecl/specs-component-datepicker/demo/data--eu';

import datepicker from './datepicker.html.twig';
import notes from './README.md';

const system = getSystem();
const dataDefault = system === 'eu' ? specsEu : specsEc;

const dataTranslated = {
...dataDefault,
autoinit: false,
helper_text: "Ceci est le texte d'aide de l'entrée",
invalid_text: "Ceci est le message d'erreur",
};

const withInit = (story) => {
const demo = story();
return `
<script>
var elt = document.querySelector('[data-ecl-datepicker-toggle]');
var datepicker = new ECL.Datepicker(elt, {
format: 'DD/MMM/YYYY',
i18n: {
previousMonth : 'Mois précédent',
nextMonth : 'Mois prochain',
months : ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
weekdays : ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
weekdaysShort : ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam']
}
});
datepicker.init();
</script>
${demo}`;
};

const getArgs = (data) => ({
show_label: true,
show_helper: true,
Expand Down Expand Up @@ -61,3 +89,12 @@ Default.args = getArgs(dataDefault);
Default.argTypes = getArgTypes(dataDefault);
Default.parameters = { notes: { markdown: notes, json: dataDefault } };
Default.decorators = [withNotes, withCode];

export const Translated = (args) =>
datepicker(prepareData(dataTranslated, args));

Translated.storyName = 'translated';
Translated.args = getArgs(dataTranslated);
Translated.argTypes = getArgTypes(dataTranslated);
Translated.parameters = { notes: { markdown: notes, json: dataTranslated } };
Translated.decorators = [withNotes, withInit, withCode];
30 changes: 30 additions & 0 deletions src/implementations/vanilla/components/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@ export class Datepicker {
theme = 'ecl-datepicker-theme',
yearRange = 40,
reposition = false,
i18n = {
previousMonth: 'Previous Month',
nextMonth: 'Next Month',
months: [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
],
weekdays: [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
],
weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
},
showDaysInNextAndPreviousMonths = true,
enableSelectionDaysInNextAndPreviousMonths = true,
} = {}
Expand All @@ -46,6 +74,7 @@ export class Datepicker {
this.format = format;
this.theme = theme;
this.yearRange = yearRange;
this.i18n = i18n;
this.showDaysInNextAndPreviousMonths = showDaysInNextAndPreviousMonths;
this.enableSelectionDaysInNextAndPreviousMonths =
enableSelectionDaysInNextAndPreviousMonths;
Expand All @@ -61,6 +90,7 @@ export class Datepicker {
format: this.format,
yearRange: this.yearRange,
firstDay: 1,
i18n: this.i18n,
theme: this.theme,
reposition: this.reposition,
showDaysInNextAndPreviousMonths: this.showDaysInNextAndPreviousMonths,
Expand Down