ka215 / jquery.timeline

You can easily create the horizontal timeline with two types by using this jQuery plugin.
MIT License
240 stars 43 forks source link

Months in Spanish are lowercase, also wrong ordinal translation. #81

Closed abdielcs closed 3 years ago

abdielcs commented 3 years ago

Congratulations for this excellent library. I can see a couple of bugs related to Spanish locale.

1-When apply the Spanish locale the months are lowercase. 2-The ordinal indicator on weeks are always in English.

image

The screenshots was taken after apply the Spanish locale in https://ka2.org/jqtl-v2/index.php. Spanish ordinals explained: https://en.wikipedia.org/wiki/Ordinal_indicator. In case of weeks should be 21ª.

ka215 commented 3 years ago

Hi there,

1-When apply the Spanish locale the months are lowercase.

The translation mechanism of jQuery.Timeline wraps the native JavaScript Date.toLocaleDateString() method. Therefore, the symptom you mentioned is a native JavaScript specification.

var date = new Date();
var options = { timeZone: 'UTC', month: 'long' };
console.log( date.toLocaleDateString('en-GB', options) );
// -> May
console.log( date.toLocaleDateString('es', options) );
// -> mayo

However, we can work around this issue by adding the following stylesheet:

.jqtl-ruler-line-item[data-ruler-item^=month-] span { text-transform: capitalize; }

2-The ordinal indicator on weeks are always in English.

jQuery.Timeline extends the native JavaScript Date.toLocaleDateString() method to accept the ordinal option when displaying a week. However, this option does not support multiple languages, and the ordinal number displayed is only in English. One idea to make ordinal notation multilingual is to use a method after the timeline initialization to do the filtering. Please refer to the following sample.

$("#myTimeline").Timeline("initialized", function (self) {
    $(self).find('.jqtl-ruler-line-item[data-ruler-item^=week-]').each(function(){
        var ordinalString = $(this).children('span').get(0).textContent;
        var translateToES = parseInt(ordinalString, 10) +'.º';
        $(this).children('span').text(translateToES);
    });
});

Please try it.

Thank you,