Search code examples
datatablesangular-ui-bootstrap

DataTable in Angular How can I change the language


how to change language for DataTable from english to french in Angular this is my Code

<table #mytable *ngIf="utilisateurs" datatable class="row-border hover">
<thead>
    <tr>
        <th>Nom</th>
        <th>Prenom</th>
        <th>Email</th>
        <th>Preference</th>
        <th>Pointe Vente</th>
        <th>Type Utilisateur</th>
        <th>Date Creation</th>
        <th>Action</th>
    </tr>
</thead>
<tbody>
    <tr *ngFor="let u of utilisateurs">
        <td>{{ u.nom }}</td>
        <td>{{ u.prenom }}</td>
        <td>{{ u.email }}</td>
        <td>{{ u.preference }}</td>
        <td>{{ u.nomPointeVente }}</td>
        <td>{{ u.typeUtilisateur }}</td>
        <td>{{ u.dateCreation }}</td>
        <td><i title="editer"  (click)="editer(u)"  class="fas fa-user-edit" style="margin:10px; "   
            data-toggle="modal" data-target="#myModaledit"></i>  <i title="supprimer" class="fas fa-user-times" style="margin:10px; "></i>  <i title="details" class="fas fa-info-circle"style="margin:10px; "></i>  </td>
    </tr>
</tbody>

and this is the correction in JQuery Haw can i do this in angular

<script type="text/javascript">
$(document).ready(function() {
    $('#example').dataTable( {
        "language": {
            "url": "dataTables.german.lang"
        }
    } );
} );


Solution

  • This is a good example of changing the language in datatables: in your exemplecomponent.ts file

    dtOptions: any  = {};
    
      ngOnInit(): void {
        this.dtOptions = {
          language: {
            processing:     "Traitement en cours...",
            search:         "Rechercher&nbsp;:",
            lengthMenu:    "Afficher _MENU_ &eacute;l&eacute;ments",
            info:           "Affichage de l'&eacute;lement _START_ &agrave; _END_ sur _TOTAL_ &eacute;l&eacute;ments",
            infoEmpty:      "Affichage de l'&eacute;lement 0 &agrave; 0 sur 0 &eacute;l&eacute;ments",
            infoFiltered:   "(filtr&eacute; de _MAX_ &eacute;l&eacute;ments au total)",
            infoPostFix:    "",
            loadingRecords: "Chargement en cours...",
            zeroRecords:    "Aucun &eacute;l&eacute;ment &agrave; afficher",
            emptyTable:     "Aucune donnée disponible dans le tableau",
            paginate: {
                first:      "Premier",
                previous:   "Pr&eacute;c&eacute;dent",
                next:       "Suivant",
                last:       "Dernier"
            },
            aria: {
                sortAscending:  ": activer pour trier la colonne par ordre croissant",
                sortDescending: ": activer pour trier la colonne par ordre décroissant"
            }
        },
          pagingType: 'full_numbers',
          pageLength: 10,
          processing: true,
        };
      }