如何将jquery ui datepicker翻译成多种语言?

问题描述 投票:0回答:1

我有多家商店,有多种语言:en、de、nl、fr 等。 我需要翻译 jquery datepicker。 这是我的代码:

jQuery(function(){
    region = jQuery('html').attr('lang');// get the lang code
    jQuery("#scheduled_at").datepicker(
        {
        minDate: +3,
        maxDate: "+3M" ,
        dateFormat : 'dd-mm-yy',
        beforeShowDay: jQuery.datepicker.noWeekends,
        firstDay: 1
    });
});

我看到了这个回购协议: https://github.com/jquery/jquery-ui/tree/master/ui/i18n 包含所有翻译,但我不需要全部。只是几个。

en 翻译示例:

/* jQuery UI 日期选择器插件的英语/英国初始化。 */

/* Written by Stuart. */
( function( factory ) {
    if ( typeof define === "function" && define.amd ) {

        // AMD. Register as an anonymous module.
        define( [ "../widgets/datepicker" ], factory );
    } else {

        // Browser globals
        factory( jQuery.datepicker );
    }
}( function( datepicker ) {

    datepicker.regional[ "en-GB" ] = {
        closeText: "Done",
        prevText: "Prev",
        nextText: "Next",
        currentText: "Today",
        monthNames: [ "January","February","March","April","May","June",
            "July","August","September","October","November","December" ],
        monthNamesShort: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ],
        dayNames: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
        dayNamesShort: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
        dayNamesMin: [ "Su","Mo","Tu","We","Th","Fr","Sa" ],
        weekHeader: "Wk",
        dateFormat: "dd/mm/yy",
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: "" };
    datepicker.setDefaults( datepicker.regional[ "en-GB" ] );

    return datepicker.regional[ "en-GB" ];

} ) );

如何添加:

jQuery.datepicker.regional[region]
就我而言?对于 de、nl、fr 和 en ?

我看到这篇文章:jQuery Datepicker 本地化,但它仅适用于一种语言。

谢谢你

javascript jquery jquery-ui-datepicker
1个回答
0
投票

然后你可以使用:

$( selector ).datepicker( $.datepicker.regional[ "en" ] );
$( selector ).datepicker( $.datepicker.regional[ "de" ] );
$( selector ).datepicker( $.datepicker.regional[ "nl" ] );
$( selector ).datepicker( $.datepicker.regional[ "fr" ] );

动态的东西可以使用 jQuery 变量:

var languages = "en","fr";

 $( selector ).datepicker( $.datepicker.regional[ +languages+ ] );
© www.soinside.com 2019 - 2024. All rights reserved.