1

为了使用 jQuery datepicker,我为我的 Wordpress 博客站点加载了这些脚本:

<link rel='stylesheet' id='jquery-ui-css-css' href='http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css?ver=4.7.3' type='text/css' media='all' />
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js?ver=4.7.3'></script>
<script type='text/javascript' src='https://code.jquery.com/ui/1.12.1/jquery-ui.js?ver=4.7.3'></script>
<script type='text/javascript' src='http://jquery-ui.googlecode.com/svn/tags/latest/ui/minified/i18n/jquery-ui-i18n.min.js?ver=4.7.3'></script>
<script type='text/javascript' src='http://mywebaddress.com/wp-content/themes/twentyseventeen-child/wpadverts/js/datepicker-ro.js?ver=4.7.3'></script>

我有这段代码用于本地化datepicker

<script>
    $( function() {
        $('#adverts_eventDate').datepicker($.extend({}, $.datepicker.regional['ro'], {
            showButtonPanel : true,
            dateFormat : 'dd-mm-yy'
        }));
        } );
</script>

这段代码有效,所以我有一个日期选择器,但它没有本地化(罗马尼亚语),它是英文的。我的代码有什么问题?

这就是这些脚本在我的 Wordpress 子主题中的排列方式:

if ( !function_exists( 'wpadverts_plugin_custom_styles' ) ):
   function wpadverts_plugin_custom_styles() {
      wp_enqueue_script( 'jquery-min-js', 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js' );
      wp_enqueue_style( 'jquery-ui-css', 'http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css');
      wp_enqueue_script( 'jquery-ui-js', 'https://code.jquery.com/ui/1.12.1/jquery-ui.js' );
      wp_enqueue_script( 'jquery-ui-i18n-min', 'http://jquery-ui.googlecode.com/svn/tags/latest/ui/minified/i18n/jquery-ui-i18n.min.js' );
      wp_enqueue_script( 'jquery-ui-datepicker-ro', get_stylesheet_directory_uri() . '/wpadverts/js/datepicker-ro.js', array( 'jquery' ) );
   }
endif;
add_action( 'wp_enqueue_scripts', 'wpadverts_plugin_custom_styles' );

更新

现在我的本地化日期选择器看起来像这样:

<script>
jQuery(function($){
    $.datepicker.regional['ro'] = {
        closeText: 'Închide',
        prevText: '&laquo; Luna precedentă',
        nextText: 'Luna următoare &raquo;',
        currentText: 'Azi',
        monthNames: ['Ianuarie','Februarie','Martie','Aprilie','Mai','Iunie',
    'Iulie','August','Septembrie','Octombrie','Noiembrie','Decembrie'],
        monthNamesShort: ['Ian', 'Feb', 'Mar', 'Apr', 'Mai', 'Iun',
    'Iul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        dayNames: ['Duminică', 'Luni', 'Marţi', 'Miercuri', 'Joi', 'Vineri', 'Sâmbătă'],
        dayNamesShort: ['Dum', 'Lun', 'Mar', 'Mie', 'Joi', 'Vin', 'Sâm'],
        dayNamesMin: ['Du','Lu','Ma','Mi','Jo','Vi','Sâ'],
        weekHeader: 'Săpt',
        dateFormat: 'dd.mm.yy',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''
    };
    $.datepicker.setDefaults($.datepicker.regional['ro']);
});

$( '#adverts_eventDate' ).datepicker( $.datepicker.regional['ro'] );

</script>
4

2 回答 2

2

包括这个并尝试

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/i18n/jquery-ui-i18n.min.js"></script>

小提琴

使用你的 JS

 $(function() {
   $('#adverts_eventDate').datepicker($.extend({}, $.datepicker.regional['ro'], {
     showButtonPanel: true,
     dateFormat: 'dd-mm-yy'
   }));
 });
于 2017-03-14T11:51:09.697 回答
1

试试下面的例子,你如何自己做本地化。

jQuery(function($){
    $.datepicker.regional['ro'] = {
        closeText: 'Închide',
        prevText: '&laquo; Luna precedentă',
        nextText: 'Luna următoare &raquo;',
        currentText: 'Azi',
        monthNames: ['Ianuarie','Februarie','Martie','Aprilie','Mai','Iunie',
    'Iulie','August','Septembrie','Octombrie','Noiembrie','Decembrie'],
        monthNamesShort: ['Ian', 'Feb', 'Mar', 'Apr', 'Mai', 'Iun',
    'Iul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        dayNames: ['Duminică', 'Luni', 'Marţi', 'Miercuri', 'Joi', 'Vineri', 'Sâmbătă'],
        dayNamesShort: ['Dum', 'Lun', 'Mar', 'Mie', 'Joi', 'Vin', 'Sâm'],
        dayNamesMin: ['Du','Lu','Ma','Mi','Jo','Vi','Sâ'],
        weekHeader: 'Săpt',
        dateFormat: 'dd.mm.yy',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''
    };
    $.datepicker.setDefaults($.datepicker.regional['ro']);
});
于 2017-03-14T10:59:05.367 回答