Asped
Asped

Reputation: 3103

Datatables oLanguage (internationalisation) default setting

I have a problem with setting up i18n in datatables. I know there is the oLanguage setting, which can point to an url, or which can be naually overwritten. But the problem is, that I need to to be set for ALL datatables on the page. Any other settings can be preset by extending the default options, but this does not work with the oLanguage for some reason.

$(document).ready(function(){
    // set up defaults for datatables
    $.extend( $.fn.dataTable.defaults, {
        "bFilter": false,
        "bProcessing": true,
        "bLengthChange":false,
        "sPaginationType": "full_numbers",
        "sDom": 'rtp',
        "oLanguage": {
            "sUrl": "themes/simple/javascript/dataTables-sk.js"
        },
        "bServerSide": true

    });
});

When I do it at initialisation, it works:

$('table').dataTable( {
   "oLanguage": {
      "sUrl": "themes/simple/javascript/dataTables-sk.js"
   },
});

Any idea where the problem is?

Upvotes: 0

Views: 5719

Answers (4)

kurdemol94
kurdemol94

Reputation: 604

I had the same problem with DataTables 1.10.12. Tried different combinations similar to what @ruben-dario-perez wrote, but I only wanted to modify a few strings, and I was getting an error that "oPaginate" was not defined. Changing "oLanguage" to "language" made it work! Here's how my code looks like:

$.extend($.fn.dataTable.defaults, {
language: {
    sInfo: GlobalTranslations.Showing_START_to_END_of_TOTAL_entries,
    sInfoEmpty: GlobalTranslations.ListEmpty,
    sEmptyTable: GlobalTranslations.ListEmpty
}});

Upvotes: 0

tomrlh
tomrlh

Reputation: 1066

This question was a long time ago, but I fixed it setting the desired language to be default in jquery.data-tables.js,in the "oPaginate": "sUrl" as you said, but I put the direct link, in my case:

"sUrl": "//cdn.datatables.net/plug-ins/1.10.13/i18n/Portuguese-Brasil.json"

Hope it help someone else.

Upvotes: 0

Ruben Dario Perez
Ruben Dario Perez

Reputation: 31

I don't know if its exactly your problem, but one time i need to localize all my DataTables, and i extend the oLanguage default property like this:

    $.extend( true, $.fn.dataTable.defaults, {
    oLanguage : {
        "sProcessing":     "Procesando...",
        "sLengthMenu":     "Mostrar _MENU_ registros",
        "sZeroRecords":    "No se encontraron resultados",
        "sEmptyTable":     "Ningún dato disponible en esta tabla",
        "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
        "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
        "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
        "sInfoPostFix":    "",
        "sSearch":         "Buscar:",
        "sUrl":            "",
        "sInfoThousands":  ",",
        "sLoadingRecords": "Cargando...",
        "oPaginate": {
            "sFirst":    "Primero",
            "sLast":     "Último",
            "sNext":     "Siguiente",
            "sPrevious": "Anterior"
        },
        "oAria": {
            "sSortAscending":  ": Activar para ordenar la columna de manera ascendente",
            "sSortDescending": ": Activar para ordenar la columna de manera descendente"
        }
    }
});

I put it in a script that i render in top of my page, and all the DataTables in my app become localized. In my case i get the translation in the offitial DataTables translations page (Spanish in my case):

https://datatables.net/plug-ins/i18n/

I dont know if im so late, but i find this question recently.

Sorry about my English.

Good luck!

Upvotes: 3

Asped
Asped

Reputation: 3103

I haven't found out anything more about this. It seems to be a very specifi bug to a specific system (I was using the Silverstripe framework), and on any other system/framework this works without any problems

Upvotes: -1

Related Questions