Skip to content

Instantly share code, notes, and snippets.

@gorkamolero
Created February 27, 2015 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gorkamolero/0c2eae18d4acc481dfbb to your computer and use it in GitHub Desktop.
Save gorkamolero/0c2eae18d4acc481dfbb to your computer and use it in GitHub Desktop.
Translating Calendars/Events in Squarespace
// Declare an Array of months
var englishFullMonths = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ],
englishAbbrMonths = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ],
spanishFullMonths = [ 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre' ],
spanishAbbrMonths = [ 'Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic' ];
// Wait until DOM ready
(function ($) {
// Function to wait for an element
$.fn.waitUntilExists = function (handler, shouldRunHandlerOnce, isChild) {
var found = 'found';
var $this = $(this.selector);
var $elements = $this.not(function () { return $(this).data(found); }).each(handler).data(found, true);
if (!isChild) {
(window.waitUntilExists_Intervals = window.waitUntilExists_Intervals || {})[this.selector] =
window.setInterval(function () { $this.waitUntilExists(handler, shouldRunHandlerOnce, true); }, 500)
;
}
else if (shouldRunHandlerOnce && $elements.length) {
window.clearInterval(window.waitUntilExists_Intervals[this.selector]);
}
return $this;
}
// This function takes care of the translation
$.fn.translateMonth = function(el){
return this.each(function(){
$this = $(this);
var node = $this.contents().filter(function(){ return this.nodeType == 3 }).first(),
text = node.text(),
first = text.split(" ", el).join(" "),
month = first,
monthPos,
translatedMonth;
// Case there is none
if (!node.length) return;
// Case it's a full month
if ( jQuery.inArray( month, englishFullMonths ) != -1 ) {
monthPos = jQuery.inArray( month, englishFullMonths ),
translatedMonth = spanishFullMonths[monthPos];
// Slice dat shit (cut first word)
node[0].nodeValue = text.slice(first.length);
// Insert word
node.before(translatedMonth);
}
// Case it ain't
if ( jQuery.inArray( month, englishAbbrMonths ) != -1 ) {
monthPos = jQuery.inArray( month, englishAbbrMonths ),
translatedMonth = spanishAbbrMonths[monthPos];
$this.html(translatedMonth);
}
});
};
// With this you can translate the calendar
$('.yui3-calendar-header-label').waitUntilExists(function() {
$('.yui3-calendar-header-label').translateMonth(1);
});
// With this you can translate an event listing, for example, or any other element that uses the abbreviated forms
$('.eventlist-datetag-startdate--month').waitUntilExists(function() {
$('.eventlist-datetag-startdate--month').translateMonth(1);
});
}(jQuery));
@raphaellebb
Copy link

HI,
I've tried this code on my squarespace calendar with french and it doesn't work, can someone help me to make it work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment