2015-10-14 3 views
6

Sto usando jQuery DataTables v1.10.9 con Select extension.DataTables - traduce un testo relativo all'estensione selezionata

Quando si seleziona una riga o più, v'è un testo che appare nella parte inferiore, per esempio, "2 file selezionati", vedere la schermata qui sotto:

Language File:

{ 
    "sEmptyTable":  "No data available in table", 
    "sInfo":   "Showing _START_ to _END_ of _TOTAL_ entries", 
    "sInfoEmpty":  "Showing 0 to 0 of 0 entries", 
    "sInfoFiltered": "(filtered from _MAX_ total entries)", 
    "sInfoPostFix": "", 
    "sInfoThousands": ",", 
    "sLengthMenu":  "Show _MENU_ entries", 
    "sLoadingRecords": "Loading...", 
    "sProcessing":  "Processing...", 
    "sSearch":   "Search:", 
    "sZeroRecords": "No matching records found", 
    "oPaginate": { 
     "sFirst": "First", 
     "sLast":  "Last", 
     "sNext":  "Next", 
     "sPrevious": "Previous" 
    }, 
    "select": { 
     "rows": { 
      "_": "You have selected %d rows", 
      "0": "Click a row to select", 
      "1": "1 row selected" 
     } 
    } 
} 

Tabella inizializzazione:

dataTableY = $('#tableID').DataTable({ 
    serverSide: true, 
    ajax: { 
     url: myProp.base_url + 'directory/class/method' 
    }, 
    processing: true, 
    scrollY: 420, 
    paging: true, 
    info: true, 
    searchable: true, 
    select: { 
     style: 'os' 
    }, 
    pagingType: 'full_numbers', 
    language: { 
     url: myProp.base_url + '/DataTables/lang/language.json' 
    } 
}); 

Come posso tradurre questo testo?

risposta

6

Utilizzare il codice qui sotto:

$(document).ready(function() { 
    $('#example').DataTable({ 
     select: true, 
     language: { 
      select: { 
       rows: { 
        _: "You have selected %d rows", 
        0: "Click a row to select it", 
        1: "Only 1 row selected" 
       } 
      } 
     } 
    }); 
}); 

Vedi Select - Internationalization example per la dimostrazione.

Se si desidera utilizzare nel file di lingua, utilizzare il formato di seguito:

{ 
    "sEmptyTable":  "No data available in table", 
    "sInfo":   "Showing _START_ to _END_ of _TOTAL_ entries", 
    "sInfoEmpty":  "Showing 0 to 0 of 0 entries", 
    "sInfoFiltered": "(filtered from _MAX_ total entries)", 
    "sInfoPostFix": "", 
    "sInfoThousands": ",", 
    "sLengthMenu":  "Show _MENU_ entries", 
    "sLoadingRecords": "Loading...", 
    "sProcessing":  "Processing...", 
    "sSearch":   "Search:", 
    "sZeroRecords": "No matching records found", 
    "oPaginate": { 
     "sFirst": "First", 
     "sLast":  "Last", 
     "sNext":  "Next", 
     "sPrevious": "Previous" 
    }, 
    "select": { 
     "rows": { 
      "_": "You have selected %d rows", 
      "0": "Click a row to select", 
      "1": "1 row selected" 
     } 
    } 
} 

Vedi this jsFiddle per il codice e la dimostrazione.

+0

Grazie, funziona solo quando lo aggiungi a 'language {}' direttamente come nel tuo esempio, ma quando lo aggiungi al file di linguaggio json non funziona. –

+0

@LionKing, vedere [questo esempio] (https://jsfiddle.net/scw8dp55/), funziona anche con il file di lingua. –

+0

@LionKing, il controllo delle informazioni è ancora errato 'Da 1 a 50 di 1208 voci (filtrate da 50 voci totali)', sembra che tu abbia 'recordsTotal' e' recordsFiltered' di nuovo scambiato. –