Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

feat(i18n): allow the i18nStrings.weekNumber option to be a function

Closes #393
  • Loading branch information...
Matt Lewis
Matt Lewis committed Jul 19, 2016
1 parent 87a45c2 commit 247f2c14ec39385993f527b1861e09413b85307a
@@ -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() {

@@ -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>
@@ -11,6 +11,7 @@ describe('mwlCalendarMonth directive', function() {
directiveScope,
showModal,
calendarHelper,
calendarConfig,
template =
'<mwl-calendar-month ' +
'events="events" ' +
@@ -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);
@@ -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.
You can’t perform that action at this time.