Skip to content

Commit

Permalink
Add translations to the date picker
Browse files Browse the repository at this point in the history
  • Loading branch information
Windvis committed Apr 29, 2021
1 parent f4c084e commit 4f68659
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/components/date-time-picker.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
<div class="au-o-grid__item au-u-2-6">
{{#let (unique-id) as |id|}}
<AuLabel for={{id}}>Datum</AuLabel>
<AuDatePicker @id={{id}} @onChange={{this.onChangeDate}} @value={{this.date}} />
<AuDatePicker
@id={{id}}
@onChange={{this.onChangeDate}}
@value={{this.date}}
@localization={{this.datePickerLocalization}}
/>
{{/let}}
</div>
<div class="au-o-grid__item au-u-2-6 au-u-1-6@medium">
Expand Down
38 changes: 38 additions & 0 deletions app/components/date-time-picker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Component from '@glimmer/component';
import { action } from "@ember/object";
import { inject as service } from '@ember/service';

export default class DateTimePicker extends Component{
@service intl;
date;
hours;
minutes;
Expand All @@ -15,6 +17,23 @@ export default class DateTimePicker extends Component{
}
}

get datePickerLocalization() {
return {
buttonLabel: this.intl.t('auDatePicker.buttonLabel'),
selectedDateMessage: this.intl.t('auDatePicker.selectedDateMessage'),
prevMonthLabel: this.intl.t('auDatePicker.prevMonthLabel'),
nextMonthLabel: this.intl.t('auDatePicker.nextMonthLabel'),
monthSelectLabel: this.intl.t('auDatePicker.monthSelectLabel'),
yearSelectLabel: this.intl.t('auDatePicker.yearSelectLabel'),
closeLabel: this.intl.t('auDatePicker.closeLabel'),
keyboardInstruction: this.intl.t('auDatePicker.keyboardInstruction'),
calendarHeading: this.intl.t('auDatePicker.calendarHeading'),
dayNames: getLocalizedDays(this.intl),
monthNames: getLocalizedMonths(this.intl),
monthNamesShort: getLocalizedMonths(this.intl, 'short'),
};
}

@action
onChangeDate(isoDate, date) {
let wasDateInputCleared = !date;
Expand Down Expand Up @@ -45,3 +64,22 @@ export default class DateTimePicker extends Component{
this.args.onChange(this.date);
}
}

function getLocalizedMonths(intl, monthFormat = 'long') {
let someYear = 2021;
return [...Array(12).keys()]
.map((monthIndex) => {
let date = new Date(someYear, monthIndex);
return intl.formatDate(date, { month: monthFormat });
});
}

function getLocalizedDays(intl, weekdayFormat = 'long') {
let someSunday = new Date('2021-01-03');
return [...Array(7).keys()]
.map((index) => {
let weekday = new Date(someSunday.getTime());
weekday.setDate(someSunday.getDate() + index);
return intl.formatDate(weekday, { weekday: weekdayFormat });
});
}
10 changes: 10 additions & 0 deletions translations/appuniversum/en-us.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
auDatePicker:
buttonLabel: "Choose a date"
selectedDateMessage: "Selected date is"
prevMonthLabel: "Previous month"
nextMonthLabel: "Next month"
monthSelectLabel: "Month"
yearSelectLabel: "Year"
closeLabel: "Close windows"
keyboardInstruction: "You can use arrow keys to navigate dates"
calendarHeading: "Choose a date"
10 changes: 10 additions & 0 deletions translations/appuniversum/nl-be.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
auDatePicker:
buttonLabel: "Kies een datum"
selectedDateMessage: "De geselecteerde datum is"
prevMonthLabel: "Vorige maand"
nextMonthLabel: "Volgende maand"
monthSelectLabel: "Maand"
yearSelectLabel: "Jaar"
closeLabel: "Sluit venster"
keyboardInstruction: "Gebruik de pijltjestoetsen om te navigeren"
calendarHeading: "Kies een datum"

0 comments on commit 4f68659

Please sign in to comment.