admin管理员组文章数量:1202351
I am using a Bootstrap Datepicker available here and everything is working fine. However, I want to localize the calendar given a user's preferred language. I've set the following when I initialize the datepicker:
locale: 'fr'
However, I get a console error that reads:
Uncaught TypeError: locale() locale fr is not loaded from moment locales!
I am including MomentJS in my project:
<script src="/vendors/moment/min/moment.min.js"></script>
This is my first implementation so I feel like I'm missing something simple but just can't figure it out.
I am using a Bootstrap Datepicker available here and everything is working fine. However, I want to localize the calendar given a user's preferred language. I've set the following when I initialize the datepicker:
locale: 'fr'
However, I get a console error that reads:
Uncaught TypeError: locale() locale fr is not loaded from moment locales!
I am including MomentJS in my project:
<script src="/vendors/moment/min/moment.min.js"></script>
This is my first implementation so I feel like I'm missing something simple but just can't figure it out.
Share Improve this question edited Dec 2, 2016 at 13:38 Hakan Fıstık 19.4k16 gold badges121 silver badges146 bronze badges asked Mar 3, 2016 at 17:11 JasonJason 1,1373 gold badges17 silver badges32 bronze badges2 Answers
Reset to default 13Replace
/moment/min/moment.min.js
by
/moment/min/moment-with-locales.js
and it will work
As the error messages says, you just have to include the desired locale to solve your issue. If you need only fr
locale, you can add something like this:
<script src="/vendors/moment/locale/fr.js"></script>
after moment
import.
EDIT:
If you need multiple locales you can import locales.js
instead of fr.js
. Moreover moments provides a single file, moment-with-locales.min.js
, with moment library + all supported locales.
If you want to dynamically set locale for you picker, you can use locale
function:
// Example with german locale
var localeString = 'de';
$('#your-picker-id').data("DateTimePicker").locale(localeString);
本文标签: javascriptBootstrap Datepicker Locale with MomentJSStack Overflow
版权声明:本文标题:javascript - Bootstrap Datepicker Locale with MomentJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738579667a2101085.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论