45

我使用bootstrap-datetimepicker.jsStefan Petre 的版权 2012

http://www.malot.fr/bootstrap-datetimepicker/index.php

我导入 js 和另一种语言,例如俄语:

<script type="text/javascript" 
  src="/Resources/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
<script type="text/javascript" 
  src="/Resources/plugins/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.ru.js" charset="UTF-8"></script>

在 document.ready 中

$(document).ready(function () {
    // debugger;

    $(".form_datetime").datetimepicker({
        isRTL: false,
        format: 'dd.mm.yyyy hh:ii',
        autoclose:true
    });
});

但它没有翻译

我试图在初始化时插入

**language: "RU"**
**language: "ru"**
**language: "ru-RU"**

但没有任何变化,你有什么建议吗?

4

12 回答 12

77

我认为你必须在选项中设置它:

$(".form_datetime").datetimepicker({
    isRTL: false,
    format: 'dd.mm.yyyy hh:ii',
    autoclose:true,
    language: 'ru'
});

如果它不起作用,请确保:

$.fn.datetimepicker.dates['en'] = {
    days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
    daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
    daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
    months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
    monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
    today: "Today"
};

为“ru”定义

于 2013-10-15T13:18:38.473 回答
21

如果你使用moment.js你需要加载moment-with-locales.min.js不是moment.min.js。否则,您locale: 'ru'将无法正常工作。

于 2016-01-02T18:15:43.453 回答
17

您需要在moment库之后添加javascript语言文件,例如:

<script type="text/javascript" src="js/moment/moment.js"></script>
<script type="text/javascript" src="js/moment/es.js"></script>

现在您可以设置语言了。

<script type="text/javascript">
$(function () {
  $('#datetimepicker1').datetimepicker({locale:'es'});
});
</script>

以下是所有语言:https ://github.com/moment/moment

于 2016-06-23T03:04:01.960 回答
11

选项是locale: 'ru'

但首先,你必须调用脚本../moment.js/version/locale/ru.js

希望这可以帮助。

于 2015-09-09T18:40:23.023 回答
10

只需在插件后包含您想要的语言环境。您可以在 github https://github.com/uxsolutions/bootstrap-datepicker/tree/master/dist/locales上的locales文件夹中找到它

<script src="bootstrap-datepicker.XX.js" charset="UTF-8"></script>

然后添加选项

$('.datepicker').datepicker({
   language: 'XX'
});

XX是您想要的语言环境,例如ru

于 2017-07-31T18:59:04.880 回答
5

1.您将通过以下链接在 datepicker.js 中使用不同的语言环境数组元素 https://github.com/smalot/bootstrap-datetimepicker/tree/master/js/locales

2.在 datepicker.js 中添加数组,如下所示:

$.fn.datepicker.Constructor = Datepicker;
    var dates = $.fn.datepicker.dates = {
        en: {
            days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
            daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
            daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
            months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
            monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
            today: "Today"
        },
        CN:{
        days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
        daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
    daysMin: ["日", "一", "二", "三", "四", "五", "六", "日"],
    months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
    monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
    today: "今天",
    suffix: [],
    meridiem: ["上午", "下午"]
}
	};

于 2017-05-25T08:46:44.707 回答
4

1.首先将此js文件添加到您的HTML中。

<script th:src="@{${webLinkFactory.jsLibRootPath()}+'/bootstrap-datepicker.nl.min.js'}" charset="UTF-8"type="text/javascript"></script>

显然在moment.min.js之后。

bootstrap-datepicker.nl.min.js 的内容将是

;(function($){
    $.fn.datepicker.dates['nl'] = {
        days: ["Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"],
        daysShort: ["Zon", "Man", "Din", "Woe", "Don", "Vri", "Zat", "Zon"],
        daysMin: ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za", "Zo"],
        months: ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"],
        monthsShort: ["Jan", "Feb", "Mrt", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"],
        today: "Vandaag",
        suffix: [],
        meridiem: []
    };
    $.fn.datetimepicker.dates['nl'] = {
        days: ["Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"],
        daysShort: ["Zon", "Man", "Din", "Woe", "Don", "Vri", "Zat", "Zon"],
        daysMin: ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za", "Zo"],
        months: ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"],
        monthsShort: ["Jan", "Feb", "Mrt", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"],
        today: "Vandaag",
        suffix: [],
        meridiem: []
    };
}(jQuery));

2.在你的js文件的ready函数中设置这一行。

$(document).ready(function () {
    $.fn.datetimepicker.defaults.language = 'nl';
}

3.以这种方式初始化你的日期时间选择器

$(this).datetimepicker({
                        format: "yyyy-mm-dd hh:ii",
                        autoclose: true,
                        weekStart: 1,
                        locale: 'nl',
                        language: 'nl'
                    });

按照这个步骤,我能够成功地将我的英语 datepicker 和 datetimepicker 转换为荷兰语。

于 2019-08-08T07:31:45.947 回答
1

你是对的!其他获取方式!

https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/locales/bootstrap-datepicker.ru.min.js

你可以在那里找到所有语言https://cdnjs.com/libraries/bootstrap-datepicker

https://labs.maarch.org/maarch/maarchRM/commit/3299d1e7ed25018b48715e16a42d52c288b4da3e

于 2020-06-19T11:06:51.867 回答
1

对于讲法语的人,这就是你的做法

        ;(function($){
        $.fn.datepicker.dates['fr'] = {
            days: ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
            daysShort: ["dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam."],
            daysMin: ["d", "l", "ma", "me", "j", "v", "s"],
            months: ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"],
            monthsShort: ["janv.", "févr.", "mars", "avril", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc."],
            today: "Aujourd'hui",
            monthsTitle: "Mois",
            clear: "Effacer",
            weekStart: 1,
            format: "dd/mm/yyyy"
        };
    }(jQuery));

    $('.js-datepicker').datepicker({
        format: 'dd/mm/yyyy',
        startDate: new Date(),
        language: 'fr',
    });

感谢此来源:https ://www.1formatik.com/1056/comment-mettre-bootstrap-datepicker-en-francais

于 2021-03-03T15:14:18.877 回答
1

对于像我一样无法通过上述解决方案解决此问题的人,我建议验证您是否同时在不同位置初始化 $(element).datetimepicker(...) 。

就我而言,经过很长时间,我发现一个 global.js 干扰了另一个 datetimepicker 初始化。

如果您出于某种原因需要在不同的文件中使用不同的初始化来维护工作,请记住在每个文件之前删除 datetimepicker:

$(element).datetimepicker('remove')

参考:https ://www.malot.fr/bootstrap-datetimepicker/index.php#methods

编辑:这个解决方案仍然需要正确导入语言文件,就在bootstrap-datetimepicker.js.

我希望这有帮助!

于 2019-08-13T19:57:05.267 回答
0

这仅供您参考:

https://github.com/rajit/bootstrap3-datepicker/tree/master/locales/zh-CN

https://github.com/smalot/bootstrap-datetimepicker

https://bootstrap-datepicker.readthedocs.io/en/v1.4.1/i18n.html

案例如下:</p>

 <div class="input" id="event_period">
   <input class="date" required="required" type="text">
 </div>

 $.fn.datepicker.dates['zh-CN'] = {
    days:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
    daysShort:["周日","周一","周二","周三","周四","周五","周六"],
    daysMin:["日","一","二","三","四","五","六"],
    months:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],
    monthsShort:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],
    today:"今日",
    clear:"清除"
  };

  $('#event_period').datepicker({
    inputs: $('input.date'),
    todayBtn: "linked",
    clearBtn: true,
    format: "yyyy年mm月",
    titleFormat: "yyyy年mm月",
    language: 'zh-CN',
    weekStart:1 // Available or not
  });
于 2018-12-18T11:09:34.623 回答
0

尝试这个:

$( ".form_datetime" ).datepicker( $.datepicker.regional[ "zh-CN" ], { dateFormat: 'dd.mm.yyyy hh:ii' });
于 2019-02-25T08:07:34.520 回答