javascript - example - Cambiar idioma para bootstrap DateTimePicker
datepicker bootstrap 4 español (6)
1. utilizará un elemento de matriz de configuración regional diferente en datepicker.js del siguiente enlace https://github.com/smalot/bootstrap-datetimepicker/tree/master/js/locales
2.add array en datepicker.js como este:
$.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: ["上午", "下午"]
}
};
Uso bootstrap-datetimepicker.js
Copyright 2012 por Stefan Petre
http://www.malot.fr/bootstrap-datetimepicker/index.php
Importe el js y otro idioma, por ejemplo ruso:
<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>
en document.ready
$(document).ready(function () {
// debugger;
$(".form_datetime").datetimepicker({
isRTL: false,
format: ''dd.mm.yyyy hh:ii'',
autoclose:true
});
});
pero no esta traducido
Traté de insertar en init
**language: "RU"**
**language: "ru"**
**language: "ru-RU"**
pero nada cambia, ¿tienes alguna propuesta?
Creo que hay que configurarlo en las opciones:
$(".form_datetime").datetimepicker({
isRTL: false,
format: ''dd.mm.yyyy hh:ii'',
autoclose:true,
language: ''ru''
});
Si no funciona, asegúrese de que:
$.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"
};
se define para ''ru''
La opción es locale: ''ru''
Pero primero, debe llamar al script ../moment.js/version/locale/ru.js
Espero que esto ayude.
Si usa moment.js
, debe cargar moment-with-locales.min.js
no moment.min.js
. De lo contrario, su locale: ''ru''
no funcionará.
Simplemente incluya su ubicación deseada después del complemento. Puede encontrarlo en la carpeta de entornos locales en github https://github.com/uxsolutions/bootstrap-datepicker/tree/master/dist/locales
<script src="bootstrap-datepicker.XX.js" charset="UTF-8"></script>
y luego agregar la opción
$(''.datepicker'').datepicker({
language: ''XX''
});
Donde XX es tu localidad deseada como ru
necesita agregar el archivo de idioma javascript, después del momento de la biblioteca, ejemplo:
<script type="text/javascript" src="js/moment/moment.js"></script>
<script type="text/javascript" src="js/moment/es.js"></script>
Ahora puedes configurar un idioma.
<script type="text/javascript">
$(function () {
$(''#datetimepicker1'').datetimepicker({locale:''es''});
});
</script>
Aquí están todos los idiomas: https://github.com/moment/moment