Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatables Translation not working

I'm struggling with Datatables translations. As far as I understand the documentation, it should load the language file via Ajax.

I don't see an HTTP request to the file /static/assets/js/datatables_de.json at all (not in Chrome's developer toolbar nor on the server). What am I doing wrong?

$(document).ready(function() {
    var hitstable = $('#hitstable').DataTable({
        "ajax": '/customer/ajax_get_hits',
        "stateSave": true,
        "aoColumnDefs": [
            { aTargets: [0], bSortable: false },
            { aTargets: [1], bSortable: true },
            { aTargets: [2], bSortable: true },
            { aTargets: [3], bSortable: true },
            { aTargets: [4], bSortable: true },
            { aTargets: [5], bSortable: true },
            { aTargets: [6], bSortable: true },
            { aTargets: [7], bSortable: true },
            { aTargets: [8], bSortable: false },
        ],
        "bServerSide": true,
        "order": [[ 1, "asc" ]],
        "oLanguage": {
            sProcessing: '<img src="/static/assets/img/loading.gif">'
        },
        "language": {
            "url": "/static/assets/js/datatables_de.json"
        }
    });
});
like image 453
Daniel Avatar asked Oct 17 '22 22:10

Daniel


1 Answers

I Think I've figured it out.

It seems that oLanguage and language is not compatible. oLanguage is considered legacy, and just by adding it to the configuration it seems like it overrides the language field.

sProcessing is included in the language files, so you should not need to add it to the configuration.

Try and remove the oLanguage: https://jsfiddle.net/fzg38jta/1/

or by adding the language in the oLanguage instead:

{
    "sProcessing":   "Próiseáil...",
    "sLengthMenu":   "Taispeáin iontrálacha _MENU_",
    "sZeroRecords":  "Gan aon taifead meaitseáil aimsithe",
    "sInfo":         "_START_ Showing a _END_ na n-iontrálacha  _TOTAL_",
    "sInfoEmpty":    "Showing 0-0 na n-iontrálacha  0",
    "sInfoFiltered": "(scagtha ó _MAX_ iontrálacha iomlán)",
    "sInfoPostFix":  "",
    "sSearch":       "Cuardaigh:",
    "sUrl":          "",
    "oPaginate": {
        "sFirst":    "An Chéad",
        "sPrevious": "Roimhe Seo",
        "sNext":     "Ar Aghaidh",
        "sLast":     "Last"
    }
}
like image 187
Tom Glover Avatar answered Oct 21 '22 03:10

Tom Glover