jquerydatatables

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 ?


Solution

  • 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