twitter-bootstrap twitter bootstrap datepicker 国际化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13340982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 15:42:02  来源:igfitidea点击:

twitter bootstrap datepicker internationalization

twitter-bootstrapdatepicker

提问by dtjmsy

I am using this twitter bootstrap style datepicker from Stefan Petre

我正在使用来自 Stefan Petre 的这个twitter bootstrap 风格的日期选择器

However, I don' t know how to set the format of the datepicker to french, apart from changing it directly from the sources, is there a better way to do it ?

但是,我不知道如何将 datepicker 的格式设置为法语,除了直接从源更改它之外,还有更好的方法吗?

Thanks all

谢谢大家

采纳答案by Yohn

I've been using a modifiedversion of Stefan Petre's datepicker, and at the bottom of the docsthere it says to include your locale file after you included the main datpicker file.

我一直在使用Stefan Petre 的 datepicker的修改版本,在文档底部,它说在包含主 datpicker 文件后包含您的语言环境文件。

回答by Renan Barreiro

dtjmsy, you can use this as well:

dtjmsy,您也可以使用它:

$('.datepicker').datepicker({
   language: "pt-BR"
});

And here a link with a good sandbox where you can try some configurations: http://eternicode.github.io/bootstrap-datepicker/?#sandbox

这里有一个带有良好沙箱的链接,您可以在其中尝试一些配置:http: //eternicode.github.io/bootstrap-datepicker/?#sandbox

回答by syndrael

Just add bootstrap-datepicker/js/locales/bootstrap-datepicker.fr.js in your code. and

只需在您的代码中添加 bootstrap-datepicker/js/locales/bootstrap-datepicker.fr.js。和

$('.datepicker').datepicker({ language: "fr-FR" });

$('.datepicker').datepicker({ 语言: "fr-FR" });

That's it

而已

回答by Renato Mestre

In version 3.x, you have to internationalizate the moment.js

在 3.x 版本中,你必须将 moment.js 国际化

Check the source here

在此处检查来源

As follow...

如下...

// moment.js language configuration
// language : brazilian portuguese (pt-br)
// author : Caio Ribeiro Pereira : https://github.com/caio-ribeiro-pereira

(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.locale('pt-br', {
        months : "janeiro_fevereiro_mar?o_abril_maio_junho_julho_agosto_setembro_outubro_novembro_dezembro".split("_"),
        monthsShort : "jan_fev_mar_abr_mai_jun_jul_ago_set_out_nov_dez".split("_"),
        weekdays : "domingo_segunda-feira_ter?a-feira_quarta-feira_quinta-feira_sexta-feira_sábado".split("_"),
        weekdaysShort : "dom_seg_ter_qua_qui_sex_sáb".split("_"),
        weekdaysMin : "dom_2a_3a_4a_5a_6a_sáb".split("_"),
        longDateFormat : {
            LT : "HH:mm",
            L : "DD/MM/YYYY",
            LL : "D [de] MMMM [de] YYYY",
            LLL : "D [de] MMMM [de] YYYY [às] LT",
            LLLL : "dddd, D [de] MMMM [de] YYYY [às] LT"
        },
        calendar : {
            sameDay: '[Hoje às] LT',
            nextDay: '[Amanh? às] LT',
            nextWeek: 'dddd [às] LT',
            lastDay: '[Ontem às] LT',
            lastWeek: function () {
                return (this.day() === 0 || this.day() === 6) ?
                    '[último] dddd [às] LT' : // Saturday + Sunday
                    '[última] dddd [às] LT'; // Monday - Friday
            },
            sameElse: 'L'
        },
        relativeTime : {
            future : "em %s",
            past : "%s atrás",
            s : "segundos",
            m : "um minuto",
            mm : "%d minutos",
            h : "uma hora",
            hh : "%d horas",
            d : "um dia",
            dd : "%d dias",
            M : "um mês",
            MM : "%d meses",
            y : "um ano",
            yy : "%d anos"
        },
        ordinal : '%do'
    });
}));

回答by RickL

If you want to specify the localized text from the server you could add this (calling it (eg) "somename"):

如果你想从服务器指定本地化的文本,你可以添加这个(称之为(例如)“somename”):

jQuery.fn.datepicker.dates.somename = {
    days: ["Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"],
    daysShort: ["Вск", "Пнд", "Втр", "Срд", "Чтв", "Птн", "Суб"],
    daysMin: ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"],
    months: ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
    monthsShort: ["Янв", "Фев", "Мар", "Апр", "Май", "Июн", "Июл", "Авг", "Сен", "Окт", "Ноя", "Дек"],
    today: "Сегодня",
    clear: "Очистить",
    format: "dd.mm.yyyy",
    weekStart: 1
};

above the calling function (giving the language parameter the value "somename"):

在调用函数上方(给语言参数值“somename”):

jQuery('#datepicker-container input').datepicker({
    language: "somename"
});

You can then specify whatever values and language you like from, say, a resx file.

然后,您可以从 resx 文件中指定您喜欢的任何值和语言。