ruby-on-rails-4 - bootstrap3 datetimepicker 无法加载语言环境

标签 ruby-on-rails-4 bootstrap-datetimepicker

(使用 Rails 4)我试图在当前语言环境中显示 bootstrap3 datetimepicker,它在英语中工作正常,但是当我尝试在 application.js 中插入 require 语言环境文件时(如文档中所述),我得到一个错误:

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

在我的 Assets 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

bootstrap-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 内容不对...但为什么呢?或者还有其他问题吗? 问题不在于日期时间选择器,因为它以英语正确显示(默认)

最佳答案

使用这个最新版本,使用 moments.js ...我应该使用 moments 语言环境!!! 所以我的 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.
        }
    });
}));

关于ruby-on-rails-4 - bootstrap3 datetimepicker 无法加载语言环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26083652/

相关文章:

javascript - bootstrap-datetimepicker 只显示日期

jquery - 时间选择器容器不包装其内容

javascript - Bootstrap 日期时间选择器动态默认日期不起作用

ruby-on-rails - 将 API 响应的属性/属性与本地 stub 进行比较

ruby-on-rails - 具有两个输入参数的 Pundit 策略

ruby-on-rails - rails - postgres 或 rails 是否自动验证 datetime 列只能有 datetime 对象?

javascript - 从 bootstrap-datetimepicker 获取日期作为字符串

ruby-on-rails - 复制带有回形针附件的记录

mysql - 什么 SET FOREIGN_KEY_CHECKS=0;做

javascript - 如何在 datetimepicker 中添加基于小时的最少天数?