Bootstrap Datepicker Locale with MomentJS

I am using Bootstrap Datepicker available here and everything is working fine. However, I want to localize the calendar, given the user's preferred language. I installed the following when initializing the datepicker:

locale: 'fr' 

However, I get a console error that reads:

Uncaught TypeError: locale () locale fr does not load from moment locales!

I have included MomentJS in my project:

 <script src="/vendors/moment/min/moment.min.js"></script> 

This is my first implementation, so I feel that I am missing something simple, but I just can’t understand.

+5
source share
2 answers

As the error messages say, you just need to specify the desired language to solve the problem. If you only need 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 In addition, moments provide a single file, moment-with-locales.min.js , a library of minutes + all supported locales.

If you want to dynamically set the locale for you, you can use locale :

 // Example with german locale var localeString = 'de'; $('#your-picker-id').data("DateTimePicker").locale(localeString); 
+6
source

Replace

 /moment/min/moment.min.js 

by

 /moment/min/moment-with-locales.js 

and he will work

+8
source

Source: https://habr.com/ru/post/1244376/


All Articles