Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 359e1a9

Browse files
committed
Fix lang parameter being overriden by $locale. Fix #135
1 parent 80a32ee commit 359e1a9

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

src/calendar.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
angular.module('ui.calendar', [])
1212
.constant('uiCalendarConfig', {})
13-
.controller('uiCalendarCtrl', ['$scope', '$timeout', function($scope, $timeout){
13+
.controller('uiCalendarCtrl', ['$scope', '$timeout', '$locale', function($scope, $timeout, $locale){
1414

1515
var sourceSerialId = 1,
1616
eventSerialId = 1,
@@ -165,26 +165,31 @@ angular.module('ui.calendar', [])
165165

166166
return config;
167167
};
168-
}])
169-
.directive('uiCalendar', ['uiCalendarConfig', '$locale', function(uiCalendarConfig, $locale) {
170-
// Configure to use locale names by default
171-
var tValues = function(data) {
172-
// convert {0: "Jan", 1: "Feb", ...} to ["Jan", "Feb", ...]
173-
var r, k;
174-
r = [];
175-
for (k in data) {
176-
r[k] = data[k];
168+
169+
this.getLocaleConfig = function(fullCalendarConfig) {
170+
if (!fullCalendarConfig.lang || fullCalendarConfig.useNgLocale) {
171+
// Configure to use locale names by default
172+
var tValues = function(data) {
173+
// convert {0: "Jan", 1: "Feb", ...} to ["Jan", "Feb", ...]
174+
var r, k;
175+
r = [];
176+
for (k in data) {
177+
r[k] = data[k];
178+
}
179+
return r;
180+
};
181+
var dtf = $locale.DATETIME_FORMATS;
182+
return {
183+
monthNames: tValues(dtf.MONTH),
184+
monthNamesShort: tValues(dtf.SHORTMONTH),
185+
dayNames: tValues(dtf.DAY),
186+
dayNamesShort: tValues(dtf.SHORTDAY)
187+
};
177188
}
178-
return r;
189+
return {};
179190
};
180-
var dtf = $locale.DATETIME_FORMATS;
181-
uiCalendarConfig = angular.extend({
182-
monthNames: tValues(dtf.MONTH),
183-
monthNamesShort: tValues(dtf.SHORTMONTH),
184-
dayNames: tValues(dtf.DAY),
185-
dayNamesShort: tValues(dtf.SHORTDAY)
186-
}, uiCalendarConfig || {});
187-
191+
}])
192+
.directive('uiCalendar', ['uiCalendarConfig', function(uiCalendarConfig) {
188193
return {
189194
restrict: 'A',
190195
scope: {eventSources:'=ngModel',calendarWatchEvent: '&'},
@@ -203,6 +208,9 @@ angular.module('ui.calendar', [])
203208

204209
fullCalendarConfig = controller.getFullCalendarConfig(calendarSettings, uiCalendarConfig);
205210

211+
var localeConfig = controller.getLocaleConfig(fullCalendarConfig);
212+
angular.extend(fullCalendarConfig, localeConfig);
213+
206214
options = { eventSources: sources };
207215
angular.extend(options, fullCalendarConfig);
208216

0 commit comments

Comments
 (0)