bootstrap-datepicker 全局设置语言 [英] bootstrap-datepicker set language globally
问题描述
我正在使用 bootstrap-datepaginator,里面使用了 bootstrap-datepicker.Utilizzanto bootstrap-datepicker作为一个单独的组件,设置语言没有问题,但是使用bootstrap-datepaginator就不一样了.我该怎么办?
I'm using bootstrap-datepaginator that inside uses bootstrap-datepicker. Utilizzanto bootstrap-datepicker as a single component, there are no problems to set the language, but the same is not true using bootstrap-datepaginator. How can I do?
我正在尝试将意大利语设置为整个项目的默认语言.在 index.html
中,我放置了以下脚本:
I'm trying to set the Italian language as a default for the entire project.
In index.html
I put the following script:
<script src="vendors/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script src="vendors/jquery-ui/ui/i18n/datepicker-it.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker( $.datepicker.regional[ "it" ] );
});
</script>
但在控制台中我收到这些错误:
But in the console I get these errors:
Uncaught TypeError: Cannot read property 'regional' of undefined datepicker-it.js:15
Uncaught TypeError: Cannot read property 'regional' of undefined (index):394
我什么都试过了,但我快疯了!
I tried everything but I'm going crazy!
我是这样修改代码的:
<script src="vendors/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script src="vendors/bootstrap-datepicker/js/locales/bootstrap-datepicker.it.js"></script>
<script>
$(function() {
$.datepicker.setDefaults( $.datepicker.regional["it"] );
});
</script>
但是现在报错如下:
Uncaught TypeError: Cannot read property 'setDefaults' of undefined
<小时>
通过此修复:
With this fix:
$('.datepicker').datepicker({
language: "it"
});
我在控制台中没有出现错误,但默认情况下语言始终为英语
I haven't got errors in console but the language is always english by default
推荐答案
您可以像这样分配 Bootstrap Datepicker 的默认选项:
You can set default options for Bootstrap Datepicker by assigning them like so:
$.fn.datepicker.defaults.language = 'it';
示例如下:
$(document).ready(function(){
$.fn.datepicker.defaults.language = 'it';
});
$(document).ready(function(){
$('.datepicker').datepicker();
});
<link href="https://cdn.jsdelivr.net/bootstrap.datepicker-fork/1.3.0/css/datepicker3.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/bootstrap.datepicker-fork/1.3.0/js/bootstrap-datepicker.js"></script>
<script src="https://cdn.jsdelivr.net/bootstrap.datepicker-fork/1.3.0/js/locales/bootstrap-datepicker.it.js"></script>
<input class="datepicker"/>
这篇关于bootstrap-datepicker 全局设置语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!