Skip to content

Commit

Permalink
fix bug with langs with no fc options
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Dec 30, 2014
1 parent bb7f9c8 commit 94aaa26
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,28 @@ fc.lang = function(langCode, newFcOptions) {
// get the FullCalendar internal option hash for this language. create if necessary
fcOptions = langOptionHash[langCode] || (langOptionHash[langCode] = {});

if (newFcOptions) { // provided new options for this language?

// this is as good a time as any to compute options based off of moment locale data
momOptions = getMomentLocaleData(langCode);
$.each(momComputableOptions, function(name, func) {
fcOptions[name] = func(momOptions, fcOptions);
});

// merge the new options on top of the old
// provided new options for this language? merge them in
if (newFcOptions) {
mergeOptions(fcOptions, newFcOptions);
}

// compute language options that weren't defined.
// always do this. newFcOptions can be undefined when initializing from i18n file,
// so no way to tell if this is an initialization or a default-setting.
momOptions = getMomentLocaleData(langCode); // will fall back to en
$.each(momComputableOptions, function(name, func) {
if (fcOptions[name] === undefined) {
fcOptions[name] = func(momOptions, fcOptions);
}
});

// set it as the default language for FullCalendar
defaults.lang = langCode;
};


// NOTE: can't guarantee any of these computations will run because not every language has datepicker
// configs, so make sure there are English fallbacks for these in the defaults file.
var dpComputableOptions = {

defaultButtonText: function(dpOptions) {
Expand Down Expand Up @@ -139,5 +144,6 @@ function getMomentLocaleData(langCode) {
}


// initialize the default language. forces computation of moment-derived English options.
// Initialize English by forcing computation of moment-derived options.
// Also, sets it as the default.
fc.lang('en', englishDefaults);
14 changes: 14 additions & 0 deletions tests/automated/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,18 @@ describe('lang', function() {
expect(s).toEqual('Thursday May 1st 2014');
});

it('works when certain language has no FC settings defined', function() {
affix('#cal');
$('#cal').fullCalendar({
lang: 'en-ca',
defaultView: 'agendaWeek',
defaultDate: '2014-12-25',
events: [
{ title: 'Christmas', start: '2014-12-25T10:00:00' }
]
});
expect($('.fc-day-header:first')).toHaveText('Sun 12-21');
expect($('.fc-event .fc-time')).toHaveText('10:00');
});

});

0 comments on commit 94aaa26

Please sign in to comment.