Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTables - translate a text which relates to select extension

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 ?

like image 365
Lion King Avatar asked Oct 14 '15 18:10

Lion King


1 Answers

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.

like image 86
Gyrocode.com Avatar answered Sep 21 '22 02:09

Gyrocode.com