Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatables change interface language

I am currently using angular-datatables.

How can I see the interface of the table in other languages?

I mean the "Show entries", "Search:", "Showing 1 to 10 of 20 entries" literals fore example in Spanish.

like image 209
Egidi Avatar asked Apr 25 '16 19:04

Egidi


People also ask

How do I change the language displayed by DataTables?

Language options. Changing the language information displayed by DataTables is as simple as passing in a language object to the DataTable constructor. This example shows a different set of English string being used, rather than the defaults. Display.

Is DataTables internationalisable?

This ensures that DataTables is fully internationalisable as strings for any language can be used. The default language options for DataTables are shown below for reference. Additionally there are a wide range of translations readily available on this site, in the internationalisation plug-ins.

Are there any translations available for DataTables?

Additionally there are a wide range of translations readily available on this site, in the internationalisation plug-ins. The following is the default object that DataTables uses for its language strings (for information about each individual parameter, please see its individual documentation document):

What language is used to perform the server-side processing for this table?

The script used to perform the server-side processing for this table is shown below. Please note that this is just an example script using PHP. Server-side processing scripts can be written in any language, using the protocol described in the DataTables documentation.


3 Answers

I created a .ts file like this:

export class LanguageApp {
  public static spanish_datatables = {
    processing: "Procesando...",
    search: "Buscar:",
    lengthMenu: "Mostrar _MENU_ &elementos",
    info: "Mostrando desde _START_ al _END_ de _TOTAL_ elementos",
    infoEmpty: "Mostrando ningún elemento.",
    infoFiltered: "(filtrado _MAX_ elementos total)",
    infoPostFix: "",
    loadingRecords: "Cargando registros...",
    zeroRecords: "No se encontraron registros",
    emptyTable: "No hay datos disponibles en la tabla",
    paginate: {
      first: "Primero",
      previous: "Anterior",
      next: "Siguiente",
      last: "Último"
    },
    aria: {
      sortAscending: ": Activar para ordenar la tabla en orden ascendente",
      sortDescending: ": Activar para ordenar la tabla en orden descendente"
    }
  }
}

Then in the component that was loading the DataTable just put that config inside dtOptions:

this.dtOptions = { 
      language: LanguageApp.spanish_datatables
};
like image 119
Sergio Laureano Avatar answered Oct 09 '22 08:10

Sergio Laureano


In Angular2+ what worked for me is quite the same as mentioned by @davidkonrad, but without the starting letters (s and o), and adding the language as an attribute of the dtOptions. I.e.:

this.dtOptions = {
  pagingType: 'full_numbers',
  pageLength: 10,
  dom: 'Bfrtip',
  buttons: [
    /*'print',
    'csv'*/
  ],
  responsive: true,
  /* below is the relevant part, e.g. translated to spanish */ 
  language: {
    processing: "Procesando...",
    search: "Buscar:",
    lengthMenu: "Mostrar _MENU_ éléments",
    info: "Mostrando desde _START_ al _END_ de _TOTAL_ elementos",
    infoEmpty: "Mostrando ningún elemento.",
    infoFiltered: "(filtrado _MAX_ elementos total)",
    infoPostFix: "",
    loadingRecords: "Cargando registros...",
    zeroRecords: "No se encontraron registros",
    emptyTable: "No hay datos disponibles en la tabla",
    paginate: {
      first: "Primero",
      previous: "Anterior",
      next: "Siguiente",
      last: "Último"
    },
    aria: {
      sortAscending: ": Activar para ordenar la tabla en orden ascendente",
      sortDescending: ": Activar para ordenar la tabla en orden descendente"
    }
  }
};
like image 27
Laszlo Sarvold Avatar answered Oct 09 '22 10:10

Laszlo Sarvold


You need to define a language struct like this (danish implementation, what I am using in my angular-datatables apps) :

var language = {
  "sEmptyTable": "Ingen tilgængelige data (prøv en anden søgning)",
  "sInfo": "Viser _START_ til _END_ af _TOTAL_ rækker",
  "sInfoEmpty": "Viser 0 til 0 af 0 rækker",
  "sInfoFiltered": "(filtreret ud af _MAX_ rækker ialt)",
  "sInfoPostFix": "",
  "sInfoThousands": ",",
  "sLengthMenu": "Vis _MENU_ rækker",
  "sLoadingRecords": "Henter data...",
  "sProcessing": "Processing...",
  "sSearch": "Filter:",
  "sZeroRecords": "Ingen rækker matchede filter",
  "oPaginate": {
    "sFirst": "Første",
    "sLast": "Sidste",
    "sNext": "Næste",
    "sPrevious": "Forrige"
  },
  "oAria": {
    "sSortAscending": ": activate to sort column ascending",
    "sSortDescending": ": activate to sort column descending"
  }
}

There is a bunch of languages here -> https://www.datatables.net/plug-ins/i18n/

And then you include the language using the withLanguage() option method

.withLanguage(language)

demo -> http://plnkr.co/edit/RCrqM3z7qwsUfFwy8HE6?p=preview

like image 23
davidkonrad Avatar answered Oct 09 '22 10:10

davidkonrad