Integrate confirm message for remove and update into language defaults

Integrate confirm message for remove and update into language defaults

rf1234rf1234 Posts: 2,946Questions: 87Answers: 416

I have been trying to do my language settings in case the user's language is not English. I am almost done, but I don't know how to set the confirm message for deletion or update of rows.
So far I have only been able to set this individually for the specific table which is a nuisance because of so much code redundancy. As you can see I tried to integrate something i18n based. This code works when used within the individual Editor definition but not here. Any ideal how to resolve this please?

function dataTablesInit() {   
    //Data tables default new button labels
    var showAllLabel = 'Show all';
    
    //Data tables language settings
    if (lang === 'de') {
        showAllLabel = 'Alles anzeigen';        
        $.extend( true, $.fn.dataTable.defaults, {
//            "i18n": {
//                remove: {
//                    confirm: {
//                        _: 'Sind Sie sicher, dass Sie %d Zeilen löschen wollen?',
//                        1: 'Sind Sie sicher, dass Sie eine Zeile löschen wollen?'
//                    }
//                }
//            },
            "language": {
                "decimal": ",",
                "thousands": ".",
                "info": "Anzeige _START_ bis _END_ von _TOTAL_ Einträgen",
                "infoEmpty": "Keine Einträge",
                "infoPostFix": "",
                "infoFiltered": " - gefiltert aus insgesamt _MAX_ Einträgen",
                "loadingRecords": "Bitte warten Sie - Daten werden geladen ...",
                "paginate": {
                    "first": "Erste",
                    "last": "Letzte",
                    "next": "Nächste",
                    "previous": "Zurück"
                },
                "processing": "Verarbeitung läuft ...",
                "search": "Suche:",
                "searchPlaceholder": "Suchbegriff",
                "zeroRecords": "Keine Daten! Bitte ändern Sie Ihren Suchbegriff.",
                "emptyTable": "Keine Daten vorhanden",
                "aria": {
                    "sortAscending":  ": aktivieren, um Spalte aufsteigend zu sortieren",
                    "sortDescending": ": aktivieren, um Spalte absteigend zu sortieren"
                },
                //only works for built-in buttons, not for custom buttons
                "buttons": {
                    "create": "Neu",
                    "edit": "Ändern",
                    "remove": "Löschen",
                    "copy": "Kopieren",
                    "csv": "CSV-Datei",
                    "excel": "Excel-Tabelle",
                    "pdf": "PDF-Dokument",
                    "print": "Drucken",
                    "colvis": "Spalten Auswahl",
                    "collection": "Auswahl"
                },
                select: {
                    rows: {
                        _: '%d Zeilen ausgewählt',
                        0: 'Zeile anklicken um auszuwählen',
                        1: 'Eine Zeile ausgewählt'
                    }
                }
            }            
        } );        
    }
    //custom button added with language specific label
    $.fn.dataTable.ext.buttons.showAll = {
        text: showAllLabel
    };
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,208Questions: 1Answers: 10,415 Site admin
    Answer ✓

    The principle of your commented out lines are correct, but they are being extended on the wrong object. The Editor defaults should be set on the $.fn.dataTable.Editor.defaults object.

    Those are Editor initialisation options, not DataTables.

    Allan

  • rf1234rf1234 Posts: 2,946Questions: 87Answers: 416

    Thanks a lot, Allan. In the meantime I had figured it out myself, but it took me really long ...

    if (lang === 'de') {
            $.extend( true, $.fn.dataTable.Editor.defaults, { 
                i18n: {
                    remove: {
                        button: "Löschen",
                        title:  "Löschen",
                        submit: "Endgültig Löschen",
                        confirm: {
                            _: 'Sind Sie sicher, dass Sie %d Zeilen löschen wollen?',
                            1: 'Sind Sie sicher, dass Sie eine Zeile löschen wollen?'
                        }
                    }
                },      
            });
        }
    
This discussion has been closed.