mirror of
https://github.com/wassname/fullcalendar.git
synced 2026-07-24 13:00:34 +08:00
Fix for Issue 29 (languages)
This commit is contained in:
+24
-12
@@ -64,26 +64,33 @@ function Calendar(element, instanceOptions) {
|
||||
// -----------------------------------------------------------------------------------
|
||||
// Apply overrides to the current language's data
|
||||
|
||||
var langData = createObject( // make a cheap clone
|
||||
moment.localeData(options.lang)
|
||||
);
|
||||
// Returns moment's internal locale data. If doesn't exist, returns English.
|
||||
// Works with moment-pre-2.8
|
||||
function getLocaleData(langCode) {
|
||||
var f = moment.localeData || moment.langData;
|
||||
return f.call(moment, langCode) ||
|
||||
f.call(moment, 'en'); // the newer localData could return null, so fall back to en
|
||||
}
|
||||
|
||||
|
||||
var localeData = createObject(getLocaleData(options.lang)); // make a cheap copy
|
||||
|
||||
if (options.monthNames) {
|
||||
langData._months = options.monthNames;
|
||||
localeData._months = options.monthNames;
|
||||
}
|
||||
if (options.monthNamesShort) {
|
||||
langData._monthsShort = options.monthNamesShort;
|
||||
localeData._monthsShort = options.monthNamesShort;
|
||||
}
|
||||
if (options.dayNames) {
|
||||
langData._weekdays = options.dayNames;
|
||||
localeData._weekdays = options.dayNames;
|
||||
}
|
||||
if (options.dayNamesShort) {
|
||||
langData._weekdaysShort = options.dayNamesShort;
|
||||
localeData._weekdaysShort = options.dayNamesShort;
|
||||
}
|
||||
if (options.firstDay != null) {
|
||||
var _week = createObject(langData._week); // _week: { dow: # }
|
||||
var _week = createObject(localeData._week); // _week: { dow: # }
|
||||
_week.dow = options.firstDay;
|
||||
langData._week = _week;
|
||||
localeData._week = _week;
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +123,12 @@ function Calendar(element, instanceOptions) {
|
||||
mom = fc.moment.parseZone.apply(null, arguments); // let the input decide the zone
|
||||
}
|
||||
|
||||
mom._lang = langData;
|
||||
if ('_locale' in mom) { // moment 2.8 and above
|
||||
mom._locale = localeData;
|
||||
}
|
||||
else { // pre-moment-2.8
|
||||
mom._lang = localeData;
|
||||
}
|
||||
|
||||
return mom;
|
||||
};
|
||||
@@ -204,7 +216,7 @@ function Calendar(element, instanceOptions) {
|
||||
|
||||
// a function that returns a formatStr // TODO: in future, precompute this
|
||||
if (typeof formatStr === 'function') {
|
||||
formatStr = formatStr.call(t, options, langData);
|
||||
formatStr = formatStr.call(t, options, localeData);
|
||||
}
|
||||
|
||||
return formatRange(m1, m2, formatStr, null, options.isRTL);
|
||||
@@ -216,7 +228,7 @@ function Calendar(element, instanceOptions) {
|
||||
|
||||
// a function that returns a formatStr // TODO: in future, precompute this
|
||||
if (typeof formatStr === 'function') {
|
||||
formatStr = formatStr.call(t, options, langData);
|
||||
formatStr = formatStr.call(t, options, localeData);
|
||||
}
|
||||
|
||||
return formatDate(mom, formatStr);
|
||||
|
||||
@@ -73,11 +73,15 @@ function formatDateWithChunk(date, chunk) {
|
||||
// rendering of one date, without any separator.
|
||||
function formatRange(date1, date2, formatStr, separator, isRTL) {
|
||||
|
||||
var localeData;
|
||||
|
||||
date1 = fc.moment.parseZone(date1);
|
||||
date2 = fc.moment.parseZone(date2);
|
||||
|
||||
localeData = (date1.localeData || date1.lang).call(date1); // works with moment-pre-2.8
|
||||
|
||||
// Expand localized format strings, like "LL" -> "MMMM D YYYY"
|
||||
formatStr = date1.localeData().longDateFormat(formatStr) || formatStr;
|
||||
formatStr = localeData.longDateFormat(formatStr) || formatStr;
|
||||
// BTW, this is not important for `formatDate` because it is impossible to put custom tokens
|
||||
// or non-zero areas in Moment's localized format strings.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user