2014-09-28 3 views
3

(Использование Rails 4) Я пытаюсь отобразить bootstrap3 datetimepicker в текущей локали, он отлично работает на английском языке, но когда я пытаюсь вставить требуемый языковой файл в application.js (as говорится в док), я получаю сообщение об ошибке:bootstrap3 datetimepicker не может загрузить локаль

[Error] TypeError: undefined is not an object (evaluating '$.fn.datetimepicker.dates') 
(anonymous function) (application.js, line 15026) 

в моих активах, в application.js, у меня есть:

//= require jquery 
    //= require jquery_ujs 
    //= require bootstrap.min 

    //= require moment 
    //= require bootstrap-datetimepicker 
    //= require pickers 

    // You may include any languages (optional) 
    //= require locales/bootstrap-datetimepicker.fr 

бутстраповская-datetimepicker.fr.js файл выглядит следующим образом:

 ;(function($){ 
     $.fn.datetimepicker.dates['fr'] = { 
     days: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"], 
     daysShort: ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim"], 
     daysMin: ["D", "L", "Ma", "Me", "J", "V", "S", "D"], 
     months: ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"], 
     monthsShort: ["Jan", "Fev", "Mar", "Avr", "Mai", "Jui", "Jul", "Aou", "Sep", "Oct", "Nov", "Dec"], 
     today: "Aujourd'hui" 
     }; 
    }(jQuery)); 

Возможно, этот контент javascript неправильный ... но почему? или есть еще одна проблема? Проблема не с datetimepicker, так как она корректно отображается на английском языке (по умолчанию)

ответ

3

с этой последней версией, используя моменты.js ... Я SHOUDL использую моменты локалей !!! , так что мой bootstrap-datetimepicker.fr.js должен быть:

// moment.js locale configuration 
// locale : french (fr) 
// author : John Fischer : https://github.com/jfroffice 

(function (factory) { 
    if (typeof define === 'function' && define.amd) { 
     define(['moment'], factory); // AMD 
    } else if (typeof exports === 'object') { 
     module.exports = factory(require('../moment')); // Node 
    } else { 
     factory(window.moment); // Browser global 
    } 
}(function (moment) { 
    return moment.defineLocale('fr', { 
     months : 'janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre'.split('_'), 
     monthsShort : 'janv._févr._mars_avr._mai_juin_juil._août_sept._oct._nov._déc.'.split('_'), 
     weekdays : 'dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi'.split('_'), 
     weekdaysShort : 'dim._lun._mar._mer._jeu._ven._sam.'.split('_'), 
     weekdaysMin : 'Di_Lu_Ma_Me_Je_Ve_Sa'.split('_'), 
     longDateFormat : { 
      LT : 'HH:mm', 
      L : 'DD/MM/YYYY', 
      LL : 'D MMMM YYYY', 
      LLL : 'D MMMM YYYY LT', 
      LLLL : 'dddd D MMMM YYYY LT' 
     }, 
     calendar : { 
      sameDay: '[Aujourd\'hui à] LT', 
      nextDay: '[Demain à] LT', 
      nextWeek: 'dddd [à] LT', 
      lastDay: '[Hier à] LT', 
      lastWeek: 'dddd [dernier à] LT', 
      sameElse: 'L' 
     }, 
     relativeTime : { 
      future : 'dans %s', 
      past : 'il y a %s', 
      s : 'quelques secondes', 
      m : 'une minute', 
      mm : '%d minutes', 
      h : 'une heure', 
      hh : '%d heures', 
      d : 'un jour', 
      dd : '%d jours', 
      M : 'un mois', 
      MM : '%d mois', 
      y : 'un an', 
      yy : '%d ans' 
     }, 
     ordinal : function (number) { 
      return number + (number === 1 ? 'er' : ''); 
     }, 
     week : { 
      dow : 1, // Monday is the first day of the week. 
      doy : 4 // The week that contains Jan 4th is the first week of the year. 
     } 
    }); 
}));