Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Commit

Permalink
feat(i18n): allow the i18nStrings.weekNumber option to be a function
Browse files Browse the repository at this point in the history
Closes #393
  • Loading branch information
Matt Lewis committed Jul 19, 2016
1 parent 87a45c2 commit 247f2c1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/directives/mwlCalendarMonth.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ angular
});
};

vm.getWeekNumberLabel = function(day) {
var weekNumber = day.date.clone().add(1, 'day').isoWeek();
if (typeof calendarConfig.i18nStrings.weekNumber === 'function') {
return calendarConfig.i18nStrings.weekNumber({weekNumber: weekNumber});
} else {
return calendarConfig.i18nStrings.weekNumber.replace('{week}', weekNumber);
}
};

})
.directive('mwlCalendarMonth', function() {

Expand Down
2 changes: 1 addition & 1 deletion src/templates/calendarMonthCell.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<ng-include src="vm.customTemplateUrls.calendarMonthCellEvents || vm.calendarConfig.templates.calendarMonthCellEvents"></ng-include>

<div id="cal-week-box" ng-if="$first && rowHovered">
<span ng-bind="vm.calendarConfig.i18nStrings.weekNumber.replace('{week}', day.date.clone().add(1, 'day').isoWeek())"></span>
<span ng-bind="vm.getWeekNumberLabel(day)"></span>
</div>

</div>
15 changes: 14 additions & 1 deletion test/unit/directives/mwlCalendarMonth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('mwlCalendarMonth directive', function() {
directiveScope,
showModal,
calendarHelper,
calendarConfig,
template =
'<mwl-calendar-month ' +
'events="events" ' +
Expand Down Expand Up @@ -80,9 +81,10 @@ describe('mwlCalendarMonth directive', function() {

beforeEach(angular.mock.module('mwl.calendar'));

beforeEach(angular.mock.inject(function($compile, _$rootScope_, _calendarHelper_) {
beforeEach(angular.mock.inject(function($compile, _$rootScope_, _calendarHelper_, _calendarConfig_) {
$rootScope = _$rootScope_;
calendarHelper = _calendarHelper_;
calendarConfig = _calendarConfig_;
scope = $rootScope.$new();
prepareScope(scope);
element = angular.element(template);
Expand Down Expand Up @@ -179,4 +181,15 @@ describe('mwlCalendarMonth directive', function() {
});
});

it('should get the week label', function() {
expect(MwlCalendarCtrl.getWeekNumberLabel({date: moment().startOf('year').endOf('week').add(1, 'day')})).to.equal('Week 1');
});

it('should allow the week label option to be a function', function() {
calendarConfig.i18nStrings.weekNumber = function(params) {
return 'My custom function ' + params.weekNumber;
};
expect(MwlCalendarCtrl.getWeekNumberLabel({date: moment().startOf('year').endOf('week').add(1, 'day')})).to.equal('My custom function 1');
});

});

0 comments on commit 247f2c1

Please sign in to comment.