更改日期选择器语言不起作用
changing datepicker language is not working
我一直在尝试更改日期选择器显示的语言。默认是英语,我想用法语。
我在搜索过程中得到了一些结果,但 none 似乎对我有用 smh...我已经尝试了那些 ,2, 3, 4, 5 但语言仍然没有变化...我一定是在某个地方做错了什么我猜
这是我的代码的简化版本(包含所有必要信息):
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="{{ asset('main/assets/js/main.js') }} "></script>
<script type="text/javascript" src="{{ asset('main/assets/js/jquery.min.js') }} "></script>
<script type="text/javascript" src=" {{ asset('main/assets/js/bootstrap.min.js') }}"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
<script type="text/javascript" src=" {{ asset('main/assets/js/datepicker-fr.js') }}"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>
</head>
<body>
<input class="date form-control" type="text" id="datepicker" name="date" placeholder="Définir date limite de disponiblité de cette thématique">
<script>
$(function (){
$.datepicker.setDefaults( $.datepicker.regional[ "fr" ] );
$('#datepicker').datepicker({
autoclose: true,
format: 'dd-mm-yyyy'
});
});
</script>
</body>
引用的 datepicker-fr.js
文件是在此处找到的 https://github.com/jquery/jquery-ui/blob/master/ui/i18n/datepicker-fr.js
根据网上查到的,我先后将脚本改为:
<script>
$(function (){
$('#datepicker').datepicker( $.datepicker.regional[ "fr" ] );
});
</script>
<script>
$(function (){
$.datepicker.setDefaults( $.datepicker.regional[ "fr" ] );
$('#datepicker').datepicker();
});
</script>
<script>
$(function (){
$.datepicker.setDefaults( $.datepicker.regional[ "fr" ] );
$('#datepicker').datepicker({
closeText: "Fermer",
prevText: "Précédent",
nextText: "Suivant",
currentText: "Aujourd'hui",
monthNames: [ "janvier", "février", "mars", "avril", "mai", "juin",
"juillet", "août", "septembre", "octobre", "novembre", "décembre" ],
monthNamesShort: [ "janv.", "févr.", "mars", "avr.", "mai", "juin",
"juil.", "août", "sept.", "oct.", "nov.", "déc." ],
dayNames: [ "dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi" ],
dayNamesShort: [ "dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam." ],
dayNamesMin: [ "D","L","M","M","J","V","S" ],
weekHeader: "Sem.",
dateFormat: "dd/mm/yy",
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ""
});
});
</script>
日期仍以英文显示,我没有在控制台中看到任何问题。我在这里错过了什么?非常感谢您的帮助谢谢
只需包含 jQuery-Ui
并设置 fr
作为默认语言,当然是在 init
之前
$(function() {
$.datepicker.regional['fr'] = {
closeText: "Fermer",
prevText: "Précédent",
nextText: "Suivant",
currentText: "Aujourd'hui",
monthNames: ["janvier", "février", "mars", "avril", "mai", "juin",
"juillet", "août", "septembre", "octobre", "novembre", "décembre"
],
monthNamesShort: ["janv.", "févr.", "mars", "avr.", "mai", "juin",
"juil.", "août", "sept.", "oct.", "nov.", "déc."
],
dayNames: ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
dayNamesShort: ["dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam."],
dayNamesMin: ["D", "L", "M", "M", "J", "V", "S"],
weekHeader: "Sem.",
dateFormat: "dd/mm/yy",
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ""
};
$.datepicker.setDefaults($.datepicker.regional['fr']);
$('#datepicker').datepicker();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" integrity="sha256-rByPlHULObEjJ6XQxW/flG2r+22R5dKiAoef+aXWfik=" crossorigin="anonymous" />
<input id="datepicker" />
我一直在尝试更改日期选择器显示的语言。默认是英语,我想用法语。
我在搜索过程中得到了一些结果,但 none 似乎对我有用 smh...我已经尝试了那些
这是我的代码的简化版本(包含所有必要信息):
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="{{ asset('main/assets/js/main.js') }} "></script>
<script type="text/javascript" src="{{ asset('main/assets/js/jquery.min.js') }} "></script>
<script type="text/javascript" src=" {{ asset('main/assets/js/bootstrap.min.js') }}"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
<script type="text/javascript" src=" {{ asset('main/assets/js/datepicker-fr.js') }}"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>
</head>
<body>
<input class="date form-control" type="text" id="datepicker" name="date" placeholder="Définir date limite de disponiblité de cette thématique">
<script>
$(function (){
$.datepicker.setDefaults( $.datepicker.regional[ "fr" ] );
$('#datepicker').datepicker({
autoclose: true,
format: 'dd-mm-yyyy'
});
});
</script>
</body>
引用的 datepicker-fr.js
文件是在此处找到的 https://github.com/jquery/jquery-ui/blob/master/ui/i18n/datepicker-fr.js
根据网上查到的,我先后将脚本改为:
<script>
$(function (){
$('#datepicker').datepicker( $.datepicker.regional[ "fr" ] );
});
</script>
<script>
$(function (){
$.datepicker.setDefaults( $.datepicker.regional[ "fr" ] );
$('#datepicker').datepicker();
});
</script>
<script>
$(function (){
$.datepicker.setDefaults( $.datepicker.regional[ "fr" ] );
$('#datepicker').datepicker({
closeText: "Fermer",
prevText: "Précédent",
nextText: "Suivant",
currentText: "Aujourd'hui",
monthNames: [ "janvier", "février", "mars", "avril", "mai", "juin",
"juillet", "août", "septembre", "octobre", "novembre", "décembre" ],
monthNamesShort: [ "janv.", "févr.", "mars", "avr.", "mai", "juin",
"juil.", "août", "sept.", "oct.", "nov.", "déc." ],
dayNames: [ "dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi" ],
dayNamesShort: [ "dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam." ],
dayNamesMin: [ "D","L","M","M","J","V","S" ],
weekHeader: "Sem.",
dateFormat: "dd/mm/yy",
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ""
});
});
</script>
日期仍以英文显示,我没有在控制台中看到任何问题。我在这里错过了什么?非常感谢您的帮助谢谢
只需包含 jQuery-Ui
并设置 fr
作为默认语言,当然是在 init
$(function() {
$.datepicker.regional['fr'] = {
closeText: "Fermer",
prevText: "Précédent",
nextText: "Suivant",
currentText: "Aujourd'hui",
monthNames: ["janvier", "février", "mars", "avril", "mai", "juin",
"juillet", "août", "septembre", "octobre", "novembre", "décembre"
],
monthNamesShort: ["janv.", "févr.", "mars", "avr.", "mai", "juin",
"juil.", "août", "sept.", "oct.", "nov.", "déc."
],
dayNames: ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
dayNamesShort: ["dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam."],
dayNamesMin: ["D", "L", "M", "M", "J", "V", "S"],
weekHeader: "Sem.",
dateFormat: "dd/mm/yy",
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ""
};
$.datepicker.setDefaults($.datepicker.regional['fr']);
$('#datepicker').datepicker();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" integrity="sha256-rByPlHULObEjJ6XQxW/flG2r+22R5dKiAoef+aXWfik=" crossorigin="anonymous" />
<input id="datepicker" />