最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - DataTables - translate a text which relates to select extension - Stack Overflow

programmeradmin2浏览0评论

I'm using jQuery DataTables v1.10.9 with Select extension.

When selecting a row or more, there is a text that appears in the bottom, for example, "2 rows selected", see the screenshot below:

Language File:

{
    "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"
        }
    }
}

Table initialization:

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'
    }
});

How can I translate this text ?

I'm using jQuery DataTables v1.10.9 with Select extension.

When selecting a row or more, there is a text that appears in the bottom, for example, "2 rows selected", see the screenshot below:

Language File:

{
    "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"
        }
    }
}

Table initialization:

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'
    }
});

How can I translate this text ?

Share Improve this question edited Oct 18, 2015 at 16:03 Lion King asked Oct 14, 2015 at 18:56 Lion KingLion King 33.9k26 gold badges90 silver badges157 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Use the code below:

$(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"
                }
            }
        }
    } );
} );

See Select - Internationalization example for demonstration.

If you would like to use it in the language file, use the format below:

{
    "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"
        }
    }
}

See this jsFiddle for code and demonstration.

发布评论

评论列表(0)

  1. 暂无评论