Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change language for DataTable

I store, in a session variable, which language does user wants to translate but I don't know to pass it DataTables

I found this explanation on the datatables website but that didn't really help, where do I set language param ?

like image 360
PHP Ferrari Avatar asked Nov 12 '12 10:11

PHP Ferrari


People also ask

How to set language in jQuery datatable?

u can try other language "oLanguage": { "sUrl": "//cdn.datatables.net/plug-ins/1.10.7/i18n/<LANGUAGE>. json" } a open datatables.net/plug-ins/i18n and look translation is click ur language later take CDN links :) This does not seem to work any more in 1.10.

How do I change the length of a data table?

Use page. len() API function to change page length dynamically. This method changes the number of rows shown, but the number in the Show x Entries select box remains the same.


5 Answers

You have to either create a language file and then set it using :

"oLanguage": {
  "sUrl": "media/language/your_file.txt"
}

Im not sure what server language you are using but something like this would work in PHP :

"oLanguage": {
  "sUrl": "media/language/custom_lang_<?php echo $language ?>.txt"
}

Where language matches the file name for a specific language.

or change individual settings :

"oLanguage": {
  "sLengthMenu": "Display _MENU_ records per page",
  "sZeroRecords": "Nothing found - sorry",
  "sInfo": "Showing _START_ to _END_ of _TOTAL_ records",
  "sInfoEmpty": "Showing 0 to 0 of 0 records",
  "sInfoFiltered": "(filtered from _MAX_ total records)"
}

For more details read this : http://datatables.net/plug-ins/i18n

like image 142
Manse Avatar answered Oct 08 '22 01:10

Manse


//Spanish
$('#TableName').DataTable({
    "language": {
        "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"
        }
    }
});

Also using a cdn:

//cdn.datatables.net/plug-ins/a5734b29083/i18n/Spanish.json

More options: http://www.datatables.net/plug-ins/i18n/English [| Spanish | etc]

like image 32
Carlos Espinoza Avatar answered Oct 08 '22 00:10

Carlos Espinoza


for Arabic language

 var table = $('#my_table')
                .DataTable({
                 "columns":{//......}
                 "language": 
                        {
                            "sProcessing": "جارٍ التحميل...",
                            "sLengthMenu": "أظهر _MENU_ مدخلات",
                            "sZeroRecords": "لم يعثر على أية سجلات",
                            "sInfo": "إظهار _START_ إلى _END_ من أصل _TOTAL_ مدخل",
                            "sInfoEmpty": "يعرض 0 إلى 0 من أصل 0 سجل",
                            "sInfoFiltered": "(منتقاة من مجموع _MAX_ مُدخل)",
                            "sInfoPostFix": "",
                            "sSearch": "ابحث:",
                            "sUrl": "",
                            "oPaginate": {
                                "sFirst": "الأول",
                                "sPrevious": "السابق",
                                "sNext": "التالي",
                                "sLast": "الأخير"
                            }
                        }
                });

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

Author: Ossama Khayat

like image 7
Basheer AL-MOMANI Avatar answered Oct 08 '22 00:10

Basheer AL-MOMANI


French translations:

$('#my_table').DataTable({
  "language": {
    "sProcessing": "Traitement en cours ...",
    "sLengthMenu": "Afficher _MENU_ lignes",
    "sZeroRecords": "Aucun résultat trouvé",
    "sEmptyTable": "Aucune donnée disponible",
    "sInfo": "Lignes _START_ à _END_ sur _TOTAL_",
    "sInfoEmpty": "Aucune ligne affichée",
    "sInfoFiltered": "(Filtrer un maximum de_MAX_)",
    "sInfoPostFix": "",
    "sSearch": "Chercher:",
    "sUrl": "",
    "sInfoThousands": ",",
    "sLoadingRecords": "Chargement...",
    "oPaginate": {
      "sFirst": "Premier", "sLast": "Dernier", "sNext": "Suivant", "sPrevious": "Précédent"
    },
    "oAria": {
      "sSortAscending": ": Trier par ordre croissant", "sSortDescending": ": Trier par ordre décroissant"
    }
  }
});

});

like image 7
Benjamin Crouzier Avatar answered Oct 08 '22 01:10

Benjamin Crouzier


sorry to revive this thread, i know there is the solution, but it is easy to change the language with the datatables. Here, i leave you with my own datatable example.

$(document).ready(function ()
// DataTable
        var table = $('#tblUsuarios').DataTable({
            aoColumnDefs: [
                {"aTargets": [0], "bSortable": true},
                {"aTargets": [2], "asSorting": ["asc"], "bSortable": true},
            ],
            "language": {
                "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Spanish.json"
            }

    });

The language you get from the following link:

http://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n

Just replace the URL value in the language option with the one you like. Remember to always use the comma


Worked for me, hope it will work for anyone.

Best regards!

like image 15
m_santamaria Avatar answered Oct 07 '22 23:10

m_santamaria