Meteor-Community-Packages / meteor-autoform-bs-datepicker

Custom "bootstrap-datepicker" input type for AutoForm
MIT License
25 stars 32 forks source link

i18n? #22

Closed Aralun closed 7 years ago

Aralun commented 9 years ago

Plop,

How would one implement i18n on the datepicker? Does changing the moment locale also changes the calendar entries?

ghost commented 9 years ago

I think that current version does not support this. But here http://vitalets.github.io/bootstrap-datepicker/ in options section there is language.

code snippet from Template.created hook:

Template.order.rendered = function () {

    $.fn.datepicker.dates['sk'] = {
        days: ["Nedeľa", "Pondelok", "Utorok", "Streda", "Štvrtok", "Piatok", "Sobota", "Nedeľa"],
        daysShort: ["Ned", "Pon", "Uto", "Str", "Štv", "Pia", "Sob", "Ned"],
        daysMin: ["Ne", "Po", "Ut", "St", "Št", "Pi", "So", "Ne"],
        months: ["Január", "Február", "Marec", "Apríl", "Máj", "Jún", "Júl", "August", "September", "Október", "November", "December"],
        monthsShort: ["Jan", "Feb", "Mar", "Apr", "Máj", "Jún", "Júl", "Aug", "Sep", "Okt", "Nov", "Dec"]
    };

    var endDate = new Date();
    endDate.setDate(endDate.getDate() + 30);
    var startDate = new Date();
    var daysToAdd = 1;
    var isFriday = (startDate.getDay() == 5);
    var isSaturday = (startDate.getDay() == 6);
    if (isFriday) {
        daysToAdd = 3;
    } else if (isSaturday) {
        daysToAdd = 2;
    }
    startDate.setDate(startDate.getDate() + daysToAdd);
    var datePickInput = $('#pickDate');
    datePickInput.datepicker({
        daysOfWeekDisabled: [0, 6],
        startDate: startDate,
        endDate: endDate,
        weekStart: 1,
        format: "dd. mm. yyyy",
        autoclose: true,
        language: 'sk'
    });
    datePickInput.datepicker('setUTCDate', startDate);
    datePickInput.datepicker('update');
};

Note that if you put this in rendered hook things from schema will not work(they are overriden). Let me know if you made any progress.

And also this could use some tweaks like auto detection language and format like:

var language = window.navigator.userLanguage || window.navigator.language;
Jehu commented 9 years ago

I just do this:

Meteor.startup(function() {
  $.fn.datepicker.dates.de = {
    days: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
    daysShort: ["Son", "Mon", "Die", "Mit", "Don", "Fre", "Sam"],
    daysMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
    months: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
    monthsShort: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
    today: "Heute",
    clear: "Löschen",
    weekStart: 1,
    format: "dd.mm.yyyy"
  };
});

Then the settings from schema are working, and the translation is available globally.