DataTables - 翻译与select extension

时间:2015-10-14 18:56:53

标签: javascript datatables

我正在使用带有Select扩展名的jQuery DataTables v1.10.9。

选择一行或多行时,底部会显示一个文字,例如 “选择了2行”,请参见下面的屏幕截图:

语言档案:

{
    "sEmptyTable":     "No data available in table",
    "sInfo":           "Showing _START_ to _END_ of _TOTAL_ entries",
    "sInfoEmpty":      "Showing 0 to 0 of 0 entries",
    "sInfoFiltered":   "(filtered from _MAX_ total entries)",
    "sInfoPostFix":    "",
    "sInfoThousands":  ",",
    "sLengthMenu":     "Show _MENU_ entries",
    "sLoadingRecords": "Loading...",
    "sProcessing":     "Processing...",
    "sSearch":         "Search:",
    "sZeroRecords":    "No matching records found",
    "oPaginate": {
        "sFirst":    "First",
        "sLast":     "Last",
        "sNext":     "Next",
        "sPrevious": "Previous"
    },
    "select": {
        "rows": {
            "_": "You have selected %d rows",
            "0": "Click a row to select",
            "1": "1 row selected"
        }
    }
}

表格初始化:

dataTableY = $('#tableID').DataTable({
    serverSide: true,
    ajax: {
        url: myProp.base_url + 'directory/class/method'
    },
    processing: true,
    scrollY: 420,
    paging: true,
    info: true,
    searchable: true,
    select: {
        style: 'os'
    },
    pagingType: 'full_numbers',
    language: {
        url: myProp.base_url + '/DataTables/lang/language.json'
    }
});

如何翻译此文字?

1 个答案:

答案 0 :(得分:7)

使用以下代码:

$(document).ready(function() {
    $('#example').DataTable( {
        select: true,
        language: {
            select: {
                rows: {
                    _: "You have selected %d rows",
                    0: "Click a row to select it",
                    1: "Only 1 row selected"
                }
            }
        }
    } );
} );

请参阅Select - Internationalization example进行演示。

如果您想在语言文件中使用它,请使用以下格式:

{
    "sEmptyTable":     "No data available in table",
    "sInfo":           "Showing _START_ to _END_ of _TOTAL_ entries",
    "sInfoEmpty":      "Showing 0 to 0 of 0 entries",
    "sInfoFiltered":   "(filtered from _MAX_ total entries)",
    "sInfoPostFix":    "",
    "sInfoThousands":  ",",
    "sLengthMenu":     "Show _MENU_ entries",
    "sLoadingRecords": "Loading...",
    "sProcessing":     "Processing...",
    "sSearch":         "Search:",
    "sZeroRecords":    "No matching records found",
    "oPaginate": {
        "sFirst":    "First",
        "sLast":     "Last",
        "sNext":     "Next",
        "sPrevious": "Previous"
    },
    "select": {
        "rows": {
            "_": "You have selected %d rows",
            "0": "Click a row to select",
            "1": "1 row selected"
        }
    }
}

请参阅this jsFiddle以获取代码和演示。